From 06098bef98ec515584ab8007cbf7a104f2d67980 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Sun, 27 May 2018 14:52:40 +1000 Subject: [PATCH 1/8] Focus containers only on entry. --- include/sway/input/cursor.h | 4 +-- sway/commands/border.c | 2 +- sway/commands/seat/cursor.c | 4 +-- sway/input/cursor.c | 54 ++++++++++++++++++++++++------------- sway/input/seat.c | 4 +-- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 42c894a4f..2141361d2 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -29,8 +29,8 @@ struct sway_cursor { void sway_cursor_destroy(struct sway_cursor *cursor); struct sway_cursor *sway_cursor_create(struct sway_seat *seat); -void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, - bool allow_refocusing); +void cursor_send_pointer_motion(struct sway_cursor *cursor, + double delta_x, double delta_y, uint32_t time_msec, bool allow_refocusing); void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, uint32_t button, enum wlr_button_state state); diff --git a/sway/commands/border.c b/sway/commands/border.c index 4ba361da6..5160eaa67 100644 --- a/sway/commands/border.c +++ b/sway/commands/border.c @@ -41,7 +41,7 @@ struct cmd_results *cmd_border(int argc, char **argv) { struct sway_seat *seat = input_manager_current_seat(input_manager); if (seat->cursor) { - cursor_send_pointer_motion(seat->cursor, 0, false); + cursor_send_pointer_motion(seat->cursor, 0, 0, 0, false); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 4d0a22c78..81fee31f1 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c @@ -36,7 +36,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { int delta_x = strtol(argv[1], NULL, 10); int delta_y = strtol(argv[2], NULL, 10); wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y); - cursor_send_pointer_motion(cursor, 0, true); + cursor_send_pointer_motion(cursor, 0, 0, 0, true); } else if (strcasecmp(argv[0], "set") == 0) { if (argc < 3) { return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); @@ -45,7 +45,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { float x = strtof(argv[1], NULL) / root_container.width; float y = strtof(argv[2], NULL) / root_container.height; wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y); - cursor_send_pointer_motion(cursor, 0, true); + cursor_send_pointer_motion(cursor, 0, 0, 0, true); } else { if (argc < 2) { return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 1cf432f3c..cc8d344fa 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -135,15 +135,25 @@ static struct sway_container *container_at_coords( return output->swayc; } -void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, - bool allow_refocusing) { +void cursor_send_pointer_motion(struct sway_cursor *cursor, + double delta_x, double delta_y, uint32_t time_msec, bool allow_refocusing) { + struct sway_container *prev_c = NULL; + struct wlr_surface *surface = NULL; + double sx, sy; + + if (delta_x != 0 || delta_y != 0) { + // Use the motion delta to find the container the pointer was previously + // over. + prev_c = container_at_coords(cursor->seat, + cursor->cursor->x - delta_x, cursor->cursor->y - delta_y, + &surface, &sx, &sy); + } + if (time_msec == 0) { time_msec = get_current_time_msec(); } struct wlr_seat *seat = cursor->seat->wlr_seat; - struct wlr_surface *surface = NULL; - double sx, sy; struct sway_container *c = container_at_coords(cursor->seat, cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); if (c && config->focus_follows_mouse && allow_refocusing) { @@ -162,20 +172,27 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, seat_set_focus_warp(cursor->seat, c, false); } } else if (c->type == C_VIEW) { - // Don't switch focus on title mouseover for - // stacked and tabbed layouts - // If pointed container is in nested containers which are - // inside tabbed/stacked layout we should skip them bool do_mouse_focus = true; - bool is_visible = view_is_visible(c->sway_view); struct sway_container *p = c->parent; - while (p) { - if ((p->layout == L_TABBED || p->layout == L_STACKED) - && !is_visible) { - do_mouse_focus = false; - break; + // Don't switch focus unless we have moved from one container to another. + if (c && prev_c && c == prev_c) { + do_mouse_focus = false; + } + // Skip check if we already know not to focus. + if (do_mouse_focus) { + // Don't switch focus on title mouseover for + // stacked and tabbed layouts + // If pointed container is in nested containers which are + // inside tabbed/stacked layout we should skip them + bool is_visible = view_is_visible(c->sway_view); + while (p) { + if ((p->layout == L_TABBED || p->layout == L_STACKED) + && !is_visible) { + do_mouse_focus = false; + break; + } + p = p->parent; } - p = p->parent; } if (!do_mouse_focus) { struct sway_container *next_focus = seat_get_focus_inactive( @@ -221,7 +238,8 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) { struct wlr_event_pointer_motion *event = data; wlr_cursor_move(cursor->cursor, event->device, event->delta_x, event->delta_y); - cursor_send_pointer_motion(cursor, event->time_msec, true); + cursor_send_pointer_motion(cursor, event->delta_x, event->delta_y, + event->time_msec, true); } static void handle_cursor_motion_absolute( @@ -231,7 +249,7 @@ static void handle_cursor_motion_absolute( wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); struct wlr_event_pointer_motion_absolute *event = data; wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); - cursor_send_pointer_motion(cursor, event->time_msec, true); + cursor_send_pointer_motion(cursor, 0, 0, event->time_msec, true); } void dispatch_cursor_button(struct sway_cursor *cursor, @@ -401,7 +419,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { } wlr_cursor_warp_absolute(cursor->cursor, event->device, x, y); - cursor_send_pointer_motion(cursor, event->time_msec, true); + cursor_send_pointer_motion(cursor, 0, 0, event->time_msec, true); } static void handle_tool_tip(struct wl_listener *listener, void *data) { diff --git a/sway/input/seat.c b/sway/input/seat.c index 7a3e928a3..bb5832866 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -602,7 +602,7 @@ void seat_set_focus_warp(struct sway_seat *seat, wlr_output, seat->cursor->cursor->x, seat->cursor->cursor->y)) { wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); - cursor_send_pointer_motion(seat->cursor, 0, true); + cursor_send_pointer_motion(seat->cursor, 0, 0, 0, true); } } } @@ -613,7 +613,7 @@ void seat_set_focus_warp(struct sway_seat *seat, } if (last_workspace && last_workspace != new_workspace) { - cursor_send_pointer_motion(seat->cursor, 0, true); + cursor_send_pointer_motion(seat->cursor, 0, 0, 0, true); } seat->has_focus = (container != NULL); From 4cd304e4bacb255694bf63f8f1ccacd352a96144 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Sun, 27 May 2018 22:45:14 +1000 Subject: [PATCH 2/8] Store previous position in sway_cursor. --- include/sway/input/cursor.h | 9 +++- sway/commands/border.c | 2 +- sway/commands/seat/cursor.c | 4 +- sway/input/cursor.c | 84 +++++++++++++++++++------------------ sway/input/seat.c | 4 +- 5 files changed, 56 insertions(+), 47 deletions(-) diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 2141361d2..03cb8b830 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -6,6 +6,7 @@ struct sway_cursor { struct sway_seat *seat; struct wlr_cursor *cursor; + struct cursor_position *previous; struct wlr_xcursor_manager *xcursor_manager; struct wl_client *image_client; @@ -27,10 +28,14 @@ struct sway_cursor { struct wl_listener request_set_cursor; }; +struct cursor_position { + double x, y; +}; + void sway_cursor_destroy(struct sway_cursor *cursor); struct sway_cursor *sway_cursor_create(struct sway_seat *seat); -void cursor_send_pointer_motion(struct sway_cursor *cursor, - double delta_x, double delta_y, uint32_t time_msec, bool allow_refocusing); +void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, + bool allow_refocusing); void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, uint32_t button, enum wlr_button_state state); diff --git a/sway/commands/border.c b/sway/commands/border.c index 5160eaa67..4ba361da6 100644 --- a/sway/commands/border.c +++ b/sway/commands/border.c @@ -41,7 +41,7 @@ struct cmd_results *cmd_border(int argc, char **argv) { struct sway_seat *seat = input_manager_current_seat(input_manager); if (seat->cursor) { - cursor_send_pointer_motion(seat->cursor, 0, 0, 0, false); + cursor_send_pointer_motion(seat->cursor, 0, false); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 81fee31f1..4d0a22c78 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c @@ -36,7 +36,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { int delta_x = strtol(argv[1], NULL, 10); int delta_y = strtol(argv[2], NULL, 10); wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y); - cursor_send_pointer_motion(cursor, 0, 0, 0, true); + cursor_send_pointer_motion(cursor, 0, true); } else if (strcasecmp(argv[0], "set") == 0) { if (argc < 3) { return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); @@ -45,7 +45,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { float x = strtof(argv[1], NULL) / root_container.width; float y = strtof(argv[2], NULL) / root_container.height; wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y); - cursor_send_pointer_motion(cursor, 0, 0, 0, true); + cursor_send_pointer_motion(cursor, 0, true); } else { if (argc < 2) { return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); diff --git a/sway/input/cursor.c b/sway/input/cursor.c index cc8d344fa..a318bbd44 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -135,25 +135,23 @@ static struct sway_container *container_at_coords( return output->swayc; } -void cursor_send_pointer_motion(struct sway_cursor *cursor, - double delta_x, double delta_y, uint32_t time_msec, bool allow_refocusing) { - struct sway_container *prev_c = NULL; - struct wlr_surface *surface = NULL; - double sx, sy; - - if (delta_x != 0 || delta_y != 0) { - // Use the motion delta to find the container the pointer was previously - // over. - prev_c = container_at_coords(cursor->seat, - cursor->cursor->x - delta_x, cursor->cursor->y - delta_y, - &surface, &sx, &sy); - } - +void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, + bool allow_refocusing) { if (time_msec == 0) { time_msec = get_current_time_msec(); } struct wlr_seat *seat = cursor->seat->wlr_seat; + struct wlr_surface *surface = NULL; + double sx, sy; + + // Find the container the pointer was previously over + struct sway_container *prev_c = container_at_coords(cursor->seat, + cursor->previous->x, cursor->previous->y, &surface, &sx, &sy); + // Update the stored previous position + cursor->previous->x = cursor->cursor->x; + cursor->previous->y = cursor->cursor->y; + struct sway_container *c = container_at_coords(cursor->seat, cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); if (c && config->focus_follows_mouse && allow_refocusing) { @@ -173,39 +171,38 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, } } else if (c->type == C_VIEW) { bool do_mouse_focus = true; + bool is_visible = view_is_visible(c->sway_view); struct sway_container *p = c->parent; - // Don't switch focus unless we have moved from one container to another. - if (c && prev_c && c == prev_c) { + // Don't switch focus unless we have moved from one container to another + if (c && c == prev_c) { do_mouse_focus = false; } - // Skip check if we already know not to focus. - if (do_mouse_focus) { - // Don't switch focus on title mouseover for - // stacked and tabbed layouts - // If pointed container is in nested containers which are - // inside tabbed/stacked layout we should skip them - bool is_visible = view_is_visible(c->sway_view); + // Don't switch focus on title mouseover for stacked and tabbed layouts + // If pointed container is in nested containers which are inside + // tabbed/stacked layout we should skip them + if (do_mouse_focus && !is_visible) { while (p) { - if ((p->layout == L_TABBED || p->layout == L_STACKED) - && !is_visible) { + if ((p->layout == L_TABBED || p->layout == L_STACKED)) { do_mouse_focus = false; break; } p = p->parent; } } - if (!do_mouse_focus) { - struct sway_container *next_focus = seat_get_focus_inactive( - cursor->seat, p); - if(next_focus && !sway_assert(next_focus->type == C_VIEW, - "focus inactive container is not a view")) { - return; - } - if (next_focus && view_is_visible(next_focus->sway_view)) { - seat_set_focus_warp(cursor->seat, next_focus, false); - } - } else { + if (do_mouse_focus) { seat_set_focus_warp(cursor->seat, c, false); + } else { + struct sway_container *next_focus = + seat_get_focus_inactive(cursor->seat, &root_container); + if (next_focus) { + if (!sway_assert(next_focus->type == C_VIEW, + "focus inactive container is not a view")) { + return; + } + if (view_is_visible(next_focus->sway_view)) { + seat_set_focus_warp(cursor->seat, next_focus, false); + } + } } } } @@ -238,8 +235,7 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) { struct wlr_event_pointer_motion *event = data; wlr_cursor_move(cursor->cursor, event->device, event->delta_x, event->delta_y); - cursor_send_pointer_motion(cursor, event->delta_x, event->delta_y, - event->time_msec, true); + cursor_send_pointer_motion(cursor, event->time_msec, true); } static void handle_cursor_motion_absolute( @@ -249,7 +245,7 @@ static void handle_cursor_motion_absolute( wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); struct wlr_event_pointer_motion_absolute *event = data; wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); - cursor_send_pointer_motion(cursor, 0, 0, event->time_msec, true); + cursor_send_pointer_motion(cursor, event->time_msec, true); } void dispatch_cursor_button(struct sway_cursor *cursor, @@ -419,7 +415,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { } wlr_cursor_warp_absolute(cursor->cursor, event->device, x, y); - cursor_send_pointer_motion(cursor, 0, 0, event->time_msec, true); + cursor_send_pointer_motion(cursor, event->time_msec, true); } static void handle_tool_tip(struct wl_listener *listener, void *data) { @@ -496,8 +492,15 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { return NULL; } + struct cursor_position *previous = calloc(1, sizeof(struct cursor_position)); + if (!sway_assert(previous, "could not allocate sway cursor position")) { + free(cursor); + return NULL; + } + struct wlr_cursor *wlr_cursor = wlr_cursor_create(); if (!sway_assert(wlr_cursor, "could not allocate wlr cursor")) { + free(previous); free(cursor); return NULL; } @@ -548,6 +551,7 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { cursor->request_set_cursor.notify = handle_request_set_cursor; cursor->cursor = wlr_cursor; + cursor->previous = previous; return cursor; } diff --git a/sway/input/seat.c b/sway/input/seat.c index bb5832866..7a3e928a3 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -602,7 +602,7 @@ void seat_set_focus_warp(struct sway_seat *seat, wlr_output, seat->cursor->cursor->x, seat->cursor->cursor->y)) { wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); - cursor_send_pointer_motion(seat->cursor, 0, 0, 0, true); + cursor_send_pointer_motion(seat->cursor, 0, true); } } } @@ -613,7 +613,7 @@ void seat_set_focus_warp(struct sway_seat *seat, } if (last_workspace && last_workspace != new_workspace) { - cursor_send_pointer_motion(seat->cursor, 0, 0, 0, true); + cursor_send_pointer_motion(seat->cursor, 0, true); } seat->has_focus = (container != NULL); From dd86444e594138771d1e7edad69ac7007c500b63 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Mon, 28 May 2018 01:17:31 +1000 Subject: [PATCH 3/8] Rely on view_is_visible rather thank walking the tree ourselves. --- sway/input/cursor.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index a318bbd44..42eb2810c 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -171,24 +171,13 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, } } else if (c->type == C_VIEW) { bool do_mouse_focus = true; - bool is_visible = view_is_visible(c->sway_view); - struct sway_container *p = c->parent; - // Don't switch focus unless we have moved from one container to another - if (c && c == prev_c) { + // Don't switch focus if either of the following is true: + // - the cursor is over the same container as before. i.e. hasn't crossed + // a window boundary; or + // - the view is not visible. i.e. in a stack or tab. + if (c == prev_c || !view_is_visible(c->sway_view)) { do_mouse_focus = false; } - // Don't switch focus on title mouseover for stacked and tabbed layouts - // If pointed container is in nested containers which are inside - // tabbed/stacked layout we should skip them - if (do_mouse_focus && !is_visible) { - while (p) { - if ((p->layout == L_TABBED || p->layout == L_STACKED)) { - do_mouse_focus = false; - break; - } - p = p->parent; - } - } if (do_mouse_focus) { seat_set_focus_warp(cursor->seat, c, false); } else { From 0039f7a4fdaa6608911bd4f3c2dbcd06f24f99ec Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Mon, 28 May 2018 01:30:19 +1000 Subject: [PATCH 4/8] Simplify logic, remove redundant variables. --- sway/input/cursor.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 42eb2810c..1fa5be34e 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -170,15 +170,10 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, seat_set_focus_warp(cursor->seat, c, false); } } else if (c->type == C_VIEW) { - bool do_mouse_focus = true; - // Don't switch focus if either of the following is true: - // - the cursor is over the same container as before. i.e. hasn't crossed - // a window boundary; or - // - the view is not visible. i.e. in a stack or tab. - if (c == prev_c || !view_is_visible(c->sway_view)) { - do_mouse_focus = false; - } - if (do_mouse_focus) { + // Focus c if both of the following are true: + // - cursor is over a new view, i.e. entered a new window; and + // - the new view is visible, i.e. not hidden in a stack or tab. + if (c != prev_c && view_is_visible(c->sway_view)) { seat_set_focus_warp(cursor->seat, c, false); } else { struct sway_container *next_focus = From d1ebbebea0db2f60f0ed03c2022db50830226ec1 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Mon, 28 May 2018 00:55:25 +1000 Subject: [PATCH 5/8] Remove unused function. --- sway/input/seat.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/sway/input/seat.c b/sway/input/seat.c index 7a3e928a3..6cfbe8d49 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -730,13 +730,6 @@ struct sway_container *seat_get_active_child(struct sway_seat *seat, return focus; } -struct sway_container *sway_seat_get_focus(struct sway_seat *seat) { - if (!seat->has_focus) { - return NULL; - } - return seat_get_focus_inactive(seat, &root_container); -} - struct sway_container *seat_get_focus(struct sway_seat *seat) { if (!seat->has_focus) { return NULL; From 1b8de3928714950d715053523d99aa1572ac63e0 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Mon, 28 May 2018 02:14:19 +1000 Subject: [PATCH 6/8] Move previous cursor_position inline. --- include/sway/input/cursor.h | 8 +++----- sway/input/cursor.c | 14 +++----------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 03cb8b830..5dd109cae 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -6,7 +6,9 @@ struct sway_cursor { struct sway_seat *seat; struct wlr_cursor *cursor; - struct cursor_position *previous; + struct { + double x, y; + } previous; struct wlr_xcursor_manager *xcursor_manager; struct wl_client *image_client; @@ -28,10 +30,6 @@ struct sway_cursor { struct wl_listener request_set_cursor; }; -struct cursor_position { - double x, y; -}; - void sway_cursor_destroy(struct sway_cursor *cursor); struct sway_cursor *sway_cursor_create(struct sway_seat *seat); void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 1fa5be34e..3e8fd5d8f 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -147,10 +147,10 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, // Find the container the pointer was previously over struct sway_container *prev_c = container_at_coords(cursor->seat, - cursor->previous->x, cursor->previous->y, &surface, &sx, &sy); + cursor->previous.x, cursor->previous.y, &surface, &sx, &sy); // Update the stored previous position - cursor->previous->x = cursor->cursor->x; - cursor->previous->y = cursor->cursor->y; + cursor->previous.x = cursor->cursor->x; + cursor->previous.y = cursor->cursor->y; struct sway_container *c = container_at_coords(cursor->seat, cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); @@ -476,15 +476,8 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { return NULL; } - struct cursor_position *previous = calloc(1, sizeof(struct cursor_position)); - if (!sway_assert(previous, "could not allocate sway cursor position")) { - free(cursor); - return NULL; - } - struct wlr_cursor *wlr_cursor = wlr_cursor_create(); if (!sway_assert(wlr_cursor, "could not allocate wlr cursor")) { - free(previous); free(cursor); return NULL; } @@ -535,7 +528,6 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { cursor->request_set_cursor.notify = handle_request_set_cursor; cursor->cursor = wlr_cursor; - cursor->previous = previous; return cursor; } From b57f88e7dbefcda5a49ea515b410dc170e642a58 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Mon, 28 May 2018 02:25:42 +1000 Subject: [PATCH 7/8] Avoid assert on container type. --- sway/input/cursor.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 3e8fd5d8f..a0afd78a2 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -178,14 +178,9 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, } else { struct sway_container *next_focus = seat_get_focus_inactive(cursor->seat, &root_container); - if (next_focus) { - if (!sway_assert(next_focus->type == C_VIEW, - "focus inactive container is not a view")) { - return; - } - if (view_is_visible(next_focus->sway_view)) { - seat_set_focus_warp(cursor->seat, next_focus, false); - } + if (next_focus && next_focus->type == C_VIEW && + view_is_visible(next_focus->sway_view)) { + seat_set_focus_warp(cursor->seat, next_focus, false); } } } From 4d8120ccf3097fd919327707eeccc56a329afbb9 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Mon, 28 May 2018 02:35:24 +1000 Subject: [PATCH 8/8] Improve comment. --- sway/input/cursor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index a0afd78a2..6751931d0 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -145,7 +145,7 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, struct wlr_surface *surface = NULL; double sx, sy; - // Find the container the pointer was previously over + // Find the container beneath the pointer's previous position struct sway_container *prev_c = container_at_coords(cursor->seat, cursor->previous.x, cursor->previous.y, &surface, &sx, &sy); // Update the stored previous position