[mutter] backends/x11: Emit discrete scroll events for accumulated smooth events



commit a5d692582dbd29fa39a01350f416997db2d495c9
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Thu Feb 11 12:12:09 2021 +0100

    backends/x11: Emit discrete scroll events for accumulated smooth events
    
    MetaVirtualInputDeviceX11 currently doesn't handle smooth scroll events
    at all.
    So, if a user of the remote desktop API uses smooth scroll events, then
    only the wayland backend handles these events.
    The user of the remote desktop API however, might not know which
    backend is being used and actually the user should not even have to
    care about it.
    
    Actual smooth events cannot be emulated in the X11 events.
    What can be done however is accumulating smooth events and then when
    the accumulated steps surpass the DISCRETE_SCROLL_STEP value, emit a
    discrete scroll event.
    So, do exactly that, to make smooth scroll events work when the remote
    desktop API is used with the x11 backend.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1727>

 src/backends/x11/meta-virtual-input-device-x11.c | 38 ++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
---
diff --git a/src/backends/x11/meta-virtual-input-device-x11.c 
b/src/backends/x11/meta-virtual-input-device-x11.c
index beeae72b99..9ae6554cdb 100644
--- a/src/backends/x11/meta-virtual-input-device-x11.c
+++ b/src/backends/x11/meta-virtual-input-device-x11.c
@@ -28,9 +28,14 @@
 #include "meta-keymap-x11.h"
 #include "meta-virtual-input-device-x11.h"
 
+#define DISCRETE_SCROLL_STEP 10.0
+
 struct _MetaVirtualInputDeviceX11
 {
   ClutterVirtualInputDevice parent;
+
+  double accum_scroll_dx;
+  double accum_scroll_dy;
 };
 
 G_DEFINE_TYPE (MetaVirtualInputDeviceX11,
@@ -112,6 +117,39 @@ meta_virtual_input_device_x11_notify_scroll_continuous (ClutterVirtualInputDevic
                                                         ClutterScrollSource        scroll_source,
                                                         ClutterScrollFinishFlags   finish_flags)
 {
+  MetaVirtualInputDeviceX11 *virtual_device_x11;
+  ClutterScrollDirection direction;
+  int i, n_xscrolls, n_yscrolls;
+
+  virtual_device_x11 = META_VIRTUAL_INPUT_DEVICE_X11 (virtual_device);
+
+  virtual_device_x11->accum_scroll_dx += dx;
+  virtual_device_x11->accum_scroll_dy += dy;
+  n_xscrolls = floor ((fabs (virtual_device_x11->accum_scroll_dx) + DBL_EPSILON) /
+                      DISCRETE_SCROLL_STEP);
+  n_yscrolls = floor ((fabs (virtual_device_x11->accum_scroll_dy) + DBL_EPSILON) /
+                      DISCRETE_SCROLL_STEP);
+
+  direction = virtual_device_x11->accum_scroll_dx > 0 ? CLUTTER_SCROLL_RIGHT
+                                                      : CLUTTER_SCROLL_LEFT;
+  for (i = 0; i < n_xscrolls; ++i)
+    {
+      meta_virtual_input_device_x11_notify_discrete_scroll (
+        virtual_device, time_us, direction, CLUTTER_SCROLL_SOURCE_WHEEL);
+    }
+
+  direction = virtual_device_x11->accum_scroll_dy > 0 ? CLUTTER_SCROLL_DOWN
+                                                      : CLUTTER_SCROLL_UP;
+  for (i = 0; i < n_yscrolls; ++i)
+    {
+      meta_virtual_input_device_x11_notify_discrete_scroll (
+        virtual_device, time_us, direction, CLUTTER_SCROLL_SOURCE_WHEEL);
+    }
+
+  virtual_device_x11->accum_scroll_dx =
+    fmod (virtual_device_x11->accum_scroll_dx, DISCRETE_SCROLL_STEP);
+  virtual_device_x11->accum_scroll_dy =
+    fmod (virtual_device_x11->accum_scroll_dy, DISCRETE_SCROLL_STEP);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]