[clutter/wip/evdev-tablet-support: 5/6] input-device: Add ClutterInputDeviceTool
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter/wip/evdev-tablet-support: 5/6] input-device: Add ClutterInputDeviceTool
- Date: Fri, 9 Jan 2015 16:41:35 +0000 (UTC)
commit 5dcccc241dc146473a74480acf4d83441b33a723
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Jan 9 17:37:28 2015 +0100
input-device: Add ClutterInputDeviceTool
This is an unique opaque struct that identifies a given tool of
a given device.
clutter/clutter-device-manager-private.h | 16 ++++
clutter/clutter-input-device.c | 124 ++++++++++++++++++++++++++++++
clutter/clutter-input-device.h | 5 +
clutter/clutter-types.h | 1 +
4 files changed, 146 insertions(+), 0 deletions(-)
---
diff --git a/clutter/clutter-device-manager-private.h b/clutter/clutter-device-manager-private.h
index 3e09288..d9771f2 100644
--- a/clutter/clutter-device-manager-private.h
+++ b/clutter/clutter-device-manager-private.h
@@ -31,6 +31,11 @@
G_BEGIN_DECLS
+struct _ClutterInputDeviceTool
+{
+ guint serial;
+};
+
typedef struct _ClutterAxisInfo
{
ClutterInputAxis axis;
@@ -132,6 +137,9 @@ struct _ClutterInputDevice
gchar *vendor_id;
gchar *product_id;
+ GPtrArray *tools;
+ ClutterInputDeviceTool *last_tool;
+
guint has_cursor : 1;
guint is_enabled : 1;
};
@@ -213,6 +221,14 @@ gboolean _clutter_input_device_get_scroll_delta (ClutterInputDev
ClutterScrollDirection *direction_p,
gdouble *delta_p);
+ClutterInputDeviceTool * _clutter_input_device_tool_new (guint serial);
+ClutterInputDeviceTool * _clutter_input_device_lookup_tool (ClutterInputDevice *device,
+ guint serial);
+void _clutter_input_device_add_tool (ClutterInputDevice *device,
+ ClutterInputDeviceTool *tool);
+void _clutter_input_device_update_tool (ClutterInputDevice *device,
+ ClutterInputDeviceTool *tool);
+
G_END_DECLS
#endif /* __CLUTTER_DEVICE_MANAGER_PRIVATE_H__ */
diff --git a/clutter/clutter-input-device.c b/clutter/clutter-input-device.c
index b6a1010..309a8c2 100644
--- a/clutter/clutter-input-device.c
+++ b/clutter/clutter-input-device.c
@@ -72,6 +72,14 @@ enum
PROP_LAST
};
+enum
+{
+ TOOL_CHANGED,
+ N_SIGNALS
+};
+
+static guint signals[N_SIGNALS] = { 0 };
+
static void _clutter_input_device_free_touch_info (gpointer data);
@@ -406,6 +414,23 @@ clutter_input_device_class_init (ClutterInputDeviceClass *klass)
NULL,
CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ /**
+ * ClutterInputDevice::tool-changed:
+ * @tool: The new tool in use for this device
+ *
+ * Emitted whenever the tool of a %CLUTTER_TABLET_DEVICE changes, a %NULL
+ * tool means the pen went too far from the tablet.
+ *
+ * Since: 1.22
+ */
+ signals[TOOL_CHANGED] =
+ g_signal_new (g_intern_static_string ("tool-changed"),
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__BOXED,
+ G_TYPE_NONE, 1, CLUTTER_TYPE_INPUT_DEVICE_TOOL);
+
gobject_class->dispose = clutter_input_device_dispose;
gobject_class->set_property = clutter_input_device_set_property;
gobject_class->get_property = clutter_input_device_get_property;
@@ -1974,3 +1999,102 @@ clutter_input_device_get_product_id (ClutterInputDevice *device)
return device->product_id;
}
+
+static ClutterInputDeviceTool *
+clutter_input_device_tool_copy (ClutterInputDeviceTool *tool)
+{
+ return tool;
+}
+
+static void
+clutter_input_device_tool_free (ClutterInputDeviceTool *tool)
+{
+ /* Nothing to free here, memory is owned by ClutterInputDevice */
+}
+
+G_DEFINE_BOXED_TYPE (ClutterInputDeviceTool, clutter_input_device_tool,
+ clutter_input_device_tool_copy,
+ clutter_input_device_tool_free);
+
+ClutterInputDeviceTool *
+_clutter_input_device_tool_new (guint serial)
+{
+ ClutterInputDeviceTool *tool;
+
+ tool = g_new0 (ClutterInputDeviceTool, 1);
+ tool->serial = serial;
+
+ return tool;
+}
+
+void
+_clutter_input_device_add_tool (ClutterInputDevice *device,
+ ClutterInputDeviceTool *tool)
+{
+ g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
+ g_return_if_fail (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_MASTER);
+ g_return_if_fail (tool != NULL);
+
+ if (!device->tools)
+ device->tools = g_ptr_array_new_with_free_func ((GDestroyNotify) g_free);
+
+ g_ptr_array_add (device->tools, tool);
+}
+
+void
+_clutter_input_device_update_tool (ClutterInputDevice *device,
+ ClutterInputDeviceTool *tool)
+{
+ g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
+ g_return_if_fail (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_MASTER);
+ g_return_if_fail (!tool || _clutter_input_device_lookup_tool (device, clutter_input_device_tool_get_serial
(tool)) != NULL);
+
+ if (device->last_tool == tool)
+ return;
+
+ device->last_tool = tool;
+ g_signal_emit (device, signals[TOOL_CHANGED], 0, tool);
+}
+
+ClutterInputDeviceTool *
+_clutter_input_device_lookup_tool (ClutterInputDevice *device,
+ guint serial)
+{
+ ClutterInputDeviceTool *tool;
+ guint i;
+
+ g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
+ g_return_val_if_fail (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_MASTER, NULL);
+
+ if (!device->tools)
+ return NULL;
+
+ for (i = 0; i < device->tools->len; i++)
+ {
+ tool = g_ptr_array_index (device->tools, i);
+
+ if (tool->serial == serial)
+ return tool;
+ }
+
+ return NULL;
+}
+
+/**
+ * clutter_input_device_tool_get_serial:
+ * @tool: a #ClutterInputDeviceTool
+ *
+ * Gets the serial of this tool, this value can be used to identify a
+ * physical tool (eg. a tablet pen) across program executions.
+ *
+ * Returns: The serial ID for this tool
+ *
+ * Since: 1.22
+ **/
+guint
+clutter_input_device_tool_get_serial (ClutterInputDeviceTool *tool)
+{
+ g_return_val_if_fail (tool != NULL, 0);
+
+ return tool->serial;
+}
diff --git a/clutter/clutter-input-device.h b/clutter/clutter-input-device.h
index 3019993..84800d2 100644
--- a/clutter/clutter-input-device.h
+++ b/clutter/clutter-input-device.h
@@ -33,6 +33,7 @@
G_BEGIN_DECLS
#define CLUTTER_TYPE_INPUT_DEVICE (clutter_input_device_get_type ())
+#define CLUTTER_TYPE_INPUT_DEVICE_TOOL (clutter_input_device_tool_get_type ())
#define CLUTTER_INPUT_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
CLUTTER_TYPE_INPUT_DEVICE, ClutterInputDevice))
#define CLUTTER_IS_INPUT_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
CLUTTER_TYPE_INPUT_DEVICE))
#define CLUTTER_INPUT_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
CLUTTER_TYPE_INPUT_DEVICE, ClutterInputDeviceClass))
@@ -49,6 +50,8 @@ typedef struct _ClutterInputDeviceClass ClutterInputDeviceClass;
CLUTTER_AVAILABLE_IN_1_0
GType clutter_input_device_get_type (void) G_GNUC_CONST;
+CLUTTER_AVAILABLE_IN_1_22
+GType clutter_input_device_tool_get_type (void) G_GNUC_CONST;
CLUTTER_AVAILABLE_IN_1_0
ClutterInputDeviceType clutter_input_device_get_device_type (ClutterInputDevice *device);
@@ -134,6 +137,8 @@ CLUTTER_AVAILABLE_IN_1_10
gboolean clutter_input_device_keycode_to_evdev (ClutterInputDevice *device,
guint hardware_keycode,
guint *evdev_keycode);
+CLUTTER_AVAILABLE_IN_1_22
+guint clutter_input_device_tool_get_serial (ClutterInputDeviceTool *tool);
CLUTTER_AVAILABLE_IN_1_22
const gchar * clutter_input_device_get_vendor_id (ClutterInputDevice *device);
diff --git a/clutter/clutter-types.h b/clutter/clutter-types.h
index f9b835a..353a23a 100644
--- a/clutter/clutter-types.h
+++ b/clutter/clutter-types.h
@@ -92,6 +92,7 @@ typedef struct _ClutterAnimation ClutterAnimation;
typedef struct _ClutterAnimator ClutterAnimator;
typedef struct _ClutterState ClutterState;
+typedef struct _ClutterInputDeviceTool ClutterInputDeviceTool;
typedef struct _ClutterInputDevice ClutterInputDevice;
typedef CoglMatrix ClutterMatrix;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]