[gtk/wip/synthetic-motion: 1/3] Add a function to synthesize motion events



commit 166c7f8a036e641f336a8ba2a09e06d399b1b226
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 | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 gdk/gdksurface.h |  3 +++
 2 files changed, 51 insertions(+)
---
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index eb3826f48f..942b324a67 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -515,6 +515,54 @@ generate_grab_broken_event (GdkDisplay *display,
     }
 }
 
+void
+gdk_surface_ensure_motion (GdkSurface *surface)
+{
+  GList *list, *l;
+  GdkDisplay *display;
+  GdkSeat *seat;
+  GdkDevice *device;
+  GdkEvent *event;
+  GdkFrameClock *frame_clock;
+
+  display = gdk_surface_get_display (surface);
+
+  for (l = g_queue_peek_head_link (&display->queued_events); l; l = l->next)
+    {
+      event = l->data;
+
+      if (event->any.type == GDK_MOTION_NOTIFY)
+        return;
+  }
+
+  seat = gdk_display_get_default_seat (display);
+  device = gdk_seat_get_pointer (seat);
+  list = gdk_seat_get_slaves (seat, GDK_SEAT_CAPABILITY_POINTER);
+  for (l = list; l; l = l->next)
+    {
+      GdkDevice *source_device = l->data;
+      double x, y;
+      GdkModifierType state;
+
+      gdk_surface_get_device_position (surface, device, &x, &y, &state);
+      event = gdk_event_motion_new (surface,
+                                    device,
+                                    source_device,
+                                    NULL,
+                                    GDK_CURRENT_TIME,
+                                    state,
+                                    x, y,
+                                    NULL);
+      _gdk_event_queue_append (display, event);
+    }
+
+  g_list_free (list);
+
+  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 6f50e66b7b..c39e6ef137 100644
--- a/gdk/gdksurface.h
+++ b/gdk/gdksurface.h
@@ -614,6 +614,9 @@ GdkVulkanContext *
                gdk_surface_create_vulkan_context(GdkSurface     *surface,
                                                  GError        **error);
 
+GDK_AVAILABLE_IN_ALL
+void           gdk_surface_ensure_motion (GdkSurface *surface);
+
 G_END_DECLS
 
 #endif /* __GDK_SURFACE_H__ */


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