Skip to content

Commit

Permalink
core: transfer views to same workspace as on destroyed output
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lcolitti committed Apr 12, 2024
1 parent 8559fb7 commit b99cb04
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/api/wayfire/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

/**
Expand Down
12 changes: 10 additions & 2 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/output-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit b99cb04

Please sign in to comment.