[mutter/wip/carlosg/grabs-pt1: 26/30] clutter: Add ClutterSeat private API to grab devices




commit 1f0259a1f15c1cf17621b517be0b7e16b89481f5
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Oct 28 17:04:49 2021 +0200

    clutter: Add ClutterSeat private API to grab devices
    
    This will be necessary to string along ClutterGrab with backend
    behavior, and mostly for the X11 backend so implement this pair
    of vfuncs there.

 clutter/clutter/clutter-seat-private.h |  5 ++++
 clutter/clutter/clutter-seat.c         | 24 ++++++++++++++++
 clutter/clutter/clutter-seat.h         |  5 ++++
 src/backends/x11/meta-seat-x11.c       | 52 ++++++++++++++++++++++++++++++++++
 4 files changed, 86 insertions(+)
---
diff --git a/clutter/clutter/clutter-seat-private.h b/clutter/clutter/clutter-seat-private.h
index 2adb7bcd6e..bad57a0dac 100644
--- a/clutter/clutter/clutter-seat-private.h
+++ b/clutter/clutter/clutter-seat-private.h
@@ -28,4 +28,9 @@
 CLUTTER_EXPORT
 void clutter_seat_destroy (ClutterSeat *seat);
 
+gboolean clutter_seat_grab (ClutterSeat *seat,
+                            uint32_t     time);
+void clutter_seat_ungrab (ClutterSeat *seat,
+                          uint32_t     time);
+
 #endif /* CLUTTER_SEAT_PRIVATE_H */
diff --git a/clutter/clutter/clutter-seat.c b/clutter/clutter/clutter-seat.c
index 3e7435fd93..7422582542 100644
--- a/clutter/clutter/clutter-seat.c
+++ b/clutter/clutter/clutter-seat.c
@@ -705,3 +705,27 @@ clutter_seat_destroy (ClutterSeat *seat)
   g_object_run_dispose (G_OBJECT (seat));
   g_object_unref (seat);
 }
+
+gboolean
+clutter_seat_grab (ClutterSeat *seat,
+                   uint32_t     time)
+{
+  ClutterSeatClass *seat_class;
+
+  seat_class = CLUTTER_SEAT_GET_CLASS (seat);
+  if (seat_class->grab)
+    return seat_class->grab (seat, time);
+  else
+    return TRUE;
+}
+
+void
+clutter_seat_ungrab (ClutterSeat *seat,
+                     uint32_t     time)
+{
+  ClutterSeatClass *seat_class;
+
+  seat_class = CLUTTER_SEAT_GET_CLASS (seat);
+  if (seat_class->ungrab)
+    return seat_class->ungrab (seat, time);
+}
diff --git a/clutter/clutter/clutter-seat.h b/clutter/clutter/clutter-seat.h
index 5c5dfe6eb5..29ffa34225 100644
--- a/clutter/clutter/clutter-seat.h
+++ b/clutter/clutter/clutter-seat.h
@@ -97,6 +97,11 @@ struct _ClutterSeatClass
                             graphene_point_t     *coords,
                             ClutterModifierType  *modifiers);
 
+  gboolean (* grab) (ClutterSeat *seat,
+                     uint32_t     time);
+  void (* ungrab) (ClutterSeat *seat,
+                   uint32_t     time);
+
   /* Virtual devices */
   ClutterVirtualInputDevice * (* create_virtual_device) (ClutterSeat            *seat,
                                                          ClutterInputDeviceType  device_type);
diff --git a/src/backends/x11/meta-seat-x11.c b/src/backends/x11/meta-seat-x11.c
index 0cfa2e510d..0acb3fc837 100644
--- a/src/backends/x11/meta-seat-x11.c
+++ b/src/backends/x11/meta-seat-x11.c
@@ -74,6 +74,7 @@ struct _MetaSeatX11
   guint has_touchscreens : 1;
   guint touch_mode : 1;
   guint has_pointer_focus : 1;
+  guint grabbed : 1;
 };
 
 static GParamSpec *props[N_PROPS] = { 0 };
@@ -1652,6 +1653,55 @@ meta_touch_info_free (MetaTouchInfo *touch_info)
   g_free (touch_info);
 }
 
+static gboolean
+meta_seat_x11_grab (ClutterSeat *seat,
+                    uint32_t     time)
+{
+  MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
+  MetaBackend *backend = meta_get_backend ();
+
+  if (seat_x11->grabbed)
+    return TRUE;
+
+  if (!meta_backend_grab_device (backend,
+                                 META_VIRTUAL_CORE_POINTER_ID,
+                                 time))
+    goto fail;
+
+  if (!meta_backend_grab_device (backend,
+                                 META_VIRTUAL_CORE_KEYBOARD_ID,
+                                 time))
+    goto ungrab_pointer;
+
+  seat_x11->grabbed = TRUE;
+
+  return TRUE;
+
+ ungrab_pointer:
+  meta_backend_ungrab_device (backend, META_VIRTUAL_CORE_POINTER_ID, time);
+ fail:
+   return FALSE;
+}
+
+static void
+meta_seat_x11_ungrab (ClutterSeat *seat,
+                      uint32_t     time)
+{
+  MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
+  MetaBackend *backend = meta_get_backend ();
+
+  if (!seat_x11->grabbed)
+    return;
+
+  meta_backend_ungrab_device (backend,
+                              META_VIRTUAL_CORE_POINTER_ID,
+                              time);
+  meta_backend_ungrab_device (backend,
+                              META_VIRTUAL_CORE_KEYBOARD_ID,
+                              time);
+  seat_x11->grabbed = FALSE;
+}
+
 static void
 meta_seat_x11_class_init (MetaSeatX11Class *klass)
 {
@@ -1673,6 +1723,8 @@ meta_seat_x11_class_init (MetaSeatX11Class *klass)
   seat_class->warp_pointer = meta_seat_x11_warp_pointer;
   seat_class->handle_event_post = meta_seat_x11_handle_event_post;
   seat_class->query_state = meta_seat_x11_query_state;
+  seat_class->grab = meta_seat_x11_grab;
+  seat_class->ungrab = meta_seat_x11_ungrab;
 
   props[PROP_OPCODE] =
     g_param_spec_int ("opcode",


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