From 6f0a0bd3852c6d92f30d43b9a39dc743987584ac Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Sat, 2 May 2020 19:22:15 -0400 Subject: input/pointer: only warp cursor when the confine region has changed Refs #5268. --- sway/input/cursor.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'sway/input/cursor.c') diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 646c61b3..8121cc84 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -774,7 +774,9 @@ static void check_constraint_region(struct sway_cursor *cursor) { struct wlr_pointer_constraint_v1 *constraint = cursor->active_constraint; pixman_region32_t *region = &constraint->region; struct sway_view *view = view_from_wlr_surface(constraint->surface); - if (view) { + if (cursor->active_confine_requires_warp && view) { + cursor->active_confine_requires_warp = false; + struct sway_container *con = view->container; double sx = cursor->cursor->x - con->content_x + view->geometry.x; @@ -813,6 +815,13 @@ static void handle_constraint_commit(struct wl_listener *listener, check_constraint_region(cursor); } +static void handle_pointer_constraint_set_region(struct wl_listener *listener, + void *data) { + struct sway_cursor *cursor = + wl_container_of(listener, cursor, constraint_commit); + cursor->active_confine_requires_warp = true; +} + static void handle_request_pointer_set_cursor(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = @@ -1224,6 +1233,7 @@ void handle_constraint_destroy(struct wl_listener *listener, void *data) { struct sway_seat *seat = constraint->seat->data; struct sway_cursor *cursor = seat->cursor; + wl_list_remove(&sway_constraint->set_region.link); wl_list_remove(&sway_constraint->destroy.link); if (cursor->active_constraint == constraint) { @@ -1247,6 +1257,9 @@ void handle_pointer_constraint(struct wl_listener *listener, void *data) { calloc(1, sizeof(struct sway_pointer_constraint)); sway_constraint->constraint = constraint; + sway_constraint->set_region.notify = handle_pointer_constraint_set_region; + wl_signal_add(&constraint->events.set_region, &sway_constraint->set_region); + sway_constraint->destroy.notify = handle_constraint_destroy; wl_signal_add(&constraint->events.destroy, &sway_constraint->destroy); @@ -1290,6 +1303,8 @@ void sway_cursor_constrain(struct sway_cursor *cursor, return; } + cursor->active_confine_requires_warp = true; + // FIXME: Big hack, stolen from wlr_pointer_constraints_v1.c:121. // This is necessary because the focus may be set before the surface // has finished committing, which means that warping won't work properly, -- cgit v1.2.3-54-g00ecf