[mutter/wip/carlosg/clutter-seat: 44/68] clutter: Add ClutterSeat object



commit c4e9dbe87244b1b7a4a49bf1fbd813ea39fa3820
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Apr 4 12:14:28 2019 +0200

    clutter: Add ClutterSeat object
    
    This object will take most responsibilities away from ClutterDeviceManager,
    with the peculiarity that it'll express the per-seat device tree.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/852

 clutter/clutter/clutter-backend-private.h        |   3 +
 clutter/clutter/clutter-backend.c                |  16 ++
 clutter/clutter/clutter-backend.h                |   4 +
 clutter/clutter/clutter-device-manager-private.h |   1 +
 clutter/clutter/clutter-input-device.c           |  43 ++++-
 clutter/clutter/clutter-input-device.h           |   3 +
 clutter/clutter/clutter-seat.c                   | 207 +++++++++++++++++++++++
 clutter/clutter/clutter-seat.h                   |  57 +++++++
 clutter/clutter/meson.build                      |   2 +
 9 files changed, 333 insertions(+), 3 deletions(-)
---
diff --git a/clutter/clutter/clutter-backend-private.h b/clutter/clutter/clutter-backend-private.h
index 369fe03ae..f22ed13ed 100644
--- a/clutter/clutter/clutter-backend-private.h
+++ b/clutter/clutter/clutter-backend-private.h
@@ -25,6 +25,7 @@
 #include <clutter/clutter-backend.h>
 #include <clutter/clutter-device-manager.h>
 #include <clutter/clutter-keymap.h>
+#include <clutter/clutter-seat.h>
 #include <clutter/clutter-stage-window.h>
 
 #define CLUTTER_BACKEND_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_BACKEND, 
ClutterBackendClass))
@@ -101,6 +102,8 @@ struct _ClutterBackendClass
 
   ClutterKeymap *       (* get_keymap)           (ClutterBackend   *backend);
 
+  ClutterSeat *         (* get_default_seat)   (ClutterBackend *backend);
+
   /* signals */
   void (* resolution_changed) (ClutterBackend *backend);
   void (* font_changed)       (ClutterBackend *backend);
diff --git a/clutter/clutter/clutter-backend.c b/clutter/clutter/clutter-backend.c
index 448093a65..8740bb161 100644
--- a/clutter/clutter/clutter-backend.c
+++ b/clutter/clutter/clutter-backend.c
@@ -1078,3 +1078,19 @@ clutter_backend_get_stage_window (ClutterBackend *backend)
 {
   return backend->stage_window;
 }
+
+/**
+ * clutter_backend_get_default_seat:
+ * @backend: the #ClutterBackend
+ *
+ * Returns the default seat
+ *
+ * Returns: (transfer none): the default seat
+ **/
+ClutterSeat *
+clutter_backend_get_default_seat (ClutterBackend *backend)
+{
+  g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL);
+
+  return CLUTTER_BACKEND_GET_CLASS (backend)->get_default_seat (backend);
+}
diff --git a/clutter/clutter/clutter-backend.h b/clutter/clutter/clutter-backend.h
index fde57d8f2..ad577e7b2 100644
--- a/clutter/clutter/clutter-backend.h
+++ b/clutter/clutter/clutter-backend.h
@@ -36,6 +36,7 @@
 #include <clutter/clutter-config.h>
 #include <clutter/clutter-keymap.h>
 #include <clutter/clutter-types.h>
+#include <clutter/clutter-seat.h>
 
 G_BEGIN_DECLS
 
@@ -84,6 +85,9 @@ void                            clutter_backend_set_input_method        (Clutter
 CLUTTER_EXPORT
 ClutterKeymap *                 clutter_backend_get_keymap              (ClutterBackend             
*backend);
 
+CLUTTER_EXPORT
+ClutterSeat *                   clutter_backend_get_default_seat        (ClutterBackend             
*backend);
+
 G_END_DECLS
 
 #endif /* __CLUTTER_BACKEND_H__ */
diff --git a/clutter/clutter/clutter-device-manager-private.h 
b/clutter/clutter/clutter-device-manager-private.h
index 5a2e6e6be..8ed440ca2 100644
--- a/clutter/clutter/clutter-device-manager-private.h
+++ b/clutter/clutter/clutter-device-manager-private.h
@@ -98,6 +98,7 @@ struct _ClutterInputDevice
   gchar *device_name;
 
   ClutterDeviceManager *device_manager;
+  ClutterSeat *seat;
 
   ClutterBackend *backend;
 
diff --git a/clutter/clutter/clutter-input-device.c b/clutter/clutter/clutter-input-device.c
index 3975e88b5..0cd4b8d40 100644
--- a/clutter/clutter/clutter-input-device.c
+++ b/clutter/clutter/clutter-input-device.c
@@ -58,6 +58,7 @@ enum
 
   PROP_DEVICE_TYPE,
   PROP_DEVICE_MANAGER,
+  PROP_SEAT,
   PROP_DEVICE_MODE,
 
   PROP_HAS_CURSOR,
@@ -174,6 +175,10 @@ clutter_input_device_set_property (GObject      *gobject,
       self->device_manager = g_value_get_object (value);
       break;
 
+    case PROP_SEAT:
+      self->seat = g_value_get_object (value);
+      break;
+
     case PROP_DEVICE_MODE:
       self->device_mode = g_value_get_enum (value);
       break;
@@ -250,6 +255,10 @@ clutter_input_device_get_property (GObject    *gobject,
       g_value_set_object (value, self->device_manager);
       break;
 
+    case PROP_SEAT:
+      g_value_set_object (value, self->seat);
+      break;
+
     case PROP_DEVICE_MODE:
       g_value_set_enum (value, self->device_mode);
       break;
@@ -374,6 +383,18 @@ clutter_input_device_class_init (ClutterInputDeviceClass *klass)
                          CLUTTER_TYPE_DEVICE_MANAGER,
                          CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
 
+  /**
+   * ClutterInputDevice:seat:
+   *
+   * The #ClutterSeat instance which owns the device
+   */
+  obj_props[PROP_SEAT] =
+    g_param_spec_object ("seat",
+                         P_("Seat"),
+                         P_("Seat"),
+                         CLUTTER_TYPE_SEAT,
+                         CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
   /**
    * ClutterInputDevice:mode:
    *
@@ -1224,11 +1245,11 @@ clutter_input_device_get_device_mode (ClutterInputDevice *device)
  *
  *   translate_native_event_to_clutter (native_event, &c_event);
  *
- *   // get the device manager
- *   manager = clutter_device_manager_get_default ();
+ *   // get the seat
+ *   seat = clutter_backend_get_deafult_seat (clutter_get_default_backend ());
  *
  *   // use the default Core Pointer that Clutter backends register by default
- *   device = clutter_device_manager_get_core_device (manager, %CLUTTER_POINTER_DEVICE);
+ *   device = clutter_seat_get_pointer (seat);
  *
  *   // update the state of the input device
  *   clutter_input_device_update_from_event (device, &c_event, FALSE);
@@ -2441,3 +2462,19 @@ clutter_input_device_is_grouped (ClutterInputDevice *device,
 
   return CLUTTER_INPUT_DEVICE_GET_CLASS (device)->is_grouped (device, other_device);
 }
+
+/**
+ * clutter_input_device_get_seat:
+ * @device: a #ClutterInputDevice
+ *
+ * Returns the seat the device belongs to
+ *
+ * Returns: (transfer none): the device seat
+ **/
+ClutterSeat *
+clutter_input_device_get_seat (ClutterInputDevice *device)
+{
+  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
+
+  return device->seat;
+}
diff --git a/clutter/clutter/clutter-input-device.h b/clutter/clutter/clutter-input-device.h
index 00dcc01d5..d2cfd2e78 100644
--- a/clutter/clutter/clutter-input-device.h
+++ b/clutter/clutter/clutter-input-device.h
@@ -29,6 +29,7 @@
 #endif
 
 #include <clutter/clutter-types.h>
+#include <clutter/clutter-seat.h>
 
 G_BEGIN_DECLS
 
@@ -171,6 +172,8 @@ void                      clutter_input_device_set_mapping_mode (ClutterInputDev
 CLUTTER_EXPORT
 gboolean                  clutter_input_device_is_grouped       (ClutterInputDevice *device,
                                                                  ClutterInputDevice *other_device);
+CLUTTER_EXPORT
+ClutterSeat *             clutter_input_device_get_seat         (ClutterInputDevice *device);
 
 G_END_DECLS
 
diff --git a/clutter/clutter/clutter-seat.c b/clutter/clutter/clutter-seat.c
new file mode 100644
index 000000000..7b78d2783
--- /dev/null
+++ b/clutter/clutter/clutter-seat.c
@@ -0,0 +1,207 @@
+/*
+ * Clutter.
+ *
+ * An OpenGL based 'interactive canvas' library.
+ *
+ * Copyright (C) 2019 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Carlos Garnacho <carlosg gnome org>
+ */
+
+#include "clutter-build-config.h"
+
+#include "clutter-backend-private.h"
+#include "clutter-input-device-tool.h"
+#include "clutter-marshal.h"
+#include "clutter-private.h"
+#include "clutter-seat.h"
+
+enum
+{
+  DEVICE_ADDED,
+  DEVICE_REMOVED,
+  TOOL_CHANGED,
+  N_SIGNALS,
+};
+
+static guint signals[N_SIGNALS] = { 0 };
+
+enum
+{
+  PROP_0,
+  PROP_BACKEND,
+  N_PROPS
+};
+
+static GParamSpec *props[N_PROPS];
+
+typedef struct _ClutterSeatPrivate ClutterSeatPrivate;
+
+struct _ClutterSeatPrivate
+{
+  ClutterBackend *backend;
+};
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ClutterSeat, clutter_seat, G_TYPE_OBJECT)
+
+static void
+clutter_seat_set_property (GObject      *object,
+                           guint         prop_id,
+                           const GValue *value,
+                           GParamSpec   *pspec)
+{
+  ClutterSeat *seat = CLUTTER_SEAT (object);
+  ClutterSeatPrivate *priv = clutter_seat_get_instance_private (seat);
+
+  switch (prop_id)
+    {
+    case PROP_BACKEND:
+      priv->backend = g_value_get_object (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+clutter_seat_get_property (GObject    *object,
+                           guint       prop_id,
+                           GValue     *value,
+                           GParamSpec *pspec)
+{
+  ClutterSeat *seat = CLUTTER_SEAT (object);
+  ClutterSeatPrivate *priv = clutter_seat_get_instance_private (seat);
+
+  switch (prop_id)
+    {
+    case PROP_BACKEND:
+      g_value_set_object (value, priv->backend);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+clutter_seat_finalize (GObject *object)
+{
+  ClutterSeat *seat = CLUTTER_SEAT (object);
+  ClutterSeatPrivate *priv = clutter_seat_get_instance_private (seat);
+
+  g_clear_object (&priv->backend);
+
+  G_OBJECT_CLASS (clutter_seat_parent_class)->finalize (object);
+}
+
+static void
+clutter_seat_class_init (ClutterSeatClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->set_property = clutter_seat_set_property;
+  object_class->get_property = clutter_seat_get_property;
+  object_class->finalize = clutter_seat_finalize;
+
+  signals[DEVICE_ADDED] =
+    g_signal_new (I_("device-added"),
+                  G_TYPE_FROM_CLASS (object_class),
+                  G_SIGNAL_RUN_LAST,
+                  0, NULL, NULL, NULL,
+                  G_TYPE_NONE, 1,
+                  CLUTTER_TYPE_INPUT_DEVICE);
+
+  signals[DEVICE_REMOVED] =
+    g_signal_new (I_("device-removed"),
+                  G_TYPE_FROM_CLASS (object_class),
+                  G_SIGNAL_RUN_LAST,
+                  0, NULL, NULL, NULL,
+                  G_TYPE_NONE, 1,
+                  CLUTTER_TYPE_INPUT_DEVICE);
+  signals[TOOL_CHANGED] =
+    g_signal_new (I_("tool-changed"),
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0, NULL, NULL,
+                  _clutter_marshal_VOID__OBJECT_OBJECT,
+                  G_TYPE_NONE, 2,
+                  CLUTTER_TYPE_INPUT_DEVICE,
+                  CLUTTER_TYPE_INPUT_DEVICE_TOOL);
+  g_signal_set_va_marshaller (signals[TOOL_CHANGED],
+                              G_TYPE_FROM_CLASS (object_class),
+                              _clutter_marshal_VOID__OBJECT_OBJECTv);
+
+  props[PROP_BACKEND] =
+    g_param_spec_object ("backend",
+                         P_("Backend"),
+                         P_("Backend"),
+                         CLUTTER_TYPE_BACKEND,
+                         CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+  g_object_class_install_properties (object_class, N_PROPS, props);
+}
+
+static void
+clutter_seat_init (ClutterSeat *seat)
+{
+}
+
+/**
+ * clutter_seat_get_pointer:
+ * @seat: a #ClutterSeat
+ *
+ * Returns the master pointer
+ *
+ * Returns: (transfer none): the master pointer
+ **/
+ClutterInputDevice *
+clutter_seat_get_pointer (ClutterSeat *seat)
+{
+  g_return_val_if_fail (CLUTTER_IS_SEAT (seat), NULL);
+
+  return CLUTTER_SEAT_GET_CLASS (seat)->get_pointer (seat);
+}
+
+/**
+ * clutter_seat_get_keyboard:
+ * @seat: a #ClutterSeat
+ *
+ * Returns the master keyboard
+ *
+ * Returns: (transfer none): the master keyboard
+ **/
+ClutterInputDevice *
+clutter_seat_get_keyboard (ClutterSeat *seat)
+{
+  g_return_val_if_fail (CLUTTER_IS_SEAT (seat), NULL);
+
+  return CLUTTER_SEAT_GET_CLASS (seat)->get_keyboard (seat);
+}
+
+/**
+ * clutter_seat_list_devices:
+ * @seat: a #ClutterSeat
+ *
+ * Returns the list of HW devices
+ *
+ * Returns: (transfer container) (element-type Clutter.InputDevice): A list of #ClutterInputDevice
+ **/
+GList *
+clutter_seat_list_devices (ClutterSeat *seat)
+{
+  g_return_val_if_fail (CLUTTER_IS_SEAT (seat), NULL);
+
+  return CLUTTER_SEAT_GET_CLASS (seat)->list_devices (seat);
+}
diff --git a/clutter/clutter/clutter-seat.h b/clutter/clutter/clutter-seat.h
new file mode 100644
index 000000000..40c9286a7
--- /dev/null
+++ b/clutter/clutter/clutter-seat.h
@@ -0,0 +1,57 @@
+/*
+ * Clutter.
+ *
+ * An OpenGL based 'interactive canvas' library.
+ *
+ * Copyright (C) 2019 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Carlos Garnacho <carlosg gnome org>
+ */
+#ifndef CLUTTER_SEAT_H
+#define CLUTTER_SEAT_H
+
+#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
+#error "Only <clutter/clutter.h> can be included directly."
+#endif
+
+#include "clutter/clutter-types.h"
+
+#define CLUTTER_TYPE_SEAT (clutter_seat_get_type ())
+
+CLUTTER_EXPORT
+G_DECLARE_DERIVABLE_TYPE (ClutterSeat, clutter_seat,
+                         CLUTTER, SEAT, GObject)
+
+typedef struct _ClutterSeatClass ClutterSeatClass;
+
+struct _ClutterSeatClass
+{
+  GObjectClass parent_class;
+
+  ClutterInputDevice * (* get_pointer)  (ClutterSeat *seat);
+  ClutterInputDevice * (* get_keyboard) (ClutterSeat *seat);
+
+  GList * (* list_devices) (ClutterSeat *seat);
+};
+
+CLUTTER_EXPORT
+ClutterInputDevice * clutter_seat_get_pointer  (ClutterSeat *seat);
+CLUTTER_EXPORT
+ClutterInputDevice * clutter_seat_get_keyboard (ClutterSeat *seat);
+CLUTTER_EXPORT
+GList * clutter_seat_list_devices (ClutterSeat *seat);
+
+#endif /* CLUTTER_SEAT_H */
diff --git a/clutter/clutter/meson.build b/clutter/clutter/meson.build
index 8173ad923..256c1ca5f 100644
--- a/clutter/clutter/meson.build
+++ b/clutter/clutter/meson.build
@@ -70,6 +70,7 @@ clutter_headers = [
   'clutter-script.h',
   'clutter-scriptable.h',
   'clutter-scroll-actor.h',
+  'clutter-seat.h',
   'clutter-settings.h',
   'clutter-shader-effect.h',
   'clutter-shader-types.h',
@@ -161,6 +162,7 @@ clutter_sources = [
   'clutter-script-parser.c',
   'clutter-scriptable.c',
   'clutter-scroll-actor.c',
+  'clutter-seat.c',
   'clutter-settings.c',
   'clutter-shader-effect.c',
   'clutter-shader-types.c',


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