diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index be95567e8..b3b98e8dd 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -52,6 +52,7 @@ struct sway_seat { bool has_focus; struct wl_list focus_stack; // list of containers in focus order struct sway_workspace *workspace; + struct sway_node *prev_focus; // If the focused layer is set, views cannot receive keyboard focus struct wlr_layer_surface_v1 *focused_layer; @@ -121,9 +122,6 @@ void seat_set_focus_workspace(struct sway_seat *seat, */ void seat_set_raw_focus(struct sway_seat *seat, struct sway_node *node); -void seat_set_focus_warp(struct sway_seat *seat, - struct sway_node *node, bool warp); - void seat_set_focus_surface(struct sway_seat *seat, struct wlr_surface *surface, bool unfocus); diff --git a/sway/commands/focus.c b/sway/commands/focus.c index 44adb95bd..46304ae03 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c @@ -34,6 +34,24 @@ static bool parse_movement_direction(const char *name, return true; } +static void consider_warp_to_focus(struct sway_seat *seat) { + struct sway_node *focus = seat_get_focus(seat); + if (config->mouse_warping == WARP_NO || !focus || !seat->prev_focus) { + return; + } + if (config->mouse_warping == WARP_OUTPUT && + node_get_output(focus) == node_get_output(seat->prev_focus)) { + return; + } + + if (focus->type == N_CONTAINER) { + cursor_warp_to_container(seat->cursor, focus->sway_container); + } else { + cursor_warp_to_workspace(seat->cursor, focus->sway_workspace); + } + cursor_send_pointer_motion(seat->cursor, 0, false); +} + /** * Get node in the direction of newly entered output. */ @@ -181,7 +199,7 @@ static struct cmd_results *focus_mode(struct sway_workspace *ws, } if (new_focus) { seat_set_focus_container(seat, new_focus); - cursor_send_pointer_motion(seat->cursor, 0, true); + consider_warp_to_focus(seat); } else { return cmd_results_new(CMD_FAILURE, "focus", "Failed to find a %s container in workspace", @@ -214,7 +232,7 @@ static struct cmd_results *focus_output(struct sway_seat *seat, free(identifier); if (output) { seat_set_focus(seat, seat_get_focus_inactive(seat, &output->node)); - cursor_send_pointer_motion(seat->cursor, 0, true); + consider_warp_to_focus(seat); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); @@ -235,6 +253,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) { if (argc == 0 && container) { seat_set_focus_container(seat, container); + consider_warp_to_focus(seat); cursor_send_pointer_motion(seat->cursor, 0, true); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } @@ -264,7 +283,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) { struct sway_node *focus = seat_get_active_tiling_child(seat, node); if (focus) { seat_set_focus(seat, focus); - cursor_send_pointer_motion(seat->cursor, 0, true); + consider_warp_to_focus(seat); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); } @@ -284,7 +303,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) { struct sway_node *node = get_node_in_output_direction(new_output, direction); seat_set_focus(seat, node); - cursor_send_pointer_motion(seat->cursor, 0, true); + consider_warp_to_focus(seat); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } @@ -292,7 +311,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) { node_get_in_direction(container, seat, direction); if (next_focus) { seat_set_focus(seat, next_focus); - cursor_send_pointer_motion(seat->cursor, 0, true); + consider_warp_to_focus(seat); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/swap.c b/sway/commands/swap.c index 9cc0d5c27..8a6dfdbd3 100644 --- a/sway/commands/swap.c +++ b/sway/commands/swap.c @@ -61,13 +61,13 @@ static void swap_focus(struct sway_container *con1, enum sway_container_layout layout2 = container_parent_layout(con2); if (focus == con1 && (layout2 == L_TABBED || layout2 == L_STACKED)) { if (workspace_is_visible(ws2)) { - seat_set_focus_warp(seat, &con2->node, false); + seat_set_focus(seat, &con2->node); } seat_set_focus_container(seat, ws1 != ws2 ? con2 : con1); } else if (focus == con2 && (layout1 == L_TABBED || layout1 == L_STACKED)) { if (workspace_is_visible(ws1)) { - seat_set_focus_warp(seat, &con1->node, false); + seat_set_focus(seat, &con1->node); } seat_set_focus_container(seat, ws1 != ws2 ? con1 : con2); } else if (ws1 != ws2) { diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 925190d6a..688fc230c 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -597,7 +597,7 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, struct sway_output *focused_output = node_get_output(focus); struct sway_output *output = node_get_output(node); if (output != focused_output) { - seat_set_focus_warp(seat, node, false); + seat_set_focus(seat, node); } } else if (node->type == N_CONTAINER && node->sway_container->view) { // Focus node if the following are true: @@ -607,14 +607,14 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, if (!wlr_seat_keyboard_has_grab(cursor->seat->wlr_seat) && node != prev_node && view_is_visible(node->sway_container->view)) { - seat_set_focus_warp(seat, node, false); + seat_set_focus(seat, node); } else { struct sway_node *next_focus = seat_get_focus_inactive(seat, &root->node); if (next_focus && next_focus->type == N_CONTAINER && next_focus->sway_container->view && view_is_visible(next_focus->sway_container->view)) { - seat_set_focus_warp(seat, next_focus, false); + seat_set_focus(seat, next_focus); } } } diff --git a/sway/input/seat.c b/sway/input/seat.c index d8d2f3a4d..60ee27d0b 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -640,13 +640,13 @@ void seat_set_raw_focus(struct sway_seat *seat, struct sway_node *node) { node_set_dirty(node_get_parent(node)); } -void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, - bool warp) { +void seat_set_focus(struct sway_seat *seat, struct sway_node *node) { if (seat->focused_layer) { return; } struct sway_node *last_focus = seat_get_focus(seat); + seat->prev_focus = last_focus; if (last_focus == node) { return; } @@ -678,8 +678,6 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, } } - struct sway_output *last_output = last_workspace ? - last_workspace->output : NULL; struct sway_output *new_output = new_workspace->output; if (last_workspace != new_workspace && new_output) { @@ -774,21 +772,6 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, workspace_consider_destroy(last_workspace); } - if (last_focus && warp) { - if (container && config->mouse_warping == WARP_CONTAINER) { - cursor_warp_to_container(seat->cursor, container); - cursor_send_pointer_motion(seat->cursor, 0, true); - } else if (new_output != last_output && - config->mouse_warping >= WARP_OUTPUT) { - if (container) { - cursor_warp_to_container(seat->cursor, container); - } else { - cursor_warp_to_workspace(seat->cursor, new_workspace); - } - cursor_send_pointer_motion(seat->cursor, 0, true); - } - } - seat->has_focus = true; if (config->smart_gaps) { @@ -800,18 +783,14 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, update_debug_tree(); } -void seat_set_focus(struct sway_seat *seat, struct sway_node *node) { - seat_set_focus_warp(seat, node, true); -} - void seat_set_focus_container(struct sway_seat *seat, struct sway_container *con) { - seat_set_focus_warp(seat, con ? &con->node : NULL, true); + seat_set_focus(seat, con ? &con->node : NULL); } void seat_set_focus_workspace(struct sway_seat *seat, struct sway_workspace *ws) { - seat_set_focus_warp(seat, ws ? &ws->node : NULL, true); + seat_set_focus(seat, ws ? &ws->node : NULL); } void seat_set_focus_surface(struct sway_seat *seat,