summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Foreman <derek.foreman@collabora.com>2022-08-10 12:59:20 -0500
committerMarius Vlad <marius.vlad@collabora.com>2022-08-12 10:55:54 +0300
commit8f8ff5f2945a5cb6348d7453730beb4c4983a2b7 (patch)
treeb3bb455d2fc27cc65045b95ae20fe0f7df3286d1
parentc32e3c6bc0a8399d4fa5195a92dafecd2d559310 (diff)
downloadweston-8f8ff5f2945a5cb6348d7453730beb4c4983a2b7.tar.gz
clients: Set the hotspot with attach if we already have a valid cursor
We want atomic hotspot updates - this can't happen with wl_pointer_set_cursor. So if we have a surface that already has a cursor role, just update the hotspot when attaching new content. Signed-off-by: Derek Foreman <derek.foreman@collabora.com> (cherry picked from commit 646cc1b389cc70e742d5cebef3a3b94e9b0a0c9f)
-rw-r--r--clients/window.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/clients/window.c b/clients/window.c
index dc9f32ca..bc9a8a83 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -352,6 +352,8 @@ struct input {
struct toytimer cursor_timer;
bool cursor_timer_running;
struct wl_surface *pointer_surface;
+ bool pointer_surface_has_role;
+ int hotspot_x, hotspot_y;
uint32_t modifiers;
uint32_t pointer_enter_serial;
uint32_t cursor_serial;
@@ -2776,6 +2778,7 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
input->display->serial = serial;
input->pointer_enter_serial = serial;
input->pointer_focus = window;
+ input->pointer_surface_has_role = false;
input->sx = sx;
input->sy = sy;
@@ -3788,6 +3791,7 @@ input_set_pointer_image_index(struct input *input, int index)
struct wl_buffer *buffer;
struct wl_cursor *cursor;
struct wl_cursor_image *image;
+ int dx = 0, dy = 0;
if (!input->pointer)
return;
@@ -3806,13 +3810,24 @@ input_set_pointer_image_index(struct input *input, int index)
if (!buffer)
return;
- wl_surface_attach(input->pointer_surface, buffer, 0, 0);
+ if (input->pointer_surface_has_role) {
+ dx = input->hotspot_x - image->hotspot_x;
+ dy = input->hotspot_y - image->hotspot_y;
+ }
+ wl_surface_attach(input->pointer_surface, buffer, dx, dy);
wl_surface_damage(input->pointer_surface, 0, 0,
image->width, image->height);
wl_surface_commit(input->pointer_surface);
- wl_pointer_set_cursor(input->pointer, input->pointer_enter_serial,
- input->pointer_surface,
- image->hotspot_x, image->hotspot_y);
+
+ if (!input->pointer_surface_has_role) {
+ wl_pointer_set_cursor(input->pointer,
+ input->pointer_enter_serial,
+ input->pointer_surface,
+ image->hotspot_x, image->hotspot_y);
+ input->pointer_surface_has_role = true;
+ }
+ input->hotspot_x = image->hotspot_x;
+ input->hotspot_y = image->hotspot_y;
}
static const struct wl_callback_listener pointer_surface_listener;
@@ -3824,11 +3839,14 @@ input_set_pointer_special(struct input *input)
wl_pointer_set_cursor(input->pointer,
input->pointer_enter_serial,
NULL, 0, 0);
+ input->pointer_surface_has_role = false;
return true;
}
- if (input->current_cursor == CURSOR_UNSET)
+ if (input->current_cursor == CURSOR_UNSET) {
+ input->pointer_surface_has_role = false;
return true;
+ }
return false;
}
@@ -5923,6 +5941,7 @@ display_add_input(struct display *d, uint32_t id, int display_seat_version)
}
input->pointer_surface = wl_compositor_create_surface(d->compositor);
+ input->pointer_surface_has_role = false;
toytimer_init(&input->cursor_timer, CLOCK_MONOTONIC, d,
cursor_timer_func);