gdk: Always request "flush events" frame clock phase on events
authorCarlos Garnacho <carlosg@gnome.org>
Wed, 26 Jan 2022 14:49:29 +0000 (15:49 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Wed, 26 Jan 2022 14:49:29 +0000 (15:49 +0100)
This change is done for 2 reasons:

- The logic to request this phase when compressing scroll events is
  slightly broken. If there are multiple scroll events that are
  coalesced into one, the surface frame clock will not get this request.
  The worst case is having >= 2 scroll events on every frame, as the
  compressed event will be left in the queue, and be further compressed
  on future events.

- Even scroll events aside, this phase is requested in oddly specific
  places that are not enough to cover all events, others do rely on
  unrelated GdkFrameClock activity that happens to flush the events
  as well.

Unify this phase request so it explicitly happens on the arrival of any
event. This ensures that events (compressed or not) will be handled
promptly after arrival.

gdk/gdkevents.c
gdk/gdksurface.c

index 1f4a920720bdec8025a852097f12cc3d993b2534..454e69ed64093d2e9a1f99a11d1cd6dde929e61d 100644 (file)
@@ -719,14 +719,6 @@ gdk_event_queue_handle_scroll_compression (GdkDisplay *display)
 
       gdk_event_unref (old_event);
     }
-
-  if (g_queue_get_length (&display->queued_events) == 1 &&
-      g_queue_peek_head_link (&display->queued_events) == scrolls)
-    {
-      GdkFrameClock *clock = gdk_surface_get_frame_clock (surface);
-      if (clock) /* might be NULL if surface was destroyed */
-        gdk_frame_clock_request_phase (clock, GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS);
-    }
 }
 
 static void
@@ -832,14 +824,6 @@ _gdk_event_queue_handle_motion_compression (GdkDisplay *display)
       g_queue_delete_link (&display->queued_events, pending_motions);
       pending_motions = next;
     }
-
-  if (g_queue_get_length (&display->queued_events) == 1 &&
-      g_queue_peek_head_link (&display->queued_events) == pending_motions)
-    {
-      GdkFrameClock *clock = gdk_surface_get_frame_clock (pending_motion_surface);
-      if (clock) /* might be NULL if surface was destroyed */
-        gdk_frame_clock_request_phase (clock, GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS);
-    }
 }
 
 void
index 1f176b9b87ba79a92aa2f91e98a8fdba842c5f25..ddfa767a9911e4d731aa650d904d63108d431a65 100644 (file)
@@ -2244,7 +2244,7 @@ _gdk_windowing_got_event (GdkDisplay *display,
                           GdkEvent   *event,
                           gulong      serial)
 {
-  GdkSurface *event_surface;
+  GdkSurface *event_surface = NULL;
   gboolean unlink_event = FALSE;
   GdkDeviceGrabInfo *button_release_grab;
   GdkPointerSurfaceInfo *pointer_info = NULL;
@@ -2336,6 +2336,14 @@ _gdk_windowing_got_event (GdkDisplay *display,
    */
   _gdk_event_queue_handle_motion_compression (display);
   gdk_event_queue_handle_scroll_compression (display);
+
+  if (event_surface)
+    {
+      GdkFrameClock *clock = gdk_surface_get_frame_clock (event_surface);
+
+      if (clock) /* might be NULL if surface was destroyed */
+        gdk_frame_clock_request_phase (clock, GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS);
+    }
 }
 
 /**