[gtk/wip/synthetic-motion2: 2/4] Add a function to synthesize motion events




commit 4c9869b2e26a07aa33141b79110e116765bc2d6d
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 | 41 +++++++++++++++++++++++++++++++++++++++++
 gdk/gdksurface.h |  3 +++
 2 files changed, 44 insertions(+)
---
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index 5551af342e..c6d2aad76e 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -499,6 +499,47 @@ 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)
+        return;
+  }
+
+  seat = gdk_display_get_default_seat (display);
+  device = gdk_seat_get_pointer (seat);
+  gdk_surface_get_device_position (surface, device, &x, &y, &state);
+
+  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 9b1613147f..e5ce4d23b1 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]