diff options
author | Tudor Brindus <me@tbrindus.ca> | 2020-05-02 19:22:15 -0400 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-05-21 10:45:08 +0200 |
commit | 6f0a0bd3852c6d92f30d43b9a39dc743987584ac (patch) | |
tree | 66b836ab37f4cf84957aaab4bdbc200691d3e08e | |
parent | swaybar: add NULL check when listing workspaces (diff) | |
download | sway-6f0a0bd3852c6d92f30d43b9a39dc743987584ac.tar.gz sway-6f0a0bd3852c6d92f30d43b9a39dc743987584ac.tar.zst sway-6f0a0bd3852c6d92f30d43b9a39dc743987584ac.zip |
input/pointer: only warp cursor when the confine region has changed
Refs #5268.
-rw-r--r-- | include/sway/input/cursor.h | 1 | ||||
-rw-r--r-- | include/sway/input/seat.h | 1 | ||||
-rw-r--r-- | sway/input/cursor.c | 17 |
3 files changed, 18 insertions, 1 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 8f9f84d0..ddece700 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h | |||
@@ -32,6 +32,7 @@ struct sway_cursor { | |||
32 | 32 | ||
33 | struct wlr_pointer_constraint_v1 *active_constraint; | 33 | struct wlr_pointer_constraint_v1 *active_constraint; |
34 | pixman_region32_t confine; // invalid if active_constraint == NULL | 34 | pixman_region32_t confine; // invalid if active_constraint == NULL |
35 | bool active_confine_requires_warp; | ||
35 | 36 | ||
36 | struct wlr_pointer_gestures_v1 *pointer_gestures; | 37 | struct wlr_pointer_gestures_v1 *pointer_gestures; |
37 | struct wl_listener pinch_begin; | 38 | struct wl_listener pinch_begin; |
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index 6a46fa91..66f8f7e4 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h | |||
@@ -111,6 +111,7 @@ struct sway_seat { | |||
111 | struct sway_pointer_constraint { | 111 | struct sway_pointer_constraint { |
112 | struct wlr_pointer_constraint_v1 *constraint; | 112 | struct wlr_pointer_constraint_v1 *constraint; |
113 | 113 | ||
114 | struct wl_listener set_region; | ||
114 | struct wl_listener destroy; | 115 | struct wl_listener destroy; |
115 | }; | 116 | }; |
116 | 117 | ||
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) { | |||
774 | struct wlr_pointer_constraint_v1 *constraint = cursor->active_constraint; | 774 | struct wlr_pointer_constraint_v1 *constraint = cursor->active_constraint; |
775 | pixman_region32_t *region = &constraint->region; | 775 | pixman_region32_t *region = &constraint->region; |
776 | struct sway_view *view = view_from_wlr_surface(constraint->surface); | 776 | struct sway_view *view = view_from_wlr_surface(constraint->surface); |
777 | if (view) { | 777 | if (cursor->active_confine_requires_warp && view) { |
778 | cursor->active_confine_requires_warp = false; | ||
779 | |||
778 | struct sway_container *con = view->container; | 780 | struct sway_container *con = view->container; |
779 | 781 | ||
780 | double sx = cursor->cursor->x - con->content_x + view->geometry.x; | 782 | double sx = cursor->cursor->x - con->content_x + view->geometry.x; |
@@ -813,6 +815,13 @@ static void handle_constraint_commit(struct wl_listener *listener, | |||
813 | check_constraint_region(cursor); | 815 | check_constraint_region(cursor); |
814 | } | 816 | } |
815 | 817 | ||
818 | static void handle_pointer_constraint_set_region(struct wl_listener *listener, | ||
819 | void *data) { | ||
820 | struct sway_cursor *cursor = | ||
821 | wl_container_of(listener, cursor, constraint_commit); | ||
822 | cursor->active_confine_requires_warp = true; | ||
823 | } | ||
824 | |||
816 | static void handle_request_pointer_set_cursor(struct wl_listener *listener, | 825 | static void handle_request_pointer_set_cursor(struct wl_listener *listener, |
817 | void *data) { | 826 | void *data) { |
818 | struct sway_cursor *cursor = | 827 | struct sway_cursor *cursor = |
@@ -1224,6 +1233,7 @@ void handle_constraint_destroy(struct wl_listener *listener, void *data) { | |||
1224 | struct sway_seat *seat = constraint->seat->data; | 1233 | struct sway_seat *seat = constraint->seat->data; |
1225 | struct sway_cursor *cursor = seat->cursor; | 1234 | struct sway_cursor *cursor = seat->cursor; |
1226 | 1235 | ||
1236 | wl_list_remove(&sway_constraint->set_region.link); | ||
1227 | wl_list_remove(&sway_constraint->destroy.link); | 1237 | wl_list_remove(&sway_constraint->destroy.link); |
1228 | 1238 | ||
1229 | if (cursor->active_constraint == constraint) { | 1239 | if (cursor->active_constraint == constraint) { |
@@ -1247,6 +1257,9 @@ void handle_pointer_constraint(struct wl_listener *listener, void *data) { | |||
1247 | calloc(1, sizeof(struct sway_pointer_constraint)); | 1257 | calloc(1, sizeof(struct sway_pointer_constraint)); |
1248 | sway_constraint->constraint = constraint; | 1258 | sway_constraint->constraint = constraint; |
1249 | 1259 | ||
1260 | sway_constraint->set_region.notify = handle_pointer_constraint_set_region; | ||
1261 | wl_signal_add(&constraint->events.set_region, &sway_constraint->set_region); | ||
1262 | |||
1250 | sway_constraint->destroy.notify = handle_constraint_destroy; | 1263 | sway_constraint->destroy.notify = handle_constraint_destroy; |
1251 | wl_signal_add(&constraint->events.destroy, &sway_constraint->destroy); | 1264 | wl_signal_add(&constraint->events.destroy, &sway_constraint->destroy); |
1252 | 1265 | ||
@@ -1290,6 +1303,8 @@ void sway_cursor_constrain(struct sway_cursor *cursor, | |||
1290 | return; | 1303 | return; |
1291 | } | 1304 | } |
1292 | 1305 | ||
1306 | cursor->active_confine_requires_warp = true; | ||
1307 | |||
1293 | // FIXME: Big hack, stolen from wlr_pointer_constraints_v1.c:121. | 1308 | // FIXME: Big hack, stolen from wlr_pointer_constraints_v1.c:121. |
1294 | // This is necessary because the focus may be set before the surface | 1309 | // This is necessary because the focus may be set before the surface |
1295 | // has finished committing, which means that warping won't work properly, | 1310 | // has finished committing, which means that warping won't work properly, |