[gtk+/wip/wayland-tablet: 532/555] gdkdevice: Add GdkDeviceTool to identify device tools



commit 6bf87e2ac80ba46448b254fa90a3e0190ba573fd
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Jan 6 14:38:14 2015 +0100

    gdkdevice: Add GdkDeviceTool to identify device tools
    
    GdkDeviceTool is an opaque typedef that can be used to identify a given
    tool (eg. pens on tablets) during the app/device lifetime. Tools are only
    set on non-master devices, and are owned by these.
    
    The accounting functions are made private, the only public call on
    GdkDeviceTool so far is gdk_device_tool_get_serial(), useful to identify
    the tool across runs.

 docs/reference/gdk/gdk3-sections.txt |    3 ++
 gdk/gdkdevice.c                      |   49 ++++++++++++++++++++++++++++++++++
 gdk/gdkdevice.h                      |    9 ++++++
 gdk/gdkdeviceprivate.h               |   11 +++++++
 4 files changed, 72 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gdk/gdk3-sections.txt b/docs/reference/gdk/gdk3-sections.txt
index 0977794..5f5136a 100644
--- a/docs/reference/gdk/gdk3-sections.txt
+++ b/docs/reference/gdk/gdk3-sections.txt
@@ -759,6 +759,9 @@ gdk_device_list_axes
 gdk_device_get_axis_value
 gdk_device_get_last_event_window
 
+<SUBSECTION>
+gdk_device_tool_get_serial
+
 <SUBSECTION Standard>
 GDK_TYPE_AXIS_USE
 GDK_TYPE_EXTENSION_MODE
diff --git a/gdk/gdkdevice.c b/gdk/gdkdevice.c
index 0ede56c..e6c93c4 100644
--- a/gdk/gdkdevice.c
+++ b/gdk/gdkdevice.c
@@ -2003,3 +2003,52 @@ gdk_device_get_axes (GdkDevice *device)
 
   return device->axis_flags;
 }
+
+GdkDeviceTool *
+gdk_device_tool_ref (GdkDeviceTool *tool)
+{
+  tool->ref_count++;
+  return tool;
+}
+
+void
+gdk_device_tool_unref (GdkDeviceTool *tool)
+{
+  tool->ref_count--;
+
+  if (tool->ref_count == 0)
+    g_free (tool);
+}
+
+G_DEFINE_BOXED_TYPE (GdkDeviceTool, gdk_device_tool,
+                     gdk_device_tool_ref, gdk_device_tool_unref);
+
+GdkDeviceTool *
+gdk_device_tool_new (guint64 serial)
+{
+  GdkDeviceTool *tool;
+
+  tool = g_new0 (GdkDeviceTool, 1);
+  tool->serial = serial;
+
+  return tool;
+}
+
+/**
+ * gdk_device_tool_get_serial:
+ * @tool: a #GdkDeviceTool
+ *
+ * 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: 3.22
+ **/
+guint
+gdk_device_tool_get_serial (GdkDeviceTool *tool)
+{
+  g_return_val_if_fail (tool != NULL, 0);
+
+  return tool->serial;
+}
diff --git a/gdk/gdkdevice.h b/gdk/gdkdevice.h
index ad5bf66..acfc123 100644
--- a/gdk/gdkdevice.h
+++ b/gdk/gdkdevice.h
@@ -32,7 +32,10 @@ G_BEGIN_DECLS
 #define GDK_DEVICE(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GDK_TYPE_DEVICE, GdkDevice))
 #define GDK_IS_DEVICE(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDK_TYPE_DEVICE))
 
+#define GDK_TYPE_DEVICE_TOOL    (gdk_device_tool_get_type ())
+
 typedef struct _GdkTimeCoord GdkTimeCoord;
+typedef struct _GdkDeviceTool GdkDeviceTool;
 
 /**
  * GdkInputSource:
@@ -320,6 +323,12 @@ GdkSeat     *gdk_device_get_seat            (GdkDevice *device);
 GDK_AVAILABLE_IN_3_22
 GdkAxisFlags gdk_device_get_axes            (GdkDevice *device);
 
+GDK_AVAILABLE_IN_3_22
+GType gdk_device_tool_get_type (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_3_22
+guint gdk_device_tool_get_serial (GdkDeviceTool *tool);
+
 G_END_DECLS
 
 #endif /* __GDK_DEVICE_H__ */
diff --git a/gdk/gdkdeviceprivate.h b/gdk/gdkdeviceprivate.h
index bdfc93a..747369a 100644
--- a/gdk/gdkdeviceprivate.h
+++ b/gdk/gdkdeviceprivate.h
@@ -32,6 +32,12 @@ G_BEGIN_DECLS
 typedef struct _GdkDeviceClass GdkDeviceClass;
 typedef struct _GdkDeviceKey GdkDeviceKey;
 
+struct _GdkDeviceTool
+{
+  guint64 serial;
+  gint ref_count;
+};
+
 struct _GdkDeviceKey
 {
   guint keyval;
@@ -184,6 +190,11 @@ GdkWindow * _gdk_device_window_at_position    (GdkDevice        *device,
 void  gdk_device_set_seat  (GdkDevice *device,
                             GdkSeat   *seat);
 
+/* Device tools */
+GdkDeviceTool *gdk_device_tool_new    (guint64        serial);
+GdkDeviceTool *gdk_device_tool_ref    (GdkDeviceTool *tool);
+void           gdk_device_tool_unref  (GdkDeviceTool *tool);
+
 G_END_DECLS
 
 #endif /* __GDK_DEVICE_PRIVATE_H__ */


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