[mutter/wip/carlosg/input-thread: 45/88] clutter: Make ClutterSeat::handle_device_event vfunc more generic




commit 8311722b2af65d2289c1c63cdb28d030e0163941
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Aug 11 11:27:18 2020 +0200

    clutter: Make ClutterSeat::handle_device_event vfunc more generic
    
    Make it able to handle not just device added/removed events, but perform
    any kind of post-processing that needed to be done on ClutterEvents at
    the seat level.

 clutter/clutter/clutter-main.c         |  8 +-------
 clutter/clutter/clutter-mutter.h       |  3 +++
 clutter/clutter/clutter-seat.c         | 15 +++++----------
 clutter/clutter/clutter-seat.h         |  7 ++-----
 src/backends/meta-backend.c            |  5 +++++
 src/backends/native/meta-seat-native.c |  6 +++---
 src/backends/x11/meta-seat-x11.c       | 13 +++++++++----
 7 files changed, 28 insertions(+), 29 deletions(-)
---
diff --git a/clutter/clutter/clutter-main.c b/clutter/clutter/clutter-main.c
index 6382d3951b..9ac6d53bff 100644
--- a/clutter/clutter/clutter-main.c
+++ b/clutter/clutter/clutter-main.c
@@ -1938,13 +1938,7 @@ _clutter_process_event_details (ClutterActor        *stage,
 
       case CLUTTER_DEVICE_ADDED:
       case CLUTTER_DEVICE_REMOVED:
-        if (!_clutter_event_process_filters (event))
-          {
-            ClutterSeat *seat;
-
-            seat = clutter_backend_get_default_seat (context->backend);
-            clutter_seat_handle_device_event (seat, event);
-          }
+        _clutter_event_process_filters (event);
         break;
 
       case CLUTTER_EVENT_LAST:
diff --git a/clutter/clutter/clutter-mutter.h b/clutter/clutter/clutter-mutter.h
index 654c6dac0e..9c75ad6a25 100644
--- a/clutter/clutter/clutter-mutter.h
+++ b/clutter/clutter/clutter-mutter.h
@@ -71,6 +71,9 @@ gboolean clutter_actor_has_transitions (ClutterActor *actor);
 CLUTTER_EXPORT
 ClutterFrameClock * clutter_actor_pick_frame_clock (ClutterActor  *self,
                                                     ClutterActor **out_actor);
+CLUTTER_EXPORT
+gboolean clutter_seat_handle_event_post (ClutterSeat        *seat,
+                                         const ClutterEvent *event);
 
 #undef __CLUTTER_H_INSIDE__
 
diff --git a/clutter/clutter/clutter-seat.c b/clutter/clutter/clutter-seat.c
index d3e2eaa245..ed78f43a59 100644
--- a/clutter/clutter/clutter-seat.c
+++ b/clutter/clutter/clutter-seat.c
@@ -27,6 +27,7 @@
 #include "clutter-input-device-tool.h"
 #include "clutter-input-pointer-a11y-private.h"
 #include "clutter-marshal.h"
+#include "clutter-mutter.h"
 #include "clutter-private.h"
 #include "clutter-seat.h"
 #include "clutter-virtual-input-device.h"
@@ -635,8 +636,8 @@ clutter_seat_compress_motion (ClutterSeat        *seat,
 }
 
 gboolean
-clutter_seat_handle_device_event (ClutterSeat  *seat,
-                                  ClutterEvent *event)
+clutter_seat_handle_event_post (ClutterSeat        *seat,
+                                const ClutterEvent *event)
 {
   ClutterSeatClass *seat_class;
   ClutterInputDevice *device;
@@ -644,16 +645,10 @@ clutter_seat_handle_device_event (ClutterSeat  *seat,
   g_return_val_if_fail (CLUTTER_IS_SEAT (seat), FALSE);
   g_return_val_if_fail (event, FALSE);
 
-  g_assert (event->type == CLUTTER_DEVICE_ADDED ||
-            event->type == CLUTTER_DEVICE_REMOVED);
-
   seat_class = CLUTTER_SEAT_GET_CLASS (seat);
 
-  if (seat_class->handle_device_event)
-    {
-      if (!seat_class->handle_device_event (seat, event))
-        return FALSE;
-    }
+  if (seat_class->handle_event_post)
+    seat_class->handle_event_post (seat, event);
 
   device = clutter_event_get_source_device (event);
   g_assert_true (CLUTTER_IS_INPUT_DEVICE (device));
diff --git a/clutter/clutter/clutter-seat.h b/clutter/clutter/clutter-seat.h
index cb2ebf9779..6ef748fddd 100644
--- a/clutter/clutter/clutter-seat.h
+++ b/clutter/clutter/clutter-seat.h
@@ -88,8 +88,8 @@ struct _ClutterSeatClass
                             ClutterEvent       *event,
                             const ClutterEvent *to_discard);
 
-  gboolean (* handle_device_event) (ClutterSeat  *seat,
-                                    ClutterEvent *event);
+  gboolean (* handle_event_post) (ClutterSeat        *seat,
+                                  const ClutterEvent *event);
 
   void (* warp_pointer) (ClutterSeat *seat,
                          int          x,
@@ -162,9 +162,6 @@ void clutter_seat_compress_motion (ClutterSeat        *seat,
                                    ClutterEvent       *event,
                                    const ClutterEvent *to_discard);
 
-gboolean clutter_seat_handle_device_event (ClutterSeat  *seat,
-                                           ClutterEvent *event);
-
 CLUTTER_EXPORT
 void clutter_seat_warp_pointer (ClutterSeat *seat,
                                 int          x,
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index e163866050..ba964c58b7 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -994,12 +994,17 @@ clutter_source_dispatch (GSource     *source,
                          gpointer     user_data)
 {
   MetaBackendSource *backend_source = (MetaBackendSource *) source;
+  MetaBackendPrivate *priv =
+    meta_backend_get_instance_private (backend_source->backend);
   ClutterEvent *event = clutter_event_get ();
+  ClutterSeat *seat;
 
   if (event)
     {
       event->any.stage =
         CLUTTER_STAGE (meta_backend_get_stage (backend_source->backend));
+      seat = clutter_backend_get_default_seat (priv->clutter_backend);
+      clutter_seat_handle_event_post (seat, event);
       clutter_do_event (event);
       clutter_event_free (event);
     }
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index 6a4c3fe68e..13aa4b5885 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -1488,8 +1488,8 @@ evdev_remove_device (MetaSeatNative        *seat,
 }
 
 static gboolean
-meta_seat_native_handle_device_event (ClutterSeat  *seat,
-                                      ClutterEvent *event)
+meta_seat_native_handle_event_post (ClutterSeat        *seat,
+                                    const ClutterEvent *event)
 {
   MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
   ClutterInputDevice *device = event->device.device;
@@ -2872,7 +2872,7 @@ meta_seat_native_class_init (MetaSeatNativeClass *klass)
   seat_class->get_supported_virtual_device_types = meta_seat_native_get_supported_virtual_device_types;
   seat_class->compress_motion = meta_seat_native_compress_motion;
   seat_class->warp_pointer = meta_seat_native_warp_pointer;
-  seat_class->handle_device_event = meta_seat_native_handle_device_event;
+  seat_class->handle_event_post = meta_seat_native_handle_event_post;
   seat_class->query_state = meta_seat_native_query_state;
 
   props[PROP_SEAT_ID] =
diff --git a/src/backends/x11/meta-seat-x11.c b/src/backends/x11/meta-seat-x11.c
index 79e744d119..f437ef16d5 100644
--- a/src/backends/x11/meta-seat-x11.c
+++ b/src/backends/x11/meta-seat-x11.c
@@ -720,13 +720,18 @@ remove_device (MetaSeatX11        *seat_x11,
 }
 
 static gboolean
-meta_seat_x11_handle_device_event (ClutterSeat  *seat,
-                                   ClutterEvent *event)
+meta_seat_x11_handle_event_post (ClutterSeat        *seat,
+                                 const ClutterEvent *event)
 {
   MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
-  ClutterInputDevice *device = event->device.device;
+  ClutterInputDevice *device;
   gboolean is_touch;
 
+  if (event->type != CLUTTER_DEVICE_ADDED &&
+      event->type != CLUTTER_DEVICE_REMOVED)
+    return TRUE;
+
+  device = clutter_event_get_device (event);
   is_touch =
     clutter_input_device_get_device_type (device) == CLUTTER_TOUCHSCREEN_DEVICE;
 
@@ -1760,7 +1765,7 @@ meta_seat_x11_class_init (MetaSeatX11Class *klass)
   seat_class->create_virtual_device = meta_seat_x11_create_virtual_device;
   seat_class->get_supported_virtual_device_types = meta_seat_x11_get_supported_virtual_device_types;
   seat_class->warp_pointer = meta_seat_x11_warp_pointer;
-  seat_class->handle_device_event = meta_seat_x11_handle_device_event;
+  seat_class->handle_event_post = meta_seat_x11_handle_event_post;
   seat_class->query_state = meta_seat_x11_query_state;
 
   props[PROP_OPCODE] =


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