Commit 5e53676b authored by Carlos Garnacho's avatar Carlos Garnacho

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
parent 531fa786
......@@ -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
......
......@@ -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;
}
......@@ -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__ */
......@@ -56,6 +56,9 @@ struct _GdkDevice
GList *slaves;
GdkDeviceType type;
GArray *axes;
gchar *vendor_id;
gchar *product_id;
};
struct _GdkDeviceClass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment