[gtk+] Add a display property to keymaps



commit c2793de6e24abe7f405b4422781cdb9a9253dd3a
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jan 11 21:43:01 2018 -0500

    Add a display property to keymaps
    
    This is a general pattern we want to follow for all
    objects in GDK. Also add a getter.

 gdk/gdkkeys.c |   65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 gdk/gdkkeys.h |    3 ++
 2 files changed, 66 insertions(+), 2 deletions(-)
---
diff --git a/gdk/gdkkeys.c b/gdk/gdkkeys.c
index 84f9cda..9f29e5d 100644
--- a/gdk/gdkkeys.c
+++ b/gdk/gdkkeys.c
@@ -98,6 +98,11 @@
  * gdk_keymap_translate_keyboard_state() just to get the keyval.
  */
 
+enum {
+  PROP_0,
+  PROP_DISPLAY,
+  LAST_PROP
+};
 
 enum {
   DIRECTION_CHANGED,
@@ -106,22 +111,70 @@ enum {
   LAST_SIGNAL
 };
 
+static GParamSpec *props[LAST_PROP] = { NULL, };
+static guint signals[LAST_SIGNAL] = { 0 };
 
 static GdkModifierType gdk_keymap_real_get_modifier_mask (GdkKeymap         *keymap,
                                                           GdkModifierIntent  intent);
 
+G_DEFINE_TYPE (GdkKeymap, gdk_keymap, G_TYPE_OBJECT)
 
-static guint signals[LAST_SIGNAL] = { 0 };
+static void
+gdk_keymap_get_property (GObject    *object,
+                         guint       prop_id,
+                         GValue     *value,
+                         GParamSpec *pspec)
+{
+  GdkKeymap *keymap = GDK_KEYMAP (object);
 
-G_DEFINE_TYPE (GdkKeymap, gdk_keymap, G_TYPE_OBJECT)
+  switch (prop_id)
+    {
+    case PROP_DISPLAY:
+      g_value_set_object (value, keymap->display);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gdk_keymap_set_property (GObject      *object,
+                         guint         prop_id,
+                         const GValue *value,
+                         GParamSpec   *pspec)
+{
+  GdkKeymap *keymap = GDK_KEYMAP (object);
+
+  switch (prop_id)
+    {
+    case PROP_DISPLAY:
+      keymap->display = g_value_get_object (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
 
 static void
 gdk_keymap_class_init (GdkKeymapClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->get_property = gdk_keymap_get_property;
+  object_class->set_property = gdk_keymap_set_property;
+
   klass->get_modifier_mask = gdk_keymap_real_get_modifier_mask;
 
+  props[PROP_DISPLAY] =
+    g_param_spec_object ("display",
+                         "Display",
+                         "The display of the keymap",
+                         GDK_TYPE_DISPLAY,
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, LAST_PROP, props);
+
   /**
    * GdkKeymap::direction-changed:
    * @keymap: the object on which the signal is emitted
@@ -185,6 +238,14 @@ gdk_keymap_init (GdkKeymap *keymap)
 {
 }
 
+GdkDisplay *
+gdk_keymap_get_display (GdkKeymap *keymap)
+{
+  g_return_val_if_fail (GDK_IS_KEYMAP (keymap), NULL);
+
+  return keymap->display;
+}
+
 /* Other key-handling stuff
  */
 
diff --git a/gdk/gdkkeys.h b/gdk/gdkkeys.h
index 304c86e..afb11b3 100644
--- a/gdk/gdkkeys.h
+++ b/gdk/gdkkeys.h
@@ -80,6 +80,9 @@ struct _GdkKeymapKey
 GDK_AVAILABLE_IN_ALL
 GType gdk_keymap_get_type (void) G_GNUC_CONST;
 
+GDK_AVAILABLE_IN_3_94
+GdkDisplay *   gdk_keymap_get_display              (GdkKeymap           *keymap);
+
 GDK_AVAILABLE_IN_ALL
 guint          gdk_keymap_lookup_key               (GdkKeymap           *keymap,
                                                    const GdkKeymapKey  *key);


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