gdkdevice: Add GdkDevice::tool-changed signal
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 6 Jan 2015 13:44:15 +0000 (14:44 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Wed, 6 Apr 2016 13:43:29 +0000 (15:43 +0200)
On the devices and backends that support it, this signal will be emitted
on slave/floating devices whenever the tool they are interacting with
changes. These notifications may also work as a sort of proximity events,
as the tool will be unset when the pen moves too far.

For backends, gdk_device_update_tool() has been included, all that should
be done on their side is just calling this whenever any tool might have
changed.

gdk/gdkdevice.c
gdk/gdkdeviceprivate.h

index d05efc260d51aa9277d29551849ab2b92aabd88e..63b3f5dc07f13b78200aae436f1a2f52f49fa5fd 100644 (file)
@@ -57,6 +57,7 @@ struct _GdkAxisInfo
 
 enum {
   CHANGED,
+  TOOL_CHANGED,
   LAST_SIGNAL
 };
 
@@ -341,6 +342,24 @@ gdk_device_class_init (GdkDeviceClass *klass)
                   0, NULL, NULL,
                   g_cclosure_marshal_VOID__VOID,
                   G_TYPE_NONE, 0);
+
+  /**
+   * GdkDevice::tool-changed:
+   * @device: the #GdkDevice that changed.
+   * @tool: The new current tool
+   *
+   * The ::tool-changed signal is emitted on pen/eraser
+   * #GdkDevice<!-- -->s whenever tools enter or leave proximity.
+   *
+   * Since: 3.22
+   */
+  signals[TOOL_CHANGED] =
+    g_signal_new (g_intern_static_string ("tool-changed"),
+                  G_TYPE_FROM_CLASS (object_class),
+                  G_SIGNAL_RUN_LAST,
+                  0, NULL, NULL,
+                  g_cclosure_marshal_VOID__BOXED,
+                  G_TYPE_NONE, 1, GDK_TYPE_DEVICE_TOOL);
 }
 
 static void
@@ -388,6 +407,8 @@ gdk_device_dispose (GObject *object)
       g_object_unref (associated);
     }
 
+  g_clear_object (&device->last_tool);
+
   G_OBJECT_CLASS (gdk_device_parent_class)->dispose (object);
 }
 
@@ -2083,6 +2104,17 @@ gdk_device_tool_new (guint64 serial)
                        NULL);
 }
 
+void
+gdk_device_update_tool (GdkDevice     *device,
+                        GdkDeviceTool *tool)
+{
+  g_return_if_fail (GDK_IS_DEVICE (device));
+  g_return_if_fail (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER);
+
+  if (g_set_object (&device->last_tool, tool))
+    g_signal_emit (device, signals[TOOL_CHANGED], 0, tool);
+}
+
 /**
  * gdk_device_tool_get_serial:
  * @tool: a #GdkDeviceTool
index a0dad3ce461a3abfb2ff64e4bb8b090e4a7560e9..52ee6c69efb1c6055e95d687a069010404c649e5 100644 (file)
@@ -76,6 +76,7 @@ struct _GdkDevice
   gchar *product_id;
 
   GdkSeat *seat;
+  GdkDeviceTool *last_tool;
 };
 
 struct _GdkDeviceClass
@@ -198,6 +199,8 @@ void  gdk_device_set_seat  (GdkDevice *device,
 
 /* Device tools */
 GdkDeviceTool *gdk_device_tool_new    (guint64        serial);
+void           gdk_device_update_tool (GdkDevice     *device,
+                                       GdkDeviceTool *tool);
 
 G_END_DECLS