[mutter/wip/carlosg/clutter-keymap: 1/3] clutter: Add generic ClutterKeymap object



commit 7ae698795ed54de41817e16b6618c59b7e9f6231
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jan 10 12:34:28 2019 +0100

    clutter: Add generic ClutterKeymap object
    
    We thus far have similar objects/code internal to backends. Expose the
    minimum API necessary to cater for gnome-shell as a generic object.
    So far only the X11 backend has an actual GObject for it, and was made
    to be a subclass right away.

 clutter/clutter/clutter-backend-private.h          |  2 +
 clutter/clutter/clutter-keymap.c                   | 64 ++++++++++++++++++++++
 clutter/clutter/clutter-keymap.h                   | 56 +++++++++++++++++++
 clutter/clutter/clutter.h                          |  1 +
 clutter/clutter/meson.build                        |  2 +
 clutter/clutter/x11/clutter-backend-x11.c          |  9 +++
 .../clutter/x11/clutter-device-manager-core-x11.c  |  4 +-
 clutter/clutter/x11/clutter-device-manager-xi2.c   |  4 +-
 clutter/clutter/x11/clutter-keymap-x11.c           | 51 ++++++++---------
 9 files changed, 164 insertions(+), 29 deletions(-)
---
diff --git a/clutter/clutter/clutter-backend-private.h b/clutter/clutter/clutter-backend-private.h
index b2103d10e..631fb8d55 100644
--- a/clutter/clutter/clutter-backend-private.h
+++ b/clutter/clutter/clutter-backend-private.h
@@ -104,6 +104,8 @@ struct _ClutterBackendClass
 
   void                  (* bell_notify)          (ClutterBackend   *backend);
 
+  ClutterKeymap *       (* get_keymap)           (ClutterBackend   *backend);
+
   /* signals */
   void (* resolution_changed) (ClutterBackend *backend);
   void (* font_changed)       (ClutterBackend *backend);
diff --git a/clutter/clutter/clutter-keymap.c b/clutter/clutter/clutter-keymap.c
new file mode 100644
index 000000000..ebf99af28
--- /dev/null
+++ b/clutter/clutter/clutter-keymap.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2018 Red Hat
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Author: Carlos Garnacho <carlosg gnome org>
+ */
+
+#include "clutter-build-config.h"
+
+#include "clutter-keymap.h"
+#include "clutter-private.h"
+
+G_DEFINE_ABSTRACT_TYPE (ClutterKeymap, clutter_keymap, G_TYPE_OBJECT)
+
+enum
+{
+  STATE_CHANGED,
+  N_SIGNALS
+};
+
+static guint signals[N_SIGNALS] = { 0, };
+
+static void
+clutter_keymap_class_init (ClutterKeymapClass *klass)
+{
+  signals[STATE_CHANGED] =
+    g_signal_new (I_("state-changed"),
+                 G_TYPE_FROM_CLASS (klass),
+                 G_SIGNAL_RUN_FIRST,
+                 0, NULL, NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                 G_TYPE_NONE, 0);
+}
+
+static void
+clutter_keymap_init (ClutterKeymap *keymap)
+{
+}
+
+gboolean
+clutter_keymap_get_num_lock_state (ClutterKeymap *keymap)
+{
+  return CLUTTER_KEYMAP_GET_CLASS (keymap)->get_num_lock_state (keymap);
+}
+
+gboolean
+clutter_keymap_get_caps_lock_state (ClutterKeymap *keymap)
+{
+  return CLUTTER_KEYMAP_GET_CLASS (keymap)->get_caps_lock_state (keymap);
+}
diff --git a/clutter/clutter/clutter-keymap.h b/clutter/clutter/clutter-keymap.h
new file mode 100644
index 000000000..1c398fcab
--- /dev/null
+++ b/clutter/clutter/clutter-keymap.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2018 Red Hat
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Author: Carlos Garnacho <carlosg gnome org>
+ */
+
+#ifndef CLUTTER_KEYMAP_H
+#define CLUTTER_KEYMAP_H
+
+#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
+#error "Only <clutter/clutter.h> can be included directly."
+#endif
+
+#include <clutter/clutter-macros.h>
+
+#include <glib-object.h>
+
+typedef struct _ClutterKeymap ClutterKeymap;
+typedef struct _ClutterKeymapClass ClutterKeymapClass;
+
+struct _ClutterKeymapClass
+{
+  GObjectClass parent_class;
+
+  gboolean (* get_num_lock_state)  (ClutterKeymap *keymap);
+  gboolean (* get_caps_lock_state) (ClutterKeymap *keymap);
+};
+
+#define CLUTTER_TYPE_KEYMAP (clutter_keymap_get_type ())
+CLUTTER_EXPORT
+G_DECLARE_DERIVABLE_TYPE (ClutterKeymap, clutter_keymap,
+                         CLUTTER, KEYMAP,
+                         GObject)
+
+CLUTTER_EXPORT
+gboolean clutter_keymap_get_num_lock_state  (ClutterKeymap *keymap);
+
+CLUTTER_EXPORT
+gboolean clutter_keymap_get_caps_lock_state (ClutterKeymap *keymap);
+
+#endif /* CLUTTER_KEYMAP_H */
diff --git a/clutter/clutter/clutter.h b/clutter/clutter/clutter.h
index cd6b53798..231d8cd1b 100644
--- a/clutter/clutter/clutter.h
+++ b/clutter/clutter/clutter.h
@@ -76,6 +76,7 @@
 #include "clutter-input-focus.h"
 #include "clutter-interval.h"
 #include "clutter-keyframe-transition.h"
+#include "clutter-keymap.h"
 #include "clutter-keysyms.h"
 #include "clutter-layout-manager.h"
 #include "clutter-layout-meta.h"
diff --git a/clutter/clutter/meson.build b/clutter/clutter/meson.build
index e731e7e89..56cc03d98 100644
--- a/clutter/clutter/meson.build
+++ b/clutter/clutter/meson.build
@@ -48,6 +48,7 @@ clutter_headers = [
   'clutter-input-method.h',
   'clutter-interval.h',
   'clutter-keyframe-transition.h',
+  'clutter-keymap.h',
   'clutter-keysyms.h',
   'clutter-layout-manager.h',
   'clutter-layout-meta.h',
@@ -134,6 +135,7 @@ clutter_sources = [
   'clutter-virtual-input-device.c',
   'clutter-interval.c',
   'clutter-keyframe-transition.c',
+  'clutter-keymap.c',
   'clutter-keysyms-table.c',
   'clutter-layout-manager.c',
   'clutter-layout-meta.c',
diff --git a/clutter/clutter/x11/clutter-backend-x11.c b/clutter/clutter/x11/clutter-backend-x11.c
index 0172da6a0..af806d6cf 100644
--- a/clutter/clutter/x11/clutter-backend-x11.c
+++ b/clutter/clutter/x11/clutter-backend-x11.c
@@ -807,6 +807,14 @@ clutter_backend_x11_get_keymap_direction (ClutterBackend *backend)
   return _clutter_keymap_x11_get_direction (backend_x11->keymap);
 }
 
+static ClutterKeymap *
+clutter_backend_x11_get_keymap (ClutterBackend *backend)
+{
+  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
+
+  return CLUTTER_KEYMAP (backend_x11->keymap);
+}
+
 static void
 clutter_backend_x11_class_init (ClutterBackendX11Class *klass)
 {
@@ -829,6 +837,7 @@ clutter_backend_x11_class_init (ClutterBackendX11Class *klass)
   backend_class->get_display = clutter_backend_x11_get_display;
 
   backend_class->get_keymap_direction = clutter_backend_x11_get_keymap_direction;
+  backend_class->get_keymap = clutter_backend_x11_get_keymap;
 }
 
 static void
diff --git a/clutter/clutter/x11/clutter-device-manager-core-x11.c 
b/clutter/clutter/x11/clutter-device-manager-core-x11.c
index 34178c1ad..2dd5a57b6 100644
--- a/clutter/clutter/x11/clutter-device-manager-core-x11.c
+++ b/clutter/clutter/x11/clutter-device-manager-core-x11.c
@@ -97,9 +97,9 @@ translate_key_event (ClutterBackendX11       *backend_x11,
     _clutter_keymap_x11_get_is_modifier (backend_x11->keymap,
                                          event->key.hardware_keycode);
   event_x11->num_lock_set =
-    _clutter_keymap_x11_get_num_lock_state (backend_x11->keymap);
+    clutter_keymap_get_num_lock_state (CLUTTER_KEYMAP (backend_x11->keymap));
   event_x11->caps_lock_set =
-    _clutter_keymap_x11_get_caps_lock_state (backend_x11->keymap);
+    clutter_keymap_get_caps_lock_state (CLUTTER_KEYMAP (backend_x11->keymap));
 
   /* unicode_value is the printable representation */
   n = XLookupString (&xevent->xkey, buffer, sizeof (buffer) - 1, NULL, NULL);
diff --git a/clutter/clutter/x11/clutter-device-manager-xi2.c 
b/clutter/clutter/x11/clutter-device-manager-xi2.c
index 915106803..09d7522bf 100644
--- a/clutter/clutter/x11/clutter-device-manager-xi2.c
+++ b/clutter/clutter/x11/clutter-device-manager-xi2.c
@@ -1386,9 +1386,9 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
           _clutter_keymap_x11_get_is_modifier (backend_x11->keymap,
                                                event->key.hardware_keycode);
         event_x11->num_lock_set =
-          _clutter_keymap_x11_get_num_lock_state (backend_x11->keymap);
+          clutter_keymap_get_num_lock_state (CLUTTER_KEYMAP (backend_x11->keymap));
         event_x11->caps_lock_set =
-          _clutter_keymap_x11_get_caps_lock_state (backend_x11->keymap);
+          clutter_keymap_get_caps_lock_state (CLUTTER_KEYMAP (backend_x11->keymap));
 
         source_device = g_hash_table_lookup (manager_xi2->devices_by_id,
                                              GINT_TO_POINTER (xev->sourceid));
diff --git a/clutter/clutter/x11/clutter-keymap-x11.c b/clutter/clutter/x11/clutter-keymap-x11.c
index 5bbca54cf..a91a93b5e 100644
--- a/clutter/clutter/x11/clutter-keymap-x11.c
+++ b/clutter/clutter/x11/clutter-keymap-x11.c
@@ -53,7 +53,7 @@ struct _DirectionCacheEntry
 
 struct _ClutterKeymapX11
 {
-  GObject parent_instance;
+  ClutterKeymap parent_instance;
 
   ClutterBackend *backend;
 
@@ -86,7 +86,7 @@ struct _ClutterKeymapX11
 
 struct _ClutterKeymapX11Class
 {
-  GObjectClass parent_class;
+  ClutterKeymapClass parent_class;
 };
 
 enum
@@ -104,7 +104,8 @@ static void clutter_event_translator_iface_init (ClutterEventTranslatorIface *if
 
 #define clutter_keymap_x11_get_type     _clutter_keymap_x11_get_type
 
-G_DEFINE_TYPE_WITH_CODE (ClutterKeymapX11, clutter_keymap_x11, G_TYPE_OBJECT,
+G_DEFINE_TYPE_WITH_CODE (ClutterKeymapX11, clutter_keymap_x11,
+                         CLUTTER_TYPE_KEYMAP,
                          G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_EVENT_TRANSLATOR,
                                                 clutter_event_translator_iface_init));
 
@@ -215,12 +216,10 @@ static void
 update_locked_mods (ClutterKeymapX11 *keymap_x11,
                     gint              locked_mods)
 {
-#if 0
   gboolean old_caps_lock_state, old_num_lock_state;
 
   old_caps_lock_state = keymap_x11->caps_lock_state;
   old_num_lock_state  = keymap_x11->num_lock_state;
-#endif
 
   keymap_x11->caps_lock_state = (locked_mods & CLUTTER_LOCK_MASK) != 0;
   keymap_x11->num_lock_state  = (locked_mods & keymap_x11->num_lock_mask) != 0;
@@ -229,12 +228,9 @@ update_locked_mods (ClutterKeymapX11 *keymap_x11,
                 keymap_x11->num_lock_state ? "set" : "unset",
                 keymap_x11->caps_lock_state ? "set" : "unset");
 
-#if 0
-  /* Add signal to ClutterBackend? */
   if ((keymap_x11->caps_lock_state != old_caps_lock_state) ||
       (keymap_x11->num_lock_state != old_num_lock_state))
-    g_signal_emit_by_name (keymap_x11->backend, "key-lock-changed");
-#endif
+    g_signal_emit_by_name (keymap_x11, "state-changed");
 }
 
 /* the code to retrieve the keymap direction and cache it
@@ -524,10 +520,27 @@ clutter_keymap_x11_finalize (GObject *gobject)
   G_OBJECT_CLASS (clutter_keymap_x11_parent_class)->finalize (gobject);
 }
 
+static gboolean
+clutter_keymap_x11_get_num_lock_state (ClutterKeymap *keymap)
+{
+  ClutterKeymapX11 *keymap_x11 = CLUTTER_KEYMAP_X11 (keymap);
+
+  return keymap_x11->num_lock_state;
+}
+
+static gboolean
+clutter_keymap_x11_get_caps_lock_state (ClutterKeymap *keymap)
+{
+  ClutterKeymapX11 *keymap_x11 = CLUTTER_KEYMAP_X11 (keymap);
+
+  return keymap_x11->caps_lock_state;
+}
+
 static void
 clutter_keymap_x11_class_init (ClutterKeymapX11Class *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  ClutterKeymapClass *keymap_class = CLUTTER_KEYMAP_CLASS (klass);
 
   obj_props[PROP_BACKEND] =
     g_param_spec_object ("backend",
@@ -539,6 +552,10 @@ clutter_keymap_x11_class_init (ClutterKeymapX11Class *klass)
   gobject_class->constructed = clutter_keymap_x11_constructed;
   gobject_class->set_property = clutter_keymap_x11_set_property;
   gobject_class->finalize = clutter_keymap_x11_finalize;
+
+  keymap_class->get_num_lock_state = clutter_keymap_x11_get_num_lock_state;
+  keymap_class->get_caps_lock_state = clutter_keymap_x11_get_caps_lock_state;
+
   g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
 }
 
@@ -612,22 +629,6 @@ _clutter_keymap_x11_get_key_group (ClutterKeymapX11    *keymap,
   return XkbGroupForCoreState (state);
 }
 
-gboolean
-_clutter_keymap_x11_get_num_lock_state (ClutterKeymapX11 *keymap)
-{
-  g_return_val_if_fail (CLUTTER_IS_KEYMAP_X11 (keymap), FALSE);
-
-  return keymap->num_lock_state;
-}
-
-gboolean
-_clutter_keymap_x11_get_caps_lock_state (ClutterKeymapX11 *keymap)
-{
-  g_return_val_if_fail (CLUTTER_IS_KEYMAP_X11 (keymap), FALSE);
-
-  return keymap->caps_lock_state;
-}
-
 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 
 /* XXX - yes, I know that XKeycodeToKeysym() has been deprecated; hopefully,


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