mirror of
https://github.com/swaywm/sway.git
synced 2024-11-11 13:04:11 +01:00
Move sticky containers when switching workspace via criteria
* Create a view on workspace 1 * Switch to workspace 2 (on the same output) and create a floating sticky view * Use criteria to focus the view on workspace 1 Previously, we only moved the sticky containers when using workspace_switch, but the above method of focusing doesn't call it. This patch relocates the sticky-moving code into seat_set_focus_warp. A side effect of this patch is that if you have a sticky container focused and then switch workspaces, the sticky container will no longer be focused. It would previously retain focus. In seat_set_focus_warp, new_output_last_ws was only set when changing outputs, but now it's always set. This means new_output_last_ws and last_workspace might point to the same workspace, which means we have to make sure we don't destroy it twice. It now checks to make sure they're different, and to make this more obvious I've moved both calls to workspace_consider_destroy to be next to each other.
This commit is contained in:
parent
5d21c33f13
commit
c620f76bea
@ -667,10 +667,8 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node,
|
||||
}
|
||||
|
||||
// find new output's old workspace, which might have to be removed if empty
|
||||
struct sway_workspace *new_output_last_ws = NULL;
|
||||
if (new_output && last_output != new_output) {
|
||||
new_output_last_ws = output_get_active_workspace(new_output);
|
||||
}
|
||||
struct sway_workspace *new_output_last_ws =
|
||||
new_output ? output_get_active_workspace(new_output) : NULL;
|
||||
|
||||
// Unfocus the previous focus
|
||||
if (last_focus) {
|
||||
@ -719,8 +717,17 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node,
|
||||
ipc_event_window(container, "focus");
|
||||
}
|
||||
|
||||
if (new_output_last_ws) {
|
||||
workspace_consider_destroy(new_output_last_ws);
|
||||
// Move sticky containers to new workspace
|
||||
if (new_output_last_ws && new_workspace != new_output_last_ws) {
|
||||
for (int i = 0; i < new_output_last_ws->floating->length; ++i) {
|
||||
struct sway_container *floater =
|
||||
new_output_last_ws->floating->items[i];
|
||||
if (floater->is_sticky) {
|
||||
container_detach(floater);
|
||||
workspace_add_floating(new_workspace, floater);
|
||||
--i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close any popups on the old focus
|
||||
@ -754,11 +761,14 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node,
|
||||
container_raise_floating(container);
|
||||
}
|
||||
|
||||
if (last_focus) {
|
||||
if (last_workspace) {
|
||||
workspace_consider_destroy(last_workspace);
|
||||
}
|
||||
if (new_output_last_ws) {
|
||||
workspace_consider_destroy(new_output_last_ws);
|
||||
}
|
||||
if (last_workspace && last_workspace != new_output_last_ws) {
|
||||
workspace_consider_destroy(last_workspace);
|
||||
}
|
||||
|
||||
if (last_focus) {
|
||||
if (config->mouse_warping && warp && new_output != last_output) {
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
|
@ -369,7 +369,6 @@ struct sway_workspace *workspace_prev(struct sway_workspace *current) {
|
||||
bool workspace_switch(struct sway_workspace *workspace,
|
||||
bool no_auto_back_and_forth) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_node *focus = seat_get_focus_inactive(seat, &root->node);
|
||||
struct sway_workspace *active_ws = seat_get_focused_workspace(seat);
|
||||
|
||||
if (!no_auto_back_and_forth && config->auto_back_and_forth
|
||||
@ -392,27 +391,6 @@ bool workspace_switch(struct sway_workspace *workspace,
|
||||
strcpy(prev_workspace_name, active_ws->name);
|
||||
}
|
||||
|
||||
// Move sticky containers to new workspace
|
||||
struct sway_output *next_output = workspace->output;
|
||||
struct sway_workspace *next_output_prev_ws =
|
||||
output_get_active_workspace(next_output);
|
||||
if (workspace != next_output_prev_ws) {
|
||||
for (int i = 0; i < next_output_prev_ws->floating->length; ++i) {
|
||||
struct sway_container *floater =
|
||||
next_output_prev_ws->floating->items[i];
|
||||
if (floater->is_sticky) {
|
||||
container_detach(floater);
|
||||
workspace_add_floating(workspace, floater);
|
||||
if (&floater->node == focus) {
|
||||
seat_set_focus(seat, NULL);
|
||||
seat_set_focus_container(seat, floater);
|
||||
cursor_send_pointer_motion(seat->cursor, 0, true);
|
||||
}
|
||||
--i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wlr_log(WLR_DEBUG, "Switching to workspace %p:%s",
|
||||
workspace, workspace->name);
|
||||
struct sway_node *next = seat_get_focus_inactive(seat, &workspace->node);
|
||||
|
Loading…
Reference in New Issue
Block a user