GdkDeviceTool: Add GdkDeviceToolType to identify the physical tool type
authorStephen Chandler Paul <thatslyude@gmail.com>
Tue, 13 Jan 2015 05:03:49 +0000 (00:03 -0500)
committerCarlos Garnacho <carlosg@gnome.org>
Wed, 6 Apr 2016 13:43:29 +0000 (15:43 +0200)
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
gdk/gdkdevice.c
gdk/gdkdevice.h
gdk/gdkdeviceprivate.h
gdk/x11/gdkdevicemanager-xi2.c

index a2757c7ab24d9a0cb95888afbfde2aec6a9b0fc0..786a5ad13df09edb1df9aca610cb3f1baedb5b28 100644 (file)
@@ -716,6 +716,7 @@ GdkInputSource
 GdkInputMode
 GdkAxisUse
 GdkAxisFlags
+GdkDeviceToolType
 GdkDeviceType
 GdkGrabOwnership
 
@@ -761,6 +762,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
index 63b3f5dc07f13b78200aae436f1a2f52f49fa5fd..bd1240d521d5954050c0eb624613fee9d18b327c 100644 (file)
@@ -2030,6 +2030,7 @@ G_DEFINE_TYPE (GdkDeviceTool, gdk_device_tool, G_TYPE_OBJECT)
 enum {
   TOOL_PROP_0,
   TOOL_PROP_SERIAL,
+  TOOL_PROP_TOOL_TYPE,
   N_TOOL_PROPS
 };
 
@@ -2048,6 +2049,9 @@ gdk_device_tool_set_property (GObject      *object,
     case TOOL_PROP_SERIAL:
       tool->serial = g_value_get_uint64 (value);
       break;
+    case TOOL_PROP_TOOL_TYPE:
+      tool->type = g_value_get_enum (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2067,6 +2071,9 @@ gdk_device_tool_get_property (GObject    *object,
     case TOOL_PROP_SERIAL:
       g_value_set_uint64 (value, tool->serial);
       break;
+    case TOOL_PROP_TOOL_TYPE:
+      g_value_set_enum (value, tool->type);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2087,6 +2094,13 @@ gdk_device_tool_class_init (GdkDeviceToolClass *klass)
                                                       0, G_MAXUINT64, 0,
                                                       G_PARAM_READWRITE |
                                                       G_PARAM_CONSTRUCT_ONLY);
+  tool_props[TOOL_PROP_TOOL_TYPE] = g_param_spec_enum ("tool-type",
+                                                       "Tool type",
+                                                       "Tool type",
+                                                       GDK_TYPE_DEVICE_TOOL_TYPE,
+                                                       GDK_DEVICE_TOOL_TYPE_UNKNOWN,
+                                                       G_PARAM_READWRITE |
+                                                       G_PARAM_CONSTRUCT_ONLY);
 
   g_object_class_install_properties (object_class, N_TOOL_PROPS, tool_props);
 }
@@ -2097,10 +2111,12 @@ gdk_device_tool_init (GdkDeviceTool *tool)
 }
 
 GdkDeviceTool *
-gdk_device_tool_new (guint64 serial)
+gdk_device_tool_new (guint64           serial,
+                     GdkDeviceToolType type)
 {
   return g_object_new (GDK_TYPE_DEVICE_TOOL,
                        "serial", serial,
+                       "tool-type", type,
                        NULL);
 }
 
@@ -2133,3 +2149,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.22
+ **/
+GdkDeviceToolType
+gdk_device_tool_get_tool_type (GdkDeviceTool *tool)
+{
+  g_return_val_if_fail (tool != NULL, GDK_DEVICE_TOOL_TYPE_UNKNOWN);
+
+  return tool->type;
+}
index 84ee37fde3822dd6f0c0ce6e97f84bd709b56ae2..495c4dc20b673a4769173d18e5f26f28b90591fa 100644 (file)
@@ -164,6 +164,33 @@ 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.
+ * @GDK_DEVICE_TOOL_TYPE_MOUSE: Tool is a mouse.
+ * @GDK_DEVICE_TOOL_TYPE_LENS: Tool is a lens cursor.
+ *
+ * Indicates the specific type of tool being used being a tablet. Such as an
+ * airbrush, pencil, etc.
+ *
+ * Since: 3.22
+ */
+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,
+  GDK_DEVICE_TOOL_TYPE_MOUSE,
+  GDK_DEVICE_TOOL_TYPE_LENS,
+} GdkDeviceToolType;
+
 /* We don't allocate each coordinate this big, but we use it to
  * be ANSI compliant and avoid accessing past the defined limits.
  */
@@ -331,6 +358,9 @@ GType gdk_device_tool_get_type (void) G_GNUC_CONST;
 GDK_AVAILABLE_IN_3_22
 guint gdk_device_tool_get_serial (GdkDeviceTool *tool);
 
+GDK_AVAILABLE_IN_3_22
+GdkDeviceToolType gdk_device_tool_get_tool_type (GdkDeviceTool *tool);
+
 G_END_DECLS
 
 #endif /* __GDK_DEVICE_H__ */
index 52ee6c69efb1c6055e95d687a069010404c649e5..6a0221ff00944b144375faeb2bc999ef056865de 100644 (file)
@@ -37,6 +37,7 @@ struct _GdkDeviceTool
 {
   GObject parent_instance;
   guint64 serial;
+  GdkDeviceToolType type;
 };
 
 struct _GdkDeviceToolClass
@@ -198,7 +199,8 @@ void  gdk_device_set_seat  (GdkDevice *device,
                             GdkSeat   *seat);
 
 /* Device tools */
-GdkDeviceTool *gdk_device_tool_new    (guint64        serial);
+GdkDeviceTool *gdk_device_tool_new    (guint64            serial,
+                                       GdkDeviceToolType  type);
 void           gdk_device_update_tool (GdkDevice     *device,
                                        GdkDeviceTool *tool);
 
index b70f5a7517f8e8984a135b56fd1b2b7eea500138..71d014d353c0d8bea015ecc90d18c4556992a0af 100644 (file)
@@ -1022,7 +1022,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_seat_default_add_tool (GDK_SEAT_DEFAULT (seat), tool);
             }
         }