[mutter] wayland: Move device seat association to MetaWaylandInputDevice



commit 87f82d9fc09245788a6d82303c67e600ff398f9a
Author: Jonas Ådahl <jadahl gmail com>
Date:   Mon Sep 12 23:20:36 2016 +0800

    wayland: Move device seat association to MetaWaylandInputDevice
    
    Make the device <-> seat association permanent, and move it into
    MetaWaylandInputDevice. A device will never be disassociated with a
    seat, so there is no point in unsetting it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=771305

 src/wayland/meta-wayland-input-device.c          |   82 +++++++++++++++++++++-
 src/wayland/meta-wayland-input-device.h          |    4 +
 src/wayland/meta-wayland-keyboard.c              |   20 +++---
 src/wayland/meta-wayland-keyboard.h              |    5 +-
 src/wayland/meta-wayland-pointer-gesture-pinch.c |    8 ++-
 src/wayland/meta-wayland-pointer-gesture-swipe.c |    8 ++-
 src/wayland/meta-wayland-pointer.c               |   20 +++--
 src/wayland/meta-wayland-pointer.h               |    6 +-
 src/wayland/meta-wayland-seat.c                  |   18 +++--
 src/wayland/meta-wayland-touch.c                 |   12 ++--
 src/wayland/meta-wayland-touch.h                 |    5 +-
 11 files changed, 140 insertions(+), 48 deletions(-)
---
diff --git a/src/wayland/meta-wayland-input-device.c b/src/wayland/meta-wayland-input-device.c
index ed72eb2..92d6fbb 100644
--- a/src/wayland/meta-wayland-input-device.c
+++ b/src/wayland/meta-wayland-input-device.c
@@ -26,9 +26,72 @@
 
 #include "wayland/meta-wayland-input-device.h"
 
-G_DEFINE_TYPE (MetaWaylandInputDevice,
-               meta_wayland_input_device,
-               G_TYPE_OBJECT)
+enum
+{
+  PROP_0,
+
+  PROP_SEAT
+};
+
+typedef struct _MetaWaylandInputDevicePrivate
+{
+  MetaWaylandSeat *seat;
+} MetaWaylandInputDevicePrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (MetaWaylandInputDevice,
+                            meta_wayland_input_device,
+                            G_TYPE_OBJECT)
+
+MetaWaylandSeat *
+meta_wayland_input_device_get_seat (MetaWaylandInputDevice *input_device)
+{
+  MetaWaylandInputDevicePrivate *priv =
+    meta_wayland_input_device_get_instance_private (input_device);
+
+  return priv->seat;
+}
+
+static void
+meta_wayland_input_device_set_property (GObject      *object,
+                                        guint         prop_id,
+                                        const GValue *value,
+                                        GParamSpec   *pspec)
+{
+  MetaWaylandInputDevice *input_device = META_WAYLAND_INPUT_DEVICE (object);
+  MetaWaylandInputDevicePrivate *priv =
+    meta_wayland_input_device_get_instance_private (input_device);
+
+  switch (prop_id)
+    {
+    case PROP_SEAT:
+      priv->seat = g_value_get_pointer (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+meta_wayland_input_device_get_property (GObject      *object,
+                                        guint       prop_id,
+                                        GValue     *value,
+                                        GParamSpec *pspec)
+{
+  MetaWaylandInputDevice *input_device = META_WAYLAND_INPUT_DEVICE (object);
+  MetaWaylandInputDevicePrivate *priv =
+    meta_wayland_input_device_get_instance_private (input_device);
+
+  switch (prop_id)
+    {
+    case PROP_SEAT:
+      g_value_set_pointer (value, priv->seat);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
 
 static void
 meta_wayland_input_device_init (MetaWaylandInputDevice *input_device)
@@ -38,4 +101,17 @@ meta_wayland_input_device_init (MetaWaylandInputDevice *input_device)
 static void
 meta_wayland_input_device_class_init (MetaWaylandInputDeviceClass *klass)
 {
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GParamSpec *pspec;
+
+  object_class->set_property = meta_wayland_input_device_set_property;
+  object_class->get_property = meta_wayland_input_device_get_property;
+
+  pspec = g_param_spec_pointer ("seat",
+                                "MetaWaylandSeat",
+                                "The seat",
+                                G_PARAM_READWRITE |
+                                G_PARAM_STATIC_STRINGS |
+                                G_PARAM_CONSTRUCT_ONLY);
+  g_object_class_install_property (object_class, PROP_SEAT, pspec);
 }
diff --git a/src/wayland/meta-wayland-input-device.h b/src/wayland/meta-wayland-input-device.h
index d76e91b..eec5678 100644
--- a/src/wayland/meta-wayland-input-device.h
+++ b/src/wayland/meta-wayland-input-device.h
@@ -27,6 +27,8 @@
 
 #include <glib-object.h>
 
+#include "wayland/meta-wayland-types.h"
+
 #define META_TYPE_WAYLAND_INPUT_DEVICE (meta_wayland_input_device_get_type ())
 G_DECLARE_DERIVABLE_TYPE (MetaWaylandInputDevice,
                           meta_wayland_input_device,
@@ -38,4 +40,6 @@ struct _MetaWaylandInputDeviceClass
   GObjectClass parent_class;
 };
 
+MetaWaylandSeat * meta_wayland_input_device_get_seat (MetaWaylandInputDevice *input_device);
+
 #endif /* META_WAYLAND_INPUT_DEVICE_H */
diff --git a/src/wayland/meta-wayland-keyboard.c b/src/wayland/meta-wayland-keyboard.c
index b6eade8..69e97e0 100644
--- a/src/wayland/meta-wayland-keyboard.c
+++ b/src/wayland/meta-wayland-keyboard.c
@@ -351,11 +351,15 @@ meta_wayland_keyboard_broadcast_modifiers (MetaWaylandKeyboard *keyboard)
   struct wl_resource *resource;
   struct wl_list *l;
 
-
   l = &keyboard->focus_resource_list;
   if (!wl_list_empty (l))
     {
-      uint32_t serial = wl_display_next_serial (keyboard->seat->wl_display);
+      MetaWaylandInputDevice *input_device =
+        META_WAYLAND_INPUT_DEVICE (keyboard);
+      MetaWaylandSeat *seat = meta_wayland_input_device_get_seat (input_device);
+      uint32_t serial;
+
+      serial = wl_display_next_serial (seat->wl_display);
 
       wl_resource_for_each (resource, l)
         keyboard_send_modifiers (keyboard, resource, serial);
@@ -602,14 +606,11 @@ static const MetaWaylandKeyboardGrabInterface default_keyboard_grab_interface =
 };
 
 void
-meta_wayland_keyboard_enable (MetaWaylandKeyboard *keyboard,
-                              MetaWaylandSeat     *seat)
+meta_wayland_keyboard_enable (MetaWaylandKeyboard *keyboard)
 {
   MetaBackend *backend = meta_get_backend ();
   GSettingsSchema *schema;
 
-  keyboard->seat = seat;
-
   wl_list_init (&keyboard->resource_list);
   wl_list_init (&keyboard->focus_resource_list);
 
@@ -677,8 +678,6 @@ meta_wayland_keyboard_disable (MetaWaylandKeyboard *keyboard)
   g_clear_object (&keyboard->settings);
   if (keyboard->gsd_settings)
     g_object_unref (keyboard->gsd_settings);
-
-  keyboard->seat = NULL;
 }
 
 static guint
@@ -826,7 +825,10 @@ void
 meta_wayland_keyboard_set_focus (MetaWaylandKeyboard *keyboard,
                                  MetaWaylandSurface *surface)
 {
-  if (keyboard->seat == NULL)
+  MetaWaylandInputDevice *input_device = META_WAYLAND_INPUT_DEVICE (keyboard);
+  MetaWaylandSeat *seat = meta_wayland_input_device_get_seat (input_device);
+
+  if (!meta_wayland_seat_has_keyboard (seat))
     return;
 
   if (keyboard->focus_surface == surface)
diff --git a/src/wayland/meta-wayland-keyboard.h b/src/wayland/meta-wayland-keyboard.h
index e87c4dd..9943938 100644
--- a/src/wayland/meta-wayland-keyboard.h
+++ b/src/wayland/meta-wayland-keyboard.h
@@ -83,8 +83,6 @@ struct _MetaWaylandKeyboard
 {
   MetaWaylandInputDevice parent;
 
-  MetaWaylandSeat *seat;
-
   struct wl_list resource_list;
   struct wl_list focus_resource_list;
 
@@ -103,8 +101,7 @@ struct _MetaWaylandKeyboard
   GSettings *gsd_settings;
 };
 
-void meta_wayland_keyboard_enable (MetaWaylandKeyboard *keyboard,
-                                   MetaWaylandSeat     *seat);
+void meta_wayland_keyboard_enable (MetaWaylandKeyboard *keyboard);
 
 void meta_wayland_keyboard_disable (MetaWaylandKeyboard *keyboard);
 
diff --git a/src/wayland/meta-wayland-pointer-gesture-pinch.c 
b/src/wayland/meta-wayland-pointer-gesture-pinch.c
index 3f91a10..f2f3a6e 100644
--- a/src/wayland/meta-wayland-pointer-gesture-pinch.c
+++ b/src/wayland/meta-wayland-pointer-gesture-pinch.c
@@ -36,11 +36,13 @@ handle_pinch_begin (MetaWaylandPointer *pointer,
                     const ClutterEvent *event)
 {
   MetaWaylandPointerClient *pointer_client;
+  MetaWaylandSeat *seat;
   struct wl_resource *resource;
   uint32_t serial;
 
   pointer_client = pointer->focus_client;
-  serial = wl_display_next_serial (pointer->seat->wl_display);
+  seat = meta_wayland_pointer_get_seat (pointer);
+  serial = wl_display_next_serial (seat->wl_display);
 
   wl_resource_for_each (resource, &pointer_client->pinch_gesture_resources)
     {
@@ -80,12 +82,14 @@ handle_pinch_end (MetaWaylandPointer *pointer,
                   const ClutterEvent *event)
 {
   MetaWaylandPointerClient *pointer_client;
+  MetaWaylandSeat *seat;
   struct wl_resource *resource;
   gboolean cancelled = FALSE;
   uint32_t serial;
 
   pointer_client = pointer->focus_client;
-  serial = wl_display_next_serial (pointer->seat->wl_display);
+  seat = meta_wayland_pointer_get_seat (pointer);
+  serial = wl_display_next_serial (seat->wl_display);
 
   if (event->touchpad_pinch.phase == CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL)
     cancelled = TRUE;
diff --git a/src/wayland/meta-wayland-pointer-gesture-swipe.c 
b/src/wayland/meta-wayland-pointer-gesture-swipe.c
index 5f98e23..514d2c7 100644
--- a/src/wayland/meta-wayland-pointer-gesture-swipe.c
+++ b/src/wayland/meta-wayland-pointer-gesture-swipe.c
@@ -36,11 +36,13 @@ handle_swipe_begin (MetaWaylandPointer *pointer,
                     const ClutterEvent *event)
 {
   MetaWaylandPointerClient *pointer_client;
+  MetaWaylandSeat *seat;
   struct wl_resource *resource;
   uint32_t serial, fingers;
 
   pointer_client = pointer->focus_client;
-  serial = wl_display_next_serial (pointer->seat->wl_display);
+  seat = meta_wayland_pointer_get_seat (pointer);
+  serial = wl_display_next_serial (seat->wl_display);
   fingers = clutter_event_get_gesture_swipe_finger_count (event);
 
   wl_resource_for_each (resource, &pointer_client->swipe_gesture_resources)
@@ -77,12 +79,14 @@ handle_swipe_end (MetaWaylandPointer *pointer,
                   const ClutterEvent *event)
 {
   MetaWaylandPointerClient *pointer_client;
+  MetaWaylandSeat *seat;
   struct wl_resource *resource;
   gboolean cancelled = FALSE;
   uint32_t serial;
 
   pointer_client = pointer->focus_client;
-  serial = wl_display_next_serial (pointer->seat->wl_display);
+  seat = meta_wayland_pointer_get_seat (pointer);
+  serial = wl_display_next_serial (seat->wl_display);
 
   if (event->touchpad_swipe.phase == CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL)
     cancelled = TRUE;
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index 2af1736..d2cb01d 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -456,14 +456,11 @@ meta_wayland_pointer_on_cursor_changed (MetaCursorTracker *cursor_tracker,
 }
 
 void
-meta_wayland_pointer_enable (MetaWaylandPointer *pointer,
-                             MetaWaylandSeat    *seat)
+meta_wayland_pointer_enable (MetaWaylandPointer *pointer)
 {
   MetaCursorTracker *cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
   ClutterDeviceManager *manager;
 
-  pointer->seat = seat;
-
   pointer->pointer_clients =
     g_hash_table_new_full (NULL, NULL, NULL,
                            (GDestroyNotify) meta_wayland_pointer_client_free);
@@ -503,7 +500,6 @@ meta_wayland_pointer_disable (MetaWaylandPointer *pointer)
   meta_wayland_pointer_set_focus (pointer, NULL);
 
   g_clear_pointer (&pointer->pointer_clients, g_hash_table_unref);
-  pointer->seat = NULL;
   pointer->cursor_surface = NULL;
 }
 
@@ -589,7 +585,11 @@ handle_button_event (MetaWaylandPointer *pointer,
   pointer->grab->interface->button (pointer->grab, event);
 
   if (implicit_grab)
-    pointer->grab_serial = wl_display_get_serial (pointer->seat->wl_display);
+    {
+      MetaWaylandSeat *seat = meta_wayland_pointer_get_seat (pointer);
+
+      pointer->grab_serial = wl_display_get_serial (seat->wl_display);
+    }
 }
 
 static void
@@ -796,7 +796,9 @@ void
 meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer,
                                 MetaWaylandSurface *surface)
 {
-  if (pointer->seat == NULL)
+  MetaWaylandSeat *seat = meta_wayland_pointer_get_seat (pointer);
+
+  if (!meta_wayland_seat_has_pointer (seat))
     return;
 
   if (pointer->focus_surface == surface)
@@ -1206,7 +1208,9 @@ meta_wayland_relative_pointer_init (MetaWaylandCompositor *compositor)
 MetaWaylandSeat *
 meta_wayland_pointer_get_seat (MetaWaylandPointer *pointer)
 {
-  return pointer->seat;
+  MetaWaylandInputDevice *input_device = META_WAYLAND_INPUT_DEVICE (pointer);
+
+  return meta_wayland_input_device_get_seat (input_device);
 }
 
 static void
diff --git a/src/wayland/meta-wayland-pointer.h b/src/wayland/meta-wayland-pointer.h
index 58550fb..1076592 100644
--- a/src/wayland/meta-wayland-pointer.h
+++ b/src/wayland/meta-wayland-pointer.h
@@ -25,6 +25,7 @@
 #include <glib.h>
 
 #include "meta-wayland-types.h"
+#include "meta-wayland-seat.h"
 #include "meta-wayland-pointer-gesture-swipe.h"
 #include "meta-wayland-pointer-gesture-pinch.h"
 #include "meta-wayland-surface.h"
@@ -65,8 +66,6 @@ struct _MetaWaylandPointer
 {
   MetaWaylandInputDevice parent;
 
-  MetaWaylandSeat *seat;
-
   MetaWaylandPointerClient *focus_client;
   GHashTable *pointer_clients;
 
@@ -91,8 +90,7 @@ struct _MetaWaylandPointer
   guint32 button_count;
 };
 
-void meta_wayland_pointer_enable (MetaWaylandPointer *pointer,
-                                  MetaWaylandSeat    *seat);
+void meta_wayland_pointer_enable (MetaWaylandPointer *pointer);
 
 void meta_wayland_pointer_disable (MetaWaylandPointer *pointer);
 
diff --git a/src/wayland/meta-wayland-seat.c b/src/wayland/meta-wayland-seat.c
index ec1c0bb..7fd815b 100644
--- a/src/wayland/meta-wayland-seat.c
+++ b/src/wayland/meta-wayland-seat.c
@@ -157,7 +157,7 @@ meta_wayland_seat_set_capabilities (MetaWaylandSeat *seat,
   seat->capabilities = flags;
 
   if (CAPABILITY_ENABLED (prev_flags, flags, WL_SEAT_CAPABILITY_POINTER))
-    meta_wayland_pointer_enable (seat->pointer, seat);
+    meta_wayland_pointer_enable (seat->pointer);
   else if (CAPABILITY_DISABLED (prev_flags, flags, WL_SEAT_CAPABILITY_POINTER))
     meta_wayland_pointer_disable (seat->pointer);
 
@@ -165,7 +165,7 @@ meta_wayland_seat_set_capabilities (MetaWaylandSeat *seat,
     {
       MetaDisplay *display;
 
-      meta_wayland_keyboard_enable (seat->keyboard, seat);
+      meta_wayland_keyboard_enable (seat->keyboard);
       display = meta_get_display ();
 
       /* Post-initialization, ensure the input focus is in sync */
@@ -176,7 +176,7 @@ meta_wayland_seat_set_capabilities (MetaWaylandSeat *seat,
     meta_wayland_keyboard_disable (seat->keyboard);
 
   if (CAPABILITY_ENABLED (prev_flags, flags, WL_SEAT_CAPABILITY_TOUCH))
-    meta_wayland_touch_enable (seat->touch, seat);
+    meta_wayland_touch_enable (seat->touch);
   else if (CAPABILITY_DISABLED (prev_flags, flags, WL_SEAT_CAPABILITY_TOUCH))
     meta_wayland_touch_disable (seat->touch);
 
@@ -215,9 +215,15 @@ meta_wayland_seat_new (MetaWaylandCompositor *compositor,
   wl_list_init (&seat->base_resource_list);
   seat->wl_display = display;
 
-  seat->pointer = g_object_new (META_TYPE_WAYLAND_POINTER, NULL);
-  seat->keyboard = g_object_new (META_TYPE_WAYLAND_KEYBOARD, NULL);
-  seat->touch = g_object_new (META_TYPE_WAYLAND_TOUCH, NULL);
+  seat->pointer = g_object_new (META_TYPE_WAYLAND_POINTER,
+                                "seat", seat,
+                                NULL);
+  seat->keyboard = g_object_new (META_TYPE_WAYLAND_KEYBOARD,
+                                 "seat", seat,
+                                 NULL);
+  seat->touch = g_object_new (META_TYPE_WAYLAND_TOUCH,
+                              "seat", seat,
+                              NULL);
 
   meta_wayland_data_device_init (&seat->data_device);
 
diff --git a/src/wayland/meta-wayland-touch.c b/src/wayland/meta-wayland-touch.c
index d3793d5..78df0a7 100644
--- a/src/wayland/meta-wayland-touch.c
+++ b/src/wayland/meta-wayland-touch.c
@@ -455,9 +455,11 @@ touch_info_free (MetaWaylandTouchInfo *touch_info)
 void
 meta_wayland_touch_cancel (MetaWaylandTouch *touch)
 {
+  MetaWaylandInputDevice *input_device = META_WAYLAND_INPUT_DEVICE (touch);
+  MetaWaylandSeat *seat = meta_wayland_input_device_get_seat (input_device);
   GList *surfaces, *s;
 
-  if (touch->seat == NULL)
+  if (!meta_wayland_seat_has_touch (seat))
     return;
 
   surfaces = s = touch_get_surfaces (touch, FALSE);
@@ -517,12 +519,10 @@ evdev_filter_func (struct libinput_event *event,
 #endif
 
 void
-meta_wayland_touch_enable (MetaWaylandTouch *touch,
-                           MetaWaylandSeat  *seat)
+meta_wayland_touch_enable (MetaWaylandTouch *touch)
 {
   ClutterDeviceManager *manager;
 
-  touch->seat = seat;
   touch->touch_surfaces = g_hash_table_new_full (NULL, NULL, NULL,
                                                  (GDestroyNotify) touch_surface_free);
   touch->touches = g_hash_table_new_full (NULL, NULL, NULL,
@@ -551,7 +551,6 @@ meta_wayland_touch_disable (MetaWaylandTouch *touch)
 
   g_clear_pointer (&touch->touch_surfaces, (GDestroyNotify) g_hash_table_unref);
   g_clear_pointer (&touch->touches, (GDestroyNotify) g_hash_table_unref);
-  touch->seat = NULL;
 }
 
 void
@@ -560,9 +559,10 @@ meta_wayland_touch_create_new_resource (MetaWaylandTouch   *touch,
                                         struct wl_resource *seat_resource,
                                         uint32_t            id)
 {
+  MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
   struct wl_resource *cr;
 
-  if (touch->seat == NULL)
+  if (!meta_wayland_seat_has_touch (seat))
     {
       wl_resource_post_error (seat_resource, WL_DISPLAY_ERROR_INVALID_METHOD,
                               "Cannot retrieve touch interface without touch capability");
diff --git a/src/wayland/meta-wayland-touch.h b/src/wayland/meta-wayland-touch.h
index 45f8337..7ea675f 100644
--- a/src/wayland/meta-wayland-touch.h
+++ b/src/wayland/meta-wayland-touch.h
@@ -40,8 +40,6 @@ struct _MetaWaylandTouch
 {
   MetaWaylandInputDevice parent;
 
-  MetaWaylandSeat *seat;
-
   struct wl_list resource_list;
 
   GHashTable *touch_surfaces; /* HT of MetaWaylandSurface->MetaWaylandTouchSurface */
@@ -51,8 +49,7 @@ struct _MetaWaylandTouch
   guint64 frame_slots;
 };
 
-void meta_wayland_touch_enable (MetaWaylandTouch *touch,
-                                MetaWaylandSeat  *seat);
+void meta_wayland_touch_enable (MetaWaylandTouch *touch);
 
 void meta_wayland_touch_disable (MetaWaylandTouch *touch);
 


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