From 60d95414d4a7ff163099c9e551ec435cb0cb7eca Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Sat, 31 Oct 2020 19:56:40 -0400 Subject: commands/focus: force container warp when fulfilling `focus mode_toggle` This commit switches focusing behavior to force a warp when executing `focus mode_toggle`. Fixes #5772. --- include/sway/input/cursor.h | 2 +- sway/commands/focus.c | 11 ++++++++++- sway/input/cursor.c | 17 ++++++++++++----- sway/input/seat.c | 5 +---- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index ca3c6f4b..55e2ce8e 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -116,7 +116,7 @@ void cursor_set_image_surface(struct sway_cursor *cursor, struct wl_client *client); void cursor_warp_to_container(struct sway_cursor *cursor, - struct sway_container *container); + struct sway_container *container, bool force); void cursor_warp_to_workspace(struct sway_cursor *cursor, struct sway_workspace *workspace); diff --git a/sway/commands/focus.c b/sway/commands/focus.c index 56c3d981..79b7aed5 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c @@ -268,7 +268,16 @@ static struct cmd_results *focus_mode(struct sway_workspace *ws, } if (new_focus) { seat_set_focus_container(seat, new_focus); - seat_consider_warp_to_focus(seat); + + // If we're on the floating layer and the floating container area + // overlaps the position on the tiling layer that would be warped to, + // `seat_consider_warp_to_focus` would decide not to warp, but we need + // to anyway. + if (config->mouse_warping == WARP_CONTAINER) { + cursor_warp_to_container(seat->cursor, new_focus, true); + } else { + seat_consider_warp_to_focus(seat); + } } else { return cmd_results_new(CMD_FAILURE, "Failed to find a %s container in workspace", diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 9ad4900b..5c883924 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -306,12 +306,16 @@ void cursor_handle_activity(struct sway_cursor *cursor, enum sway_input_idle_source idle_source = idle_source_from_device(device); seat_idle_notify_activity(cursor->seat, idle_source); - if (cursor->hidden && idle_source != IDLE_SOURCE_TOUCH) { + if (idle_source != IDLE_SOURCE_TOUCH) { cursor_unhide(cursor); } } void cursor_unhide(struct sway_cursor *cursor) { + if (!cursor->hidden) { + return; + } + cursor->hidden = false; if (cursor->image_surface) { cursor_set_image_surface(cursor, @@ -1141,18 +1145,19 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { /** * Warps the cursor to the middle of the container argument. - * Does nothing if the cursor is already inside the container. - * If container is NULL, returns without doing anything. + * Does nothing if the cursor is already inside the container and `force` is + * false. If container is NULL, returns without doing anything. */ void cursor_warp_to_container(struct sway_cursor *cursor, - struct sway_container *container) { + struct sway_container *container, bool force) { if (!container) { return; } struct wlr_box box; container_get_box(container, &box); - if (wlr_box_contains_point(&box, cursor->cursor->x, cursor->cursor->y)) { + if (!force && wlr_box_contains_point(&box, cursor->cursor->x, + cursor->cursor->y)) { return; } @@ -1160,6 +1165,7 @@ void cursor_warp_to_container(struct sway_cursor *cursor, double y = container->y + container->height / 2.0; wlr_cursor_warp(cursor->cursor, NULL, x, y); + cursor_unhide(cursor); } /** @@ -1176,6 +1182,7 @@ void cursor_warp_to_workspace(struct sway_cursor *cursor, double y = workspace->y + workspace->height / 2.0; wlr_cursor_warp(cursor->cursor, NULL, x, y); + cursor_unhide(cursor); } uint32_t get_mouse_bindsym(const char *name, char **error) { diff --git a/sway/input/seat.c b/sway/input/seat.c index e178c08a..24d7e903 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -1477,13 +1477,10 @@ void seat_consider_warp_to_focus(struct sway_seat *seat) { } if (focus->type == N_CONTAINER) { - cursor_warp_to_container(seat->cursor, focus->sway_container); + cursor_warp_to_container(seat->cursor, focus->sway_container, false); } else { cursor_warp_to_workspace(seat->cursor, focus->sway_workspace); } - if (seat->cursor->hidden){ - cursor_unhide(seat->cursor); - } } void seatop_unref(struct sway_seat *seat, struct sway_container *con) { -- cgit v1.2.3-54-g00ecf