From 0e56ebb51af7984cb029707ae3d32bdf1689992f Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 17 Nov 2023 18:24:14 +0100 Subject: [PATCH] wayland: Avoid sending wl_pointer.motion on unchanged coordinates This might happen for a variety of reasons, like monitor edges or pointer constraints. Handle this naturally in MetaWaylandPointer for all these cases. Part-of: --- src/wayland/meta-wayland-pointer.c | 21 +++++++++++++++++---- src/wayland/meta-wayland-pointer.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c index b7f668959..428394499 100644 --- a/src/wayland/meta-wayland-pointer.c +++ b/src/wayland/meta-wayland-pointer.c @@ -397,11 +397,18 @@ meta_wayland_pointer_send_motion (MetaWaylandPointer *pointer, meta_wayland_surface_get_relative_coordinates (pointer->focus_surface, x, y, &sx, &sy); - wl_resource_for_each (resource, &pointer->focus_client->pointer_resources) + if (pointer->last_rel_x != sx || + pointer->last_rel_y != sy) { - wl_pointer_send_motion (resource, time, - wl_fixed_from_double (sx), - wl_fixed_from_double (sy)); + wl_resource_for_each (resource, &pointer->focus_client->pointer_resources) + { + wl_pointer_send_motion (resource, time, + wl_fixed_from_double (sx), + wl_fixed_from_double (sy)); + } + + pointer->last_rel_x = sx; + pointer->last_rel_y = sy; } meta_wayland_pointer_send_relative_motion (pointer, event); @@ -469,6 +476,9 @@ meta_wayland_pointer_enable (MetaWaylandPointer *pointer) "cursor-changed", G_CALLBACK (meta_wayland_pointer_on_cursor_changed), pointer); + + pointer->last_rel_x = -FLT_MAX; + pointer->last_rel_y = -FLT_MAX; } void @@ -966,6 +976,9 @@ meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer, if (pointer->focus_surface == surface) return; + pointer->last_rel_x = -FLT_MAX; + pointer->last_rel_y = -FLT_MAX; + if (pointer->focus_surface != NULL) { uint32_t serial; diff --git a/src/wayland/meta-wayland-pointer.h b/src/wayland/meta-wayland-pointer.h index 7fd8261e5..56001b2e7 100644 --- a/src/wayland/meta-wayland-pointer.h +++ b/src/wayland/meta-wayland-pointer.h @@ -66,6 +66,7 @@ struct _MetaWaylandPointer guint32 grab_serial; guint32 grab_time; float grab_x, grab_y; + float last_rel_x, last_rel_y; ClutterInputDevice *device; MetaWaylandSurface *current;