[gtk+] device: Add property/getters for vendor/product identifiers



commit 5e53676b469d747b40763770828681c6970863ce
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Nov 18 14:24:52 2014 +0100

    device: Add property/getters for vendor/product identifiers
    
    These are a construct only properties, expected to be filled in from
    platform specific code.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=740758

 docs/reference/gdk/gdk3-sections.txt |    2 +
 gdk/gdkdevice.c                      |  114 +++++++++++++++++++++++++++++++++-
 gdk/gdkdevice.h                      |    5 ++
 gdk/gdkdeviceprivate.h               |    3 +
 4 files changed, 123 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gdk/gdk3-sections.txt b/docs/reference/gdk/gdk3-sections.txt
index b40b04b..dfd38a8 100644
--- a/docs/reference/gdk/gdk3-sections.txt
+++ b/docs/reference/gdk/gdk3-sections.txt
@@ -713,6 +713,8 @@ GdkGrabOwnership
 
 <SUBSECTION>
 gdk_device_get_name
+gdk_device_get_vendor_id
+gdk_device_get_product_id
 gdk_device_get_source
 gdk_device_set_mode
 gdk_device_get_mode
diff --git a/gdk/gdkdevice.c b/gdk/gdkdevice.c
index ebef53b..59631cf 100644
--- a/gdk/gdkdevice.c
+++ b/gdk/gdkdevice.c
@@ -86,7 +86,9 @@ enum {
   PROP_INPUT_SOURCE,
   PROP_INPUT_MODE,
   PROP_HAS_CURSOR,
-  PROP_N_AXES
+  PROP_N_AXES,
+  PROP_VENDOR_ID,
+  PROP_PRODUCT_ID
 };
 
 
@@ -236,6 +238,36 @@ gdk_device_class_init (GdkDeviceClass *klass)
                                                       P_("Number of axes in the device"),
                                                       0, G_MAXUINT, 0,
                                                       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+  /**
+   * GdkDevice:vendor-id:
+   *
+   * Vendor ID of this device, see gdk_device_get_vendor_id().
+   *
+   * Since: 3.16
+   */
+  g_object_class_install_property (object_class,
+                                   PROP_VENDOR_ID,
+                                   g_param_spec_string ("vendor-id",
+                                                        P_("Vendor ID"),
+                                                        P_("Vendor ID"),
+                                                        NULL,
+                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_STATIC_STRINGS));
+  /**
+   * GdkDevice:product-id:
+   *
+   * Product ID of this device, see gdk_device_get_product_id().
+   *
+   * Since: 3.16
+   */
+  g_object_class_install_property (object_class,
+                                   PROP_PRODUCT_ID,
+                                   g_param_spec_string ("product-id",
+                                                        P_("Product ID"),
+                                                        P_("Product ID"),
+                                                        NULL,
+                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_STATIC_STRINGS));
 
   /**
    * GdkDevice::changed:
@@ -293,6 +325,9 @@ gdk_device_dispose (GObject *object)
   device->name = NULL;
   device->keys = NULL;
 
+  g_clear_pointer (&device->vendor_id, g_free);
+  g_clear_pointer (&device->product_id, g_free);
+
   G_OBJECT_CLASS (gdk_device_parent_class)->dispose (object);
 }
 
@@ -329,6 +364,12 @@ gdk_device_set_property (GObject      *object,
     case PROP_HAS_CURSOR:
       device->has_cursor = g_value_get_boolean (value);
       break;
+    case PROP_VENDOR_ID:
+      device->vendor_id = g_value_dup_string (value);
+      break;
+    case PROP_PRODUCT_ID:
+      device->product_id = g_value_dup_string (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -372,6 +413,12 @@ gdk_device_get_property (GObject    *object,
     case PROP_N_AXES:
       g_value_set_uint (value, device->axes->len);
       break;
+    case PROP_VENDOR_ID:
+      g_value_set_string (value, device->vendor_id);
+      break;
+    case PROP_PRODUCT_ID:
+      g_value_set_string (value, device->product_id);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1757,3 +1804,68 @@ gdk_device_get_last_event_window (GdkDevice *device)
 
   return info->window_under_pointer;
 }
+
+/**
+ * gdk_device_get_vendor_id:
+ * @device: a slave #GdkDevice
+ *
+ * Returns the vendor ID of this device, or %NULL if this information couldn't
+ * be obtained. This ID is retrieved from the device, and is thus constant for
+ * it.
+ *
+ * This function, together with gdk_device_get_product_id(), can be used to eg.
+ * compose #GSettings paths to store settings for this device.
+ *
+ * |[<!-- language="C" -->
+ *  static GSettings *
+ *  get_device_settings (GdkDevice *device)
+ *  {
+ *    const gchar *vendor, *product;
+ *    GSettings *settings;
+ *    GdkDevice *device;
+ *    gchar *path;
+ *
+ *    vendor = gdk_device_get_vendor_id (device);
+ *    product = gdk_device_get_product_id (device);
+ *
+ *    path = g_strdup_printf ("/org/example/app/devices/%s:%s/", vendor, product);
+ *    settings = g_settings_new_with_path (DEVICE_SCHEMA, path);
+ *    g_free (path);
+ *
+ *    return settings;
+ *  }
+ * ]|
+ *
+ * Returns: (nullable): the vendor ID, or %NULL
+ *
+ * Since: 3.16
+ */
+const gchar *
+gdk_device_get_vendor_id (GdkDevice *device)
+{
+  g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
+  g_return_val_if_fail (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER, NULL);
+
+  return device->vendor_id;
+}
+
+/**
+ * gdk_device_get_product_id:
+ * @device: a slave #GdkDevice
+ *
+ * Returns the product ID of this device, or %NULL if this information couldn't
+ * be obtained. This ID is retrieved from the device, and is thus constant for
+ * it. See gdk_device_get_vendor_id() for more information.
+ *
+ * Returns: (nullable): the product ID, or %NULL
+ *
+ * Since: 3.16
+ */
+const gchar *
+gdk_device_get_product_id (GdkDevice *device)
+{
+  g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
+  g_return_val_if_fail (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER, NULL);
+
+  return device->product_id;
+}
diff --git a/gdk/gdkdevice.h b/gdk/gdkdevice.h
index 7e1094e..4894772 100644
--- a/gdk/gdkdevice.h
+++ b/gdk/gdkdevice.h
@@ -274,6 +274,11 @@ gboolean gdk_device_grab_info_libgtk_only (GdkDisplay  *display,
 GDK_AVAILABLE_IN_3_12
 GdkWindow *gdk_device_get_last_event_window (GdkDevice *device);
 
+GDK_AVAILABLE_IN_3_16
+const gchar *gdk_device_get_vendor_id       (GdkDevice *device);
+GDK_AVAILABLE_IN_3_16
+const gchar *gdk_device_get_product_id      (GdkDevice *device);
+
 G_END_DECLS
 
 #endif /* __GDK_DEVICE_H__ */
diff --git a/gdk/gdkdeviceprivate.h b/gdk/gdkdeviceprivate.h
index a8526b5..ea99897 100644
--- a/gdk/gdkdeviceprivate.h
+++ b/gdk/gdkdeviceprivate.h
@@ -56,6 +56,9 @@ struct _GdkDevice
   GList *slaves;
   GdkDeviceType type;
   GArray *axes;
+
+  gchar *vendor_id;
+  gchar *product_id;
 };
 
 struct _GdkDeviceClass


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