From: José Expósito Date: Mon, 20 Sep 2021 17:59:35 +0000 (+0200) Subject: gdk/events: Add constructor for high-resolution scroll events X-Git-Tag: archive/raspbian/4.8.3+ds-2+rpi1~3^2~20^2~4^2~3^2~6 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=51ca454eef480886c5f5e584e5b8c24631f932ab;p=gtk4.git 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. --- 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,