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




commit 686ced2a79ccd7fcff6b903c081cd2845de9827f
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Feb 21 16:38:36 2020 -0500

    Add a function to request 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, if one doesn't happen already".

 gdk/gdksurface.c        | 54 ++++++++++++++++++++++++++++++++++++++++++++++++-
 gdk/gdksurface.h        |  3 +++
 gdk/gdksurfaceprivate.h |  1 +
 3 files changed, 57 insertions(+), 1 deletion(-)
---
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index f89061a002..19fce70cbf 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -2338,6 +2338,40 @@ gdk_drag_begin (GdkSurface          *surface,
   return GDK_SURFACE_GET_CLASS (surface)->drag_begin (surface, device, content, actions, dx, dy);
 }
 
+static void
+gdk_surface_ensure_motion (GdkSurface *surface)
+{
+  GdkDisplay *display;
+  GdkSeat *seat;
+  GdkDevice *device;
+  GdkEvent *event;
+  double x, y;
+  GdkModifierType state;
+
+  if (!surface->request_motion)
+    return;
+
+  surface->request_motion = FALSE;
+
+  display = gdk_surface_get_display (surface);
+  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_surface_handle_event (event);
+  gdk_event_unref (event);
+}
+
 static void
 gdk_surface_flush_events (GdkFrameClock *clock,
                           void          *data)
@@ -2345,6 +2379,7 @@ gdk_surface_flush_events (GdkFrameClock *clock,
   GdkSurface *surface = GDK_SURFACE (data);
 
   _gdk_event_queue_flush (surface->display);
+  gdk_surface_ensure_motion (surface);
   _gdk_display_pause_events (surface->display);
 
   gdk_frame_clock_request_phase (clock, GDK_FRAME_CLOCK_PHASE_RESUME_EVENTS);
@@ -2806,7 +2841,12 @@ gdk_surface_handle_event (GdkEvent *event)
     }
   else
     {
-      g_signal_emit (gdk_event_get_surface (event), signals[EVENT], 0, event, &handled);
+      GdkSurface *surface = gdk_event_get_surface (event);
+
+      if (gdk_event_get_event_type (event) == GDK_MOTION_NOTIFY)
+        surface->request_motion = FALSE;
+
+      g_signal_emit (surface, signals[EVENT], 0, event, &handled);
     }
 
   if (GDK_PROFILER_IS_RUNNING)
@@ -2815,6 +2855,18 @@ gdk_surface_handle_event (GdkEvent *event)
   return handled;
 }
 
+void
+gdk_surface_request_motion (GdkSurface *surface)
+{
+  GdkFrameClock *frame_clock;
+
+  surface->request_motion = TRUE;
+
+  frame_clock = gdk_surface_get_frame_clock (surface);
+  if (frame_clock)
+    gdk_frame_clock_request_phase (frame_clock, GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS);
+}
+
 /**
  * gdk_surface_translate_coordinates:
  * @from: the origin surface
diff --git a/gdk/gdksurface.h b/gdk/gdksurface.h
index a03b02a4e3..bd6d0e54a3 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_request_motion (GdkSurface *surface);
+
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GdkSurface, g_object_unref)
 
 G_END_DECLS
diff --git a/gdk/gdksurfaceprivate.h b/gdk/gdksurfaceprivate.h
index 36db8286af..8b639f5510 100644
--- a/gdk/gdksurfaceprivate.h
+++ b/gdk/gdksurfaceprivate.h
@@ -72,6 +72,7 @@ struct _GdkSurface
   guint frame_clock_events_paused : 1;
   guint autohide : 1;
   guint shortcuts_inhibited : 1;
+  guint request_motion : 1;
 
   struct {
     GdkGravity surface_anchor;


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