gdk/events: Add constructor for high-resolution scroll events
authorJosé Expósito <jose.exposito89@gmail.com>
Mon, 20 Sep 2021 17:59:35 +0000 (19:59 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Wed, 10 Aug 2022 14:23:58 +0000 (14:23 +0000)
Starting with Linux Kernel v5.0 two new axes are available for
mice that support high-resolution wheel scrolling: REL_WHEEL_HI_RES and
REL_HWHEEL_HI_RES.

Both axes send data in fractions of 120 where each multiple of 120
amounts to one logical scroll event. Fractions of 120 indicate a wheel
movement less than one detent.

The 120 magic number is a copy of the Windows API, so this new
constructor can be used both in Linux >= 5.0 and Windows >= Vista.

gdk/gdkevents.c
gdk/gdkeventsprivate.h

index ba185c2ffbe360a13e5abaf18d4a84bf8df32a82..0e78d337d2a67e16d80009b2e31eac11a39a6234 100644 (file)
@@ -2377,6 +2377,48 @@ gdk_scroll_event_new_discrete (GdkSurface         *surface,
   return (GdkEvent *) self;
 }
 
+/*< private >
+ * gtk_scroll_event_new_value120:
+ * @surface: the `GdkSurface` of the event
+ * @device: the `GdkDevice` of the event
+ * @tool: (nullable): the tool that generated to event
+ * @time: the event serial
+ * @state: Flags to indicate the state of modifier keys and mouse buttons
+ *   in events.
+ * @direction: scroll direction.
+ * @delta_x: delta on the X axis in the 120.0 scale
+ * @delta_x: delta on the Y axis in the 120.0 scale
+ *
+ * Creates a new discrete GdkScrollEvent for high resolution mouse wheels.
+ *
+ * Both axes send data in fractions of 120 where each multiple of 120
+ * amounts to one logical scroll event. Fractions of 120 indicate a wheel
+ * movement less than one detent.
+ *
+ * Returns: the newly created scroll event
+ */
+GdkEvent *
+gdk_scroll_event_new_value120 (GdkSurface         *surface,
+                               GdkDevice          *device,
+                               GdkDeviceTool      *tool,
+                               guint32             time,
+                               GdkModifierType     state,
+                               GdkScrollDirection  direction,
+                               double              delta_x,
+                               double              delta_y)
+{
+  GdkScrollEvent *self = gdk_event_alloc (GDK_SCROLL, surface, device, time);
+
+  self->tool = tool != NULL ? g_object_ref (tool) : NULL;
+  self->state = state;
+  self->direction = direction;
+  self->delta_x = delta_x / 120.0;
+  self->delta_y = delta_y / 120.0;
+  self->unit = GDK_SCROLL_UNIT_WHEEL;
+
+  return (GdkEvent *) self;
+}
+
 /**
  * gdk_scroll_event_get_direction:
  * @event: (type GdkScrollEvent): a scroll event
index 661de6baa8aa5422741c976808989f8b7d6ec884..a36c5d100b61decb3b425539774a11c9ea2217a1 100644 (file)
@@ -495,6 +495,15 @@ GdkEvent * gdk_scroll_event_new_discrete (GdkSurface         *surface,
                                           GdkModifierType     state,
                                           GdkScrollDirection  direction);
 
+GdkEvent * gdk_scroll_event_new_value120 (GdkSurface         *surface,
+                                          GdkDevice          *device,
+                                          GdkDeviceTool      *tool,
+                                          guint32             time,
+                                          GdkModifierType     state,
+                                          GdkScrollDirection  direction,
+                                          double              delta_x,
+                                          double              delta_y);
+
 GdkEvent * gdk_touch_event_new          (GdkEventType      type,
                                          GdkEventSequence *sequence,
                                          GdkSurface       *surface,