From ab8e145e25ae70024b9838856663a18a5aaf3ff1 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 5 Mar 2024 13:43:57 +0100 Subject: [PATCH] wayland: Filter scroll events based on source The POINTER_EMULATED flag was a convenience to filter either side of smooth/discrete events that we should ignore based on the source. This distinction was challenged, first by v120 mice that use Clutter smooth events to deliver semi-discrete changes, second by commit e0c4b2b241 ("backends/native: Mark the emulated smooth scroll event as such") which made the smooth events be flagged as emulated, and the discrete whole-step events marked as real. This distinction feels convenient for the time being, since upper layers might be confused by real smooth scroll events without finish flags. Adapt to this change at MetaWaylandPointer so that we drop the POINTER_EMULATED check, and the events are perhaps filtered based on their source and the preferred wl_seat version of the client that we are talking to. This handles the whole grid of combinations: - wheel sources with wl_seat >=8 result in wl_pointer.axis_value120 from "emulated" smooth scroll events, with value120 information. - wheel sources with wl_seat < 8 result in wl_pointer.axis_discrete from "real" discrete scroll events. - finger/continuous sources prefer smooth events. Previously, always non-emulated for those. Part-of: --- src/wayland/meta-wayland-pointer.c | 34 +++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c index 4d1971c34..9d5a381cd 100644 --- a/src/wayland/meta-wayland-pointer.c +++ b/src/wayland/meta-wayland-pointer.c @@ -706,6 +706,34 @@ handle_button_event (MetaWaylandPointer *pointer, } } +static gboolean +maybe_filter_scroll_event (const ClutterEvent *event, + int client_version) +{ + ClutterScrollSource source; + + source = clutter_event_get_scroll_source (event); + + switch (clutter_event_get_scroll_direction (event)) + { + case CLUTTER_SCROLL_UP: + case CLUTTER_SCROLL_DOWN: + case CLUTTER_SCROLL_LEFT: + case CLUTTER_SCROLL_RIGHT: + if (source == CLUTTER_SCROLL_SOURCE_WHEEL) + return client_version >= WL_POINTER_AXIS_VALUE120_SINCE_VERSION; + + return TRUE; + case CLUTTER_SCROLL_SMOOTH: + if (source == CLUTTER_SCROLL_SOURCE_WHEEL) + return client_version < WL_POINTER_AXIS_VALUE120_SINCE_VERSION; + + return FALSE; + } + + return TRUE; +} + static void handle_scroll_event (MetaWaylandPointer *pointer, const ClutterEvent *event) @@ -718,9 +746,6 @@ handle_scroll_event (MetaWaylandPointer *pointer, MetaWaylandPointerClient *client; ClutterScrollFinishFlags finish_flags; - if (clutter_event_get_flags (event) & CLUTTER_EVENT_FLAG_POINTER_EMULATED) - return; - client = pointer->focus_client; if (!client) return; @@ -796,6 +821,9 @@ handle_scroll_event (MetaWaylandPointer *pointer, { int client_version = wl_resource_get_version (resource); + if (maybe_filter_scroll_event (event, client_version)) + continue; + if (client_version >= WL_POINTER_AXIS_SOURCE_SINCE_VERSION) wl_pointer_send_axis_source (resource, source);