Skip to content

Commit b60a25b

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, move each view to the same workspace it was on before, or, if the new workspace set has a smaller grid, to the edge.
1 parent ea88456 commit b60a25b

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-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+
* When reconfiguring, also move the view to the same workspace as it is currently on. Only
393+
* meaningful if VIEW_TO_OUTPUT_FLAG_RECONFIGURE is also set.
394+
*/
395+
VIEW_TO_OUTPUT_FLAG_SAME_WORKSPACE = 1 << 1,
391396
};
392397

393398
/**

src/core/core.cpp

Lines changed: 22 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,39 @@ 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+
{
673+
auto new_grid_size = new_wset->get_workspace_grid_size();
674+
new_ws = {
675+
std::min(old_ws.x, new_grid_size.width),
676+
std::min(old_ws.y, new_grid_size.height)
677+
};
678+
}
679+
666680
if (fullscreen)
667681
{
668-
wf::get_core().default_wm->fullscreen_request(v, new_output, true);
682+
wf::get_core().default_wm->fullscreen_request(v, new_output, true, new_ws);
669683
} else if (edges)
670684
{
671-
wf::get_core().default_wm->tile_request(v, edges);
685+
wf::get_core().default_wm->tile_request(v, edges, new_ws);
672686
} else
673687
{
674688
auto new_g = wf::clamp(view_g, new_output->workarea->get_workarea());
675689
v->set_geometry(new_g);
690+
if (new_ws.has_value())
691+
{
692+
v->get_wset()->move_to_workspace(v, new_ws.value());
693+
}
676694
}
677695

678696
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)