Skip to content

Commit b99cb04

Browse files
committed
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.
1 parent 8559fb7 commit b99cb04

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/api/wayfire/core.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,12 @@ enum
317317
* Adjust the view geometry for the new output and clamp it to the output geometry so it is
318318
* at an expected size and position.
319319
*/
320-
VIEW_TO_OUTPUT_FLAG_RECONFIGURE = 1 << 0,
320+
VIEW_TO_OUTPUT_FLAG_RECONFIGURE = 1 << 0,
321+
/**
322+
* If the new output has the same workspace geometry as the current output, move the view to the
323+
* same workspace as it is currently on.
324+
*/
325+
VIEW_TO_OUTPUT_FLAG_SAME_WORKSPACE = 1 << 1,
321326
};
322327

323328
/**

src/core/core.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,13 @@ void wf::move_view_to_output(wayfire_toplevel_view v, wf::output_t *new_output,
496496
{
497497
auto old_output = v->get_output();
498498
auto old_wset = v->get_wset();
499+
auto old_ws = old_wset->get_view_main_workspace(v);
500+
auto new_wset = new_output->wset();
499501

500502
uint32_t edges;
501503
bool fullscreen;
502-
bool reconfigure = flags & VIEW_TO_OUTPUT_FLAG_RECONFIGURE;
504+
bool reconfigure = flags & VIEW_TO_OUTPUT_FLAG_RECONFIGURE;
505+
bool same_workspace = flags & VIEW_TO_OUTPUT_FLAG_SAME_WORKSPACE;
503506
wf::geometry_t view_g;
504507
wf::geometry_t old_output_g;
505508
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,
519522

520523
assert(new_output);
521524

522-
start_move_view_to_wset(v, new_output->wset());
525+
start_move_view_to_wset(v, new_wset);
523526
if (new_output == wf::get_core().seat->get_active_output())
524527
{
525528
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,
537540
{
538541
auto new_g = wf::clamp(view_g, new_output->workarea->get_workarea());
539542
v->set_geometry(new_g);
543+
if (same_workspace &&
544+
(old_wset->get_workspace_grid_size() == new_wset->get_workspace_grid_size()))
545+
{
546+
v->get_wset()->move_to_workspace(v, old_ws);
547+
}
540548
}
541549
}
542550

src/core/output-layout.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ void transfer_views(wf::output_t *from, wf::output_t *to)
165165
auto views = from->wset()->get_views(WSET_SORT_STACKING);
166166
for (auto& view : views)
167167
{
168-
move_view_to_output(view, to, true);
168+
unsigned flags = VIEW_TO_OUTPUT_FLAG_RECONFIGURE | VIEW_TO_OUTPUT_FLAG_SAME_WORKSPACE;
169+
move_view_to_output(view, to, flags);
169170
}
170171
}
171172

0 commit comments

Comments
 (0)