[clutter/wip/evdev-tablet-support: 83/88] input-device: Add ClutterInputDeviceTool



commit d5c0c3534d13368d65a31bfcc00b258f975a3644
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   |   20 +++++
 clutter/clutter-enums.h                    |   26 ++++++
 clutter/clutter-input-device.c             |  119 ++++++++++++++++++++++++++++
 clutter/clutter-input-device.h             |    8 ++
 clutter/clutter-types.h                    |    1 +
 doc/reference/clutter/clutter-sections.txt |    5 +
 6 files changed, 179 insertions(+), 0 deletions(-)
---
diff --git a/clutter/clutter-device-manager-private.h b/clutter/clutter-device-manager-private.h
index 3e09288..18c185c 100644
--- a/clutter/clutter-device-manager-private.h
+++ b/clutter/clutter-device-manager-private.h
@@ -31,6 +31,14 @@
 
 G_BEGIN_DECLS
 
+struct _ClutterInputDeviceTool
+{
+  ClutterInputDeviceToolType type;
+  guint serial;
+  gpointer data;
+  GDestroyNotify notify;
+};
+
 typedef struct _ClutterAxisInfo
 {
   ClutterInputAxis axis;
@@ -132,6 +140,8 @@ struct _ClutterInputDevice
   gchar *vendor_id;
   gchar *product_id;
 
+  GPtrArray *tools;
+
   guint has_cursor : 1;
   guint is_enabled : 1;
 };
@@ -213,6 +223,16 @@ gboolean        _clutter_input_device_get_scroll_delta          (ClutterInputDev
                                                                  ClutterScrollDirection *direction_p,
                                                                  gdouble                *delta_p);
 
+ClutterInputDeviceTool * _clutter_input_device_tool_new         (guint                       serial,
+                                                                 ClutterInputDeviceToolType  type,
+                                                                 gpointer                    data,
+                                                                 GDestroyNotify              notify);
+ClutterInputDeviceTool * _clutter_input_device_lookup_tool      (ClutterInputDevice         *device,
+                                                                 guint                       serial,
+                                                                 ClutterInputDeviceToolType  type);
+void            _clutter_input_device_add_tool                  (ClutterInputDevice     *device,
+                                                                 ClutterInputDeviceTool *tool);
+
 G_END_DECLS
 
 #endif /* __CLUTTER_DEVICE_MANAGER_PRIVATE_H__ */
diff --git a/clutter/clutter-enums.h b/clutter/clutter-enums.h
index 9dd1b66..e7b64a3 100644
--- a/clutter/clutter-enums.h
+++ b/clutter/clutter-enums.h
@@ -1398,6 +1398,32 @@ typedef enum {
   CLUTTER_GESTURE_TRIGGER_EDGE_BEFORE
 } ClutterGestureTriggerEdge;
 
+/**
+ * ClutterInputDeviceToolType:
+ * @CLUTTER_INPUT_DEVICE_TOOL_NONE: No tool
+ * @CLUTTER_INPUT_DEVICE_TOOL_PEN: The tool is a pen
+ * @CLUTTER_INPUT_DEVICE_TOOL_ERASER: The tool is an eraser
+ * @CLUTTER_INPUT_DEVICE_TOOL_BRUSH: The tool is a brush
+ * @CLUTTER_INPUT_DEVICE_TOOL_PENCIL: The tool is a pencil
+ * @CLUTTER_INPUT_DEVICE_TOOL_AIRBRUSH: The tool is an airbrush
+ * @CLUTTER_INPUT_DEVICE_TOOL_FINGER: The tool is a finger
+ * @CLUTTER_INPUT_DEVICE_TOOL_MOUSE: The tool is a mouse
+ * @CLUTTER_INPUT_DEVICE_TOOL_LENS: The tool is a lens
+ *
+ * Since: 1.22
+ */
+typedef enum {
+  CLUTTER_INPUT_DEVICE_TOOL_NONE,
+  CLUTTER_INPUT_DEVICE_TOOL_PEN,
+  CLUTTER_INPUT_DEVICE_TOOL_ERASER,
+  CLUTTER_INPUT_DEVICE_TOOL_BRUSH,
+  CLUTTER_INPUT_DEVICE_TOOL_PENCIL,
+  CLUTTER_INPUT_DEVICE_TOOL_AIRBRUSH,
+  CLUTTER_INPUT_DEVICE_TOOL_FINGER,
+  CLUTTER_INPUT_DEVICE_TOOL_MOUSE,
+  CLUTTER_INPUT_DEVICE_TOOL_LENS
+} ClutterInputDeviceToolType;
+
 G_END_DECLS
 
 #endif /* __CLUTTER_ENUMS_H__ */
diff --git a/clutter/clutter-input-device.c b/clutter/clutter-input-device.c
index d9fd4f5..18d8378 100644
--- a/clutter/clutter-input-device.c
+++ b/clutter/clutter-input-device.c
@@ -2011,3 +2011,122 @@ 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,
+                                ClutterInputDeviceToolType type,
+                                gpointer                   data,
+                                GDestroyNotify             destroy_notify)
+{
+  ClutterInputDeviceTool *tool;
+
+  tool = g_new0 (ClutterInputDeviceTool, 1);
+  tool->serial = serial;
+  tool->type = type;
+  tool->data = data;
+  tool->notify = destroy_notify;
+
+  return tool;
+}
+
+static void
+_clutter_input_device_tool_free (ClutterInputDeviceTool *tool)
+{
+  if (tool->data && tool->notify)
+    tool->notify (tool->data);
+
+  g_slice_free (ClutterInputDeviceTool, 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) _clutter_input_device_tool_free);
+
+  g_ptr_array_add (device->tools, tool);
+}
+
+ClutterInputDeviceTool *
+_clutter_input_device_lookup_tool (ClutterInputDevice         *device,
+                                   guint                       serial,
+                                   ClutterInputDeviceToolType  type)
+{
+  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 && tool->type == type)
+        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;
+}
+
+
+/**
+ * clutter_input_device_tool_get_tool_type:
+ * @tool: a #ClutterInputDeviceTool
+ *
+ * Gets the tool type of this tool.
+ *
+ * Returns: The tool type of this tool
+ *
+ * Since: 1.22
+ **/
+ClutterInputDeviceToolType
+clutter_input_device_tool_get_tool_type (ClutterInputDeviceTool *tool)
+{
+  g_return_val_if_fail (tool != NULL, 0);
+
+  return tool->type;
+}
diff --git a/clutter/clutter-input-device.h b/clutter/clutter-input-device.h
index 3019993..a92dc6e 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,11 @@ 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
+ClutterInputDeviceToolType clutter_input_device_tool_get_tool_type (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;
diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt
index 327f185..7d6b8a6 100644
--- a/doc/reference/clutter/clutter-sections.txt
+++ b/doc/reference/clutter/clutter-sections.txt
@@ -1233,6 +1233,11 @@ clutter_input_device_sequence_get_grabbed_actor
 <SUBSECTION>
 clutter_input_device_update_from_event
 
+<SUBSECTION>
+ClutterInputDeviceToolType
+clutter_input_device_tool_get_serial
+clutter_input_device_tool_get_tool_type
+
 <SUBSECTION Standard>
 CLUTTER_TYPE_INPUT_DEVICE
 CLUTTER_INPUT_DEVICE


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