[gtk: 2/9] gdk/events: Add constructor for high-resolution scroll events




commit 51ca454eef480886c5f5e584e5b8c24631f932ab
Author: José Expósito <jose exposito89 gmail com>
Date:   Mon Sep 20 19:59:35 2021 +0200

    gdk/events: Add constructor for high-resolution scroll events
    
    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        | 42 ++++++++++++++++++++++++++++++++++++++++++
 gdk/gdkeventsprivate.h |  9 +++++++++
 2 files changed, 51 insertions(+)
---
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index ba185c2ffb..0e78d337d2 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -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
diff --git a/gdk/gdkeventsprivate.h b/gdk/gdkeventsprivate.h
index 661de6baa8..a36c5d100b 100644
--- a/gdk/gdkeventsprivate.h
+++ b/gdk/gdkeventsprivate.h
@@ -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,


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