commit 6f0a0bd3852c6d92f30d43b9a39dc743987584ac
parent 45e4e9217238fe658b99634d284768439969ad79
Author: Tudor Brindus <me@tbrindus.ca>
Date: Sat, 2 May 2020 19:22:15 -0400
input/pointer: only warp cursor when the confine region has changed
Refs #5268.
Diffstat:
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h
@@ -32,6 +32,7 @@ struct sway_cursor {
struct wlr_pointer_constraint_v1 *active_constraint;
pixman_region32_t confine; // invalid if active_constraint == NULL
+ bool active_confine_requires_warp;
struct wlr_pointer_gestures_v1 *pointer_gestures;
struct wl_listener pinch_begin;
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
@@ -111,6 +111,7 @@ struct sway_seat {
struct sway_pointer_constraint {
struct wlr_pointer_constraint_v1 *constraint;
+ struct wl_listener set_region;
struct wl_listener destroy;
};
diff --git 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,