Skip to content

Commit 9925d03

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 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 cff6f5b commit 9925d03

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/api/wayfire/core.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,12 @@ enum
387387
* Adjust the view geometry for the new output and clamp it to the output geometry so it is
388388
* at an expected size and position.
389389
*/
390-
VIEW_TO_OUTPUT_FLAG_RECONFIGURE = 1 << 0,
390+
VIEW_TO_OUTPUT_FLAG_RECONFIGURE = 1 << 0,
391+
/**
392+
* If the new output has the same workspace geometry as the current output, move the view to the
393+
* same workspace as it is currently on.
394+
*/
395+
VIEW_TO_OUTPUT_FLAG_SAME_WORKSPACE = 1 << 1,
391396
};
392397

393398
/**

src/core/core.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,13 @@ void wf::move_view_to_output(wayfire_toplevel_view v, wf::output_t *new_output,
626626

627627
auto old_output = v->get_output();
628628
auto old_wset = v->get_wset();
629+
auto old_ws = old_wset->get_view_main_workspace(v);
630+
auto new_wset = new_output->wset();
629631

630632
uint32_t edges;
631633
bool fullscreen;
632-
bool reconfigure = flags & VIEW_TO_OUTPUT_FLAG_RECONFIGURE;
634+
bool reconfigure = flags & VIEW_TO_OUTPUT_FLAG_RECONFIGURE;
635+
bool same_workspace = flags & VIEW_TO_OUTPUT_FLAG_SAME_WORKSPACE;
633636
wf::geometry_t view_g;
634637
wf::geometry_t old_output_g;
635638
wf::geometry_t new_output_g;
@@ -655,24 +658,36 @@ void wf::move_view_to_output(wayfire_toplevel_view v, wf::output_t *new_output,
655658

656659
assert(new_output);
657660

658-
start_move_view_to_wset(v, new_output->wset());
661+
start_move_view_to_wset(v, new_wset);
659662
if (new_output == wf::get_core().seat->get_active_output())
660663
{
661664
wf::get_core().seat->focus_view(v);
662665
}
663666

664667
if (reconfigure)
665668
{
669+
std::optional<wf::point_t> new_ws;
670+
671+
if (same_workspace &&
672+
old_wset->get_workspace_grid_size() == new_wset->get_workspace_grid_size())
673+
{
674+
new_ws = old_ws;
675+
}
676+
666677
if (fullscreen)
667678
{
668-
wf::get_core().default_wm->fullscreen_request(v, new_output, true);
679+
wf::get_core().default_wm->fullscreen_request(v, new_output, true, new_ws);
669680
} else if (edges)
670681
{
671-
wf::get_core().default_wm->tile_request(v, edges);
682+
wf::get_core().default_wm->tile_request(v, edges, new_ws);
672683
} else
673684
{
674685
auto new_g = wf::clamp(view_g, new_output->workarea->get_workarea());
675686
v->set_geometry(new_g);
687+
if (new_ws.has_value())
688+
{
689+
v->get_wset()->move_to_workspace(v, new_ws.value());
690+
}
676691
}
677692

678693
for (auto& dialog : v->enumerate_views())

src/core/output-layout.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ void transfer_views(wf::output_t *from, wf::output_t *to)
263263
auto views = from->wset()->get_views(WSET_SORT_STACKING);
264264
for (auto& view : views)
265265
{
266-
move_view_to_output(view, to, true);
266+
unsigned flags = VIEW_TO_OUTPUT_FLAG_RECONFIGURE | VIEW_TO_OUTPUT_FLAG_SAME_WORKSPACE;
267+
move_view_to_output(view, to, flags);
267268
}
268269
}
269270

0 commit comments

Comments
 (0)