[mutter] seat-impl: Dispatch source also when there are already queued events



commit e6b70f1a2bc5c0640c6078dd005400d699c70155
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Thu Jan 28 14:40:49 2021 +0100

    seat-impl: Dispatch source also when there are already queued events
    
    Libinput will queue a few initial events when a seat is assigned to the
    udev backend; a result of it probing udev adding detected devices. For
    us to see these events, we need to dispatch libinput before going idle,
    as nothing will show up on the libinput file descriptor until something
    else (e.g. keyboard event or mouse movement) wakes us up.
    
    Do this by adding a prepare() function to the libinput GSource, that
    checks whether there are any events in the queue already, and return
    TRUE if so is the case, causing us to dispatch before going fully idle.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1688>

 src/backends/native/meta-seat-impl.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
---
diff --git a/src/backends/native/meta-seat-impl.c b/src/backends/native/meta-seat-impl.c
index b483956fc8..da87b086ba 100644
--- a/src/backends/native/meta-seat-impl.c
+++ b/src/backends/native/meta-seat-impl.c
@@ -943,6 +943,25 @@ meta_seat_impl_notify_touch_event_in_impl (MetaSeatImpl       *seat_impl,
 /*
  * MetaEventSource for reading input devices
  */
+
+static gboolean
+meta_event_prepare (GSource *g_source,
+                    int     *timeout_ms)
+{
+  MetaEventSource *source = (MetaEventSource *) g_source;
+  MetaSeatImpl *seat_impl = source->seat_impl;
+
+  *timeout_ms = -1;
+
+  switch (libinput_next_event_type (seat_impl->libinput))
+    {
+    case LIBINPUT_EVENT_NONE:
+      return FALSE;
+    default:
+      return TRUE;
+    }
+}
+
 static gboolean
 meta_event_check (GSource *source)
 {
@@ -1429,7 +1448,7 @@ meta_event_dispatch (GSource     *g_source,
 }
 
 static GSourceFuncs event_funcs = {
-  NULL,
+  meta_event_prepare,
   meta_event_check,
   meta_event_dispatch,
   NULL


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