[gtk/wip/synthetic-motion2: 2/3] Add a function to synthesize motion events
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/synthetic-motion2: 2/3] Add a function to synthesize motion events
- Date: Wed, 26 Aug 2020 13:04:32 +0000 (UTC)
commit c101ee13db7b146d65e20330db8da4ffbbd055af
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Feb 21 16:38:36 2020 -0500
Add a function to synthesize motion events
We want to ensure that the pointer position is reflected
when widget geometry changes, so add a function that tells
GDK "please create a motion event at the current position
on this surface".
gdk/gdkdisplay.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
gdk/gdksurface.h | 3 +++
2 files changed, 47 insertions(+)
---
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index 5551af342e..ece4f20ec0 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -499,6 +499,50 @@ generate_grab_broken_event (GdkDisplay *display,
}
}
+void
+gdk_surface_ensure_motion (GdkSurface *surface)
+{
+ GList *l;
+ GdkDisplay *display;
+ GdkSeat *seat;
+ GdkDevice *device;
+ GdkEvent *event;
+ GdkFrameClock *frame_clock;
+ double x, y;
+ GdkModifierType state;
+
+ display = gdk_surface_get_display (surface);
+
+ /* if we have a motion event in the queue, do nothing */
+ for (l = g_queue_peek_head_link (&display->queued_events); l; l = l->next)
+ {
+ event = l->data;
+
+ if (gdk_event_get_event_type (event) == GDK_MOTION_NOTIFY &&
+ gdk_event_get_surface (event) == surface)
+ return;
+ }
+
+ seat = gdk_display_get_default_seat (display);
+ device = gdk_seat_get_pointer (seat);
+
+ if (!gdk_surface_get_device_position (surface, device, &x, &y, &state))
+ return;
+
+ event = gdk_motion_event_new (surface,
+ device,
+ NULL,
+ GDK_CURRENT_TIME,
+ state,
+ x, y,
+ NULL);
+ _gdk_event_queue_append (display, event);
+
+ frame_clock = gdk_surface_get_frame_clock (surface);
+ if (frame_clock)
+ gdk_frame_clock_request_phase (frame_clock, GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS);
+}
+
GdkDeviceGrabInfo *
_gdk_display_get_last_device_grab (GdkDisplay *display,
GdkDevice *device)
diff --git a/gdk/gdksurface.h b/gdk/gdksurface.h
index a03b02a4e3..494178b0a2 100644
--- a/gdk/gdksurface.h
+++ b/gdk/gdksurface.h
@@ -230,6 +230,9 @@ GdkVulkanContext *
gdk_surface_create_vulkan_context(GdkSurface *surface,
GError **error);
+GDK_AVAILABLE_IN_ALL
+void gdk_surface_ensure_motion (GdkSurface *surface);
+
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GdkSurface, g_object_unref)
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]