[gtk/wip/exalm/scroll-gesture: 359/369] events: Give scroll events pointer position
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/exalm/scroll-gesture: 359/369] events: Give scroll events pointer position
- Date: Thu, 14 Oct 2021 13:24:57 +0000 (UTC)
commit f0552949c5d670f276a8a2207aaed81e23c9fb37
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Sep 21 13:16:51 2021 +0500
events: Give scroll events pointer position
We'll need to have it for parity with touchpad swipes to use in GtkGesture.
gdk/gdkevents.c | 39 ++++++++++++++++++++++++++++++++++-
gdk/gdkeventsprivate.h | 6 ++++++
gdk/macos/gdkmacosdisplay-translate.c | 6 ++++++
gdk/wayland/gdkdevice-wayland.c | 8 +++++++
gdk/win32/gdkevents-win32.c | 4 ++++
gdk/x11/gdkdevicemanager-xi2.c | 6 ++++++
6 files changed, 68 insertions(+), 1 deletion(-)
---
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index 3ee8905ef3..9fb403eddb 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -603,9 +603,11 @@ gdk_event_queue_handle_scroll_compression (GdkDisplay *display)
GList *l;
GdkSurface *surface = NULL;
GdkDevice *device = NULL;
+ double x = 0.0, y = 0.0;
GdkEvent *last_event = NULL;
GList *scrolls = NULL;
double delta_x, delta_y;
+ gboolean has_coords = FALSE;
GArray *history = NULL;
GdkTimeCoord hist;
@@ -614,6 +616,7 @@ gdk_event_queue_handle_scroll_compression (GdkDisplay *display)
while (l)
{
GdkEvent *event = l->data;
+ double event_x, event_y;
if (event->flags & GDK_EVENT_PENDING)
break;
@@ -630,11 +633,22 @@ gdk_event_queue_handle_scroll_compression (GdkDisplay *display)
device != event->device)
break;
+ gdk_event_get_position (event, &event_x, &event_y);
+
+ if (has_coords && x != event_x)
+ break;
+
+ if (has_coords && y != event_y)
+ break;
+
if (!last_event)
last_event = event;
surface = event->surface;
device = event->device;
+ has_coords = TRUE;
+ x = event_x;
+ y = event_y;
scrolls = l;
l = l->prev;
@@ -681,6 +695,8 @@ gdk_event_queue_handle_scroll_compression (GdkDisplay *display)
gdk_event_get_device_tool (old_event),
gdk_event_get_time (old_event),
gdk_event_get_modifier_state (old_event),
+ x,
+ y,
delta_x + dx,
delta_y + dy,
gdk_scroll_event_is_stop (old_event));
@@ -2273,6 +2289,19 @@ gdk_scroll_event_get_state (GdkEvent *event)
return self->state;
}
+static gboolean
+gdk_scroll_event_get_position (GdkEvent *event,
+ double *x,
+ double *y)
+{
+ GdkScrollEvent *self = (GdkScrollEvent *) event;
+
+ *x = self->x;
+ *y = self->y;
+
+ return TRUE;
+}
+
static GdkDeviceTool *
gdk_scroll_event_get_tool (GdkEvent *event)
{
@@ -2286,7 +2315,7 @@ static const GdkEventTypeInfo gdk_scroll_event_info = {
NULL,
gdk_scroll_event_finalize,
gdk_scroll_event_get_state,
- NULL,
+ gdk_scroll_event_get_position,
NULL,
gdk_scroll_event_get_tool,
NULL,
@@ -2302,6 +2331,8 @@ gdk_scroll_event_new (GdkSurface *surface,
GdkDeviceTool *tool,
guint32 time,
GdkModifierType state,
+ double x,
+ double y,
double delta_x,
double delta_y,
gboolean is_stop)
@@ -2311,6 +2342,8 @@ gdk_scroll_event_new (GdkSurface *surface,
self->tool = tool != NULL ? g_object_ref (tool) : NULL;
self->state = state;
self->direction = GDK_SCROLL_SMOOTH;
+ self->x = x;
+ self->y = y;
self->delta_x = delta_x;
self->delta_y = delta_y;
self->is_stop = is_stop;
@@ -2324,6 +2357,8 @@ gdk_scroll_event_new_discrete (GdkSurface *surface,
GdkDeviceTool *tool,
guint32 time,
GdkModifierType state,
+ double x,
+ double y,
GdkScrollDirection direction,
gboolean emulated)
{
@@ -2331,6 +2366,8 @@ gdk_scroll_event_new_discrete (GdkSurface *surface,
self->tool = tool != NULL ? g_object_ref (tool) : NULL;
self->state = state;
+ self->x = x;
+ self->y = y;
self->direction = direction;
self->pointer_emulated = emulated;
diff --git a/gdk/gdkeventsprivate.h b/gdk/gdkeventsprivate.h
index 1ed555661f..2868ddbb8d 100644
--- a/gdk/gdkeventsprivate.h
+++ b/gdk/gdkeventsprivate.h
@@ -226,6 +226,8 @@ struct _GdkScrollEvent
{
GdkEvent parent_instance;
+ double x;
+ double y;
GdkModifierType state;
GdkScrollDirection direction;
double delta_x;
@@ -483,6 +485,8 @@ GdkEvent * gdk_scroll_event_new (GdkSurface *surface,
GdkDeviceTool *tool,
guint32 time,
GdkModifierType state,
+ double x,
+ double y,
double delta_x,
double delta_y,
gboolean is_stop);
@@ -492,6 +496,8 @@ GdkEvent * gdk_scroll_event_new_discrete (GdkSurface *surface,
GdkDeviceTool *tool,
guint32 time,
GdkModifierType state,
+ double x,
+ double y,
GdkScrollDirection direction,
gboolean emulated);
diff --git a/gdk/macos/gdkmacosdisplay-translate.c b/gdk/macos/gdkmacosdisplay-translate.c
index 3400d0f9c3..32f59f1044 100644
--- a/gdk/macos/gdkmacosdisplay-translate.c
+++ b/gdk/macos/gdkmacosdisplay-translate.c
@@ -637,6 +637,8 @@ fill_scroll_event (GdkMacosDisplay *self,
NULL,
get_time_from_ns_event (nsevent),
state,
+ x,
+ y,
-sx,
-sy,
FALSE);
@@ -674,6 +676,8 @@ fill_scroll_event (GdkMacosDisplay *self,
NULL,
get_time_from_ns_event (nsevent),
state,
+ x,
+ y,
direction,
TRUE);
_gdk_event_queue_append (GDK_DISPLAY (self), emulated);
@@ -687,6 +691,8 @@ fill_scroll_event (GdkMacosDisplay *self,
NULL,
get_time_from_ns_event (nsevent),
state,
+ x,
+ y,
dx,
dy,
FALSE);
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index fdfb8968c0..5dc8e06a1b 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -1392,6 +1392,8 @@ flush_discrete_scroll_event (GdkWaylandSeat *seat,
NULL,
seat->pointer_info.time,
device_get_modifiers (seat->logical_pointer),
+ seat->pointer_info.surface_x,
+ seat->pointer_info.surface_y,
direction,
TRUE);
@@ -1413,6 +1415,8 @@ flush_smooth_scroll_event (GdkWaylandSeat *seat,
NULL,
seat->pointer_info.time,
device_get_modifiers (seat->logical_pointer),
+ seat->pointer_info.surface_x,
+ seat->pointer_info.surface_y,
delta_x, delta_y,
is_stop);
@@ -3889,6 +3893,8 @@ tablet_tool_handle_wheel (void *data,
tablet->current_tool->tool,
tablet->pointer_info.time,
device_get_modifiers (tablet->logical_device),
+ tablet->pointer_info.surface_x,
+ tablet->pointer_info.surface_y,
0, clicks,
FALSE);
@@ -3900,6 +3906,8 @@ tablet_tool_handle_wheel (void *data,
tablet->current_tool->tool,
tablet->pointer_info.time,
device_get_modifiers (tablet->logical_device),
+ tablet->pointer_info.surface_x,
+ tablet->pointer_info.surface_y,
clicks > 0 ? GDK_SCROLL_DOWN : GDK_SCROLL_UP,
TRUE);
diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c
index 2576a6711d..81d5be5cb1 100644
--- a/gdk/win32/gdkevents-win32.c
+++ b/gdk/win32/gdkevents-win32.c
@@ -2773,6 +2773,8 @@ gdk_event_translate (MSG *msg,
NULL,
_gdk_win32_get_next_tick (msg->time),
build_pointer_event_state (msg),
+ point.x,
+ point.y,
delta_x,
delta_y,
FALSE);
@@ -2793,6 +2795,8 @@ gdk_event_translate (MSG *msg,
NULL,
_gdk_win32_get_next_tick (msg->time),
build_pointer_event_state (msg),
+ point.x,
+ point.y,
direction,
TRUE);
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index e4114e5279..ecbd7d85d2 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -1643,6 +1643,8 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
NULL,
xev->time,
_gdk_x11_device_xi2_translate_state (&xev->mods,
&xev->buttons, &xev->group),
+ (double) xev->event_x / scale,
+ (double) xev->event_x / scale,
direction,
FALSE);
@@ -1746,6 +1748,8 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
NULL,
xev->time,
state,
+ (double) xev->event_x / scale,
+ (double) xev->event_y / scale,
direction,
FALSE);
}
@@ -1756,6 +1760,8 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
NULL,
xev->time,
state,
+ (double) xev->event_x / scale,
+ (double) xev->event_y / scale,
delta_x,
delta_y,
delta_x == 0.0 && delta_y == 0.0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]