From b99cb040c43a1f571654bc076003d3f2f707d44c Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Fri, 29 Mar 2024 20:22:22 +0900 Subject: [PATCH] core: transfer views to same workspace as on destroyed output Currently, when an output is destroyed, views are transferred to the new output in roughly the same position as they were on the old output, but they are all transferred to the first workspace. This is annoying: if they were not on the first workspace, then the user must have moved them, and after they're transferred, the user must will have to move them agein. Instead, in the (common?) case that the old and the new output have the same number of workspaces, move each view to the same workspace it was on before. --- src/api/wayfire/core.hpp | 7 ++++++- src/core/core.cpp | 12 ++++++++++-- src/core/output-layout.cpp | 3 ++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/api/wayfire/core.hpp b/src/api/wayfire/core.hpp index 7f38fa0c5..3519266b2 100644 --- a/src/api/wayfire/core.hpp +++ b/src/api/wayfire/core.hpp @@ -317,7 +317,12 @@ enum * Adjust the view geometry for the new output and clamp it to the output geometry so it is * at an expected size and position. */ - VIEW_TO_OUTPUT_FLAG_RECONFIGURE = 1 << 0, + VIEW_TO_OUTPUT_FLAG_RECONFIGURE = 1 << 0, + /** + * If the new output has the same workspace geometry as the current output, move the view to the + * same workspace as it is currently on. + */ + VIEW_TO_OUTPUT_FLAG_SAME_WORKSPACE = 1 << 1, }; /** diff --git a/src/core/core.cpp b/src/core/core.cpp index 0f525cc0f..906328bb0 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -496,10 +496,13 @@ void wf::move_view_to_output(wayfire_toplevel_view v, wf::output_t *new_output, { auto old_output = v->get_output(); auto old_wset = v->get_wset(); + auto old_ws = old_wset->get_view_main_workspace(v); + auto new_wset = new_output->wset(); uint32_t edges; bool fullscreen; - bool reconfigure = flags & VIEW_TO_OUTPUT_FLAG_RECONFIGURE; + bool reconfigure = flags & VIEW_TO_OUTPUT_FLAG_RECONFIGURE; + bool same_workspace = flags & VIEW_TO_OUTPUT_FLAG_SAME_WORKSPACE; wf::geometry_t view_g; wf::geometry_t old_output_g; wf::geometry_t new_output_g; @@ -519,7 +522,7 @@ void wf::move_view_to_output(wayfire_toplevel_view v, wf::output_t *new_output, assert(new_output); - start_move_view_to_wset(v, new_output->wset()); + start_move_view_to_wset(v, new_wset); if (new_output == wf::get_core().seat->get_active_output()) { wf::get_core().seat->focus_view(v); @@ -537,6 +540,11 @@ void wf::move_view_to_output(wayfire_toplevel_view v, wf::output_t *new_output, { auto new_g = wf::clamp(view_g, new_output->workarea->get_workarea()); v->set_geometry(new_g); + if (same_workspace && + (old_wset->get_workspace_grid_size() == new_wset->get_workspace_grid_size())) + { + v->get_wset()->move_to_workspace(v, old_ws); + } } } diff --git a/src/core/output-layout.cpp b/src/core/output-layout.cpp index c2a4741cd..3bb297897 100644 --- a/src/core/output-layout.cpp +++ b/src/core/output-layout.cpp @@ -165,7 +165,8 @@ void transfer_views(wf::output_t *from, wf::output_t *to) auto views = from->wset()->get_views(WSET_SORT_STACKING); for (auto& view : views) { - move_view_to_output(view, to, true); + unsigned flags = VIEW_TO_OUTPUT_FLAG_RECONFIGURE | VIEW_TO_OUTPUT_FLAG_SAME_WORKSPACE; + move_view_to_output(view, to, flags); } }