[gtk+/wip/wayland-tablet: 8/23] GdkDeviceTool: Add GdkDeviceToolType to identify the physical tool type



commit fbf2ae9e894bf2092fc5d9f028207304454ec128
Author: Stephen Chandler Paul <thatslyude gmail com>
Date:   Tue Jan 13 00:03:49 2015 -0500

    GdkDeviceTool: Add GdkDeviceToolType to identify the physical tool type
    
    Because there are multiple different types of styluses that can be used with
    tablets, we have to have some sort of identifier for them attached to the
    GdkDeviceTool, especially since knowing the actual tool type for a GdkDeviceTool
    is necessary for matching up a GdkDeviceTool with it's appropriate
    GdkInputSource in Wayland (eg. matching up a GdkDeviceTool eraser with the
    GDK_SOURCE_ERASER GdkInputSource of a wayland tablet).
    
    Signed-off-by: Stephen Chandler Paul <thatslyude gmail com>

 docs/reference/gdk/gdk3-sections.txt |    2 ++
 gdk/gdkdevice.c                      |   23 ++++++++++++++++++++++-
 gdk/gdkdevice.h                      |   24 ++++++++++++++++++++++++
 gdk/gdkdeviceprivate.h               |   16 +++++++++-------
 gdk/x11/gdkdevicemanager-xi2.c       |    3 ++-
 5 files changed, 59 insertions(+), 9 deletions(-)
---
diff --git a/docs/reference/gdk/gdk3-sections.txt b/docs/reference/gdk/gdk3-sections.txt
index b835756..9a47e6e 100644
--- a/docs/reference/gdk/gdk3-sections.txt
+++ b/docs/reference/gdk/gdk3-sections.txt
@@ -709,6 +709,7 @@ GdkDevice
 GdkInputSource
 GdkInputMode
 GdkAxisUse
+GdkDeviceToolType
 GdkDeviceType
 GdkGrabOwnership
 
@@ -753,6 +754,7 @@ gdk_device_get_last_event_window
 
 <SUBSECTION>
 gdk_device_tool_get_serial
+gdk_device_tool_get_tool_type
 
 <SUBSECTION Standard>
 GDK_TYPE_AXIS_USE
diff --git a/gdk/gdkdevice.c b/gdk/gdkdevice.c
index 93378c2..3f7e4e3 100644
--- a/gdk/gdkdevice.c
+++ b/gdk/gdkdevice.c
@@ -1955,12 +1955,14 @@ G_DEFINE_BOXED_TYPE (GdkDeviceTool, gdk_device_tool,
                      gdk_device_tool_ref, gdk_device_tool_unref);
 
 GdkDeviceTool *
-gdk_device_tool_new (guint serial)
+gdk_device_tool_new (guint             serial,
+                     GdkDeviceToolType type)
 {
   GdkDeviceTool *tool;
 
   tool = g_new0 (GdkDeviceTool, 1);
   tool->serial = serial;
+  tool->type = type;
 
   return tool;
 }
@@ -2036,3 +2038,22 @@ gdk_device_tool_get_serial (GdkDeviceTool *tool)
 
   return tool->serial;
 }
+
+/**
+ * gdk_device_tool_get_tool_type:
+ * @tool: a #GdkDeviceTool
+ *
+ * Gets the #GdkDeviceToolType of the tool.
+ *
+ * Returns: The physical type for this tool. This can be used to figure out what
+ * sort of pen is being used, such as an airbrush or a pencil.
+ *
+ * Since: 3.18
+ **/
+GdkDeviceToolType
+gdk_device_tool_get_tool_type (GdkDeviceTool *tool)
+{
+  g_return_val_if_fail (tool != NULL, GDK_DEVICE_TOOL_TYPE_UNKNOWN);
+
+  return tool->type;
+}
diff --git a/gdk/gdkdevice.h b/gdk/gdkdevice.h
index 3c57d6e..4b0fd80 100644
--- a/gdk/gdkdevice.h
+++ b/gdk/gdkdevice.h
@@ -140,6 +140,27 @@ typedef enum {
   GDK_DEVICE_TYPE_FLOATING
 } GdkDeviceType;
 
+/**
+ * GdkDeviceToolType:
+ * @GDK_DEVICE_TOOL_TYPE_UNKNOWN: Tool is of an unknown type.
+ * @GDK_DEVICE_TOOL_TYPE_PEN: Tool is a standard tablet stylus.
+ * @GDK_DEVICE_TOOL_TYPE_ERASER: Tool is standard tablet eraser.
+ * @GDK_DEVICE_TOOL_TYPE_BRUSH: Tool is a brush stylus.
+ * @GDK_DEVICE_TOOL_TYPE_PENCIL: Tool is a pencil stylus.
+ * @GDK_DEVICE_TOOL_TYPE_AIRBRUSH: Tool is an airbrush stylus.
+ *
+ * Indicates the specific type of tool being used being a tablet. Such as an
+ * airbrush, pencil, etc.
+ */
+typedef enum {
+  GDK_DEVICE_TOOL_TYPE_UNKNOWN,
+  GDK_DEVICE_TOOL_TYPE_PEN,
+  GDK_DEVICE_TOOL_TYPE_ERASER,
+  GDK_DEVICE_TOOL_TYPE_BRUSH,
+  GDK_DEVICE_TOOL_TYPE_PENCIL,
+  GDK_DEVICE_TOOL_TYPE_AIRBRUSH
+} GdkDeviceToolType;
+
 /* We don't allocate each coordinate this big, but we use it to
  * be ANSI compliant and avoid accessing past the defined limits.
  */
@@ -304,6 +325,9 @@ GType gdk_device_tool_get_type (void) G_GNUC_CONST;
 GDK_AVAILABLE_IN_3_18
 guint gdk_device_tool_get_serial (GdkDeviceTool *tool);
 
+GDK_AVAILABLE_IN_3_18
+GdkDeviceToolType gdk_device_tool_get_tool_type (GdkDeviceTool *tool);
+
 G_END_DECLS
 
 #endif /* __GDK_DEVICE_H__ */
diff --git a/gdk/gdkdeviceprivate.h b/gdk/gdkdeviceprivate.h
index 0163211..bdd8332 100644
--- a/gdk/gdkdeviceprivate.h
+++ b/gdk/gdkdeviceprivate.h
@@ -34,6 +34,7 @@ typedef struct _GdkDeviceKey GdkDeviceKey;
 struct _GdkDeviceTool
 {
   guint serial;
+  GdkDeviceToolType type;
   gint ref_count;
 };
 
@@ -187,13 +188,14 @@ GdkWindow * _gdk_device_window_at_position    (GdkDevice        *device,
                                                gboolean          get_toplevel);
 
 /* Device tools */
-GdkDeviceTool *gdk_device_tool_new    (guint          serial);
-GdkDeviceTool *gdk_device_lookup_tool (GdkDevice     *device,
-                                       guint          serial);
-void           gdk_device_add_tool    (GdkDevice     *device,
-                                       GdkDeviceTool *tool);
-void           gdk_device_update_tool (GdkDevice     *device,
-                                       GdkDeviceTool *tool);
+GdkDeviceTool *gdk_device_tool_new    (guint              serial,
+                                       GdkDeviceToolType  type);
+GdkDeviceTool *gdk_device_lookup_tool (GdkDevice         *device,
+                                       guint              serial);
+void           gdk_device_add_tool    (GdkDevice         *device,
+                                       GdkDeviceTool     *tool);
+void           gdk_device_update_tool (GdkDevice         *device,
+                                       GdkDeviceTool     *tool);
 
 GdkDeviceTool *gdk_device_tool_ref    (GdkDeviceTool *tool);
 void           gdk_device_tool_unref  (GdkDeviceTool *tool);
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 182e295..90de9f0 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -900,7 +900,8 @@ handle_property_change (GdkX11DeviceManagerXI2 *device_manager,
 
           if (!tool && serial_id > 0)
             {
-              tool = gdk_device_tool_new (serial_id);
+              tool = gdk_device_tool_new (serial_id,
+                                          GDK_DEVICE_TOOL_TYPE_UNKNOWN);
               gdk_device_add_tool (device, tool);
             }
         }


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