[gtk+/wip/tablet-tools: 2/5] gdkdevice: Add GdkDevice::tool-changed signal



commit a34d9203ee445ba3dde784e91f379f613e1cd2fe
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Jan 6 14:44:15 2015 +0100

    gdkdevice: Add GdkDevice::tool-changed signal
    
    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        |   24 ++++++++++++++++++++++++
 gdk/gdkdeviceprivate.h |    3 +++
 2 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/gdk/gdkdevice.c b/gdk/gdkdevice.c
index 86cb7c0..b5aa07e 100644
--- a/gdk/gdkdevice.c
+++ b/gdk/gdkdevice.c
@@ -62,6 +62,7 @@ struct _GdkAxisInfo
 
 enum {
   CHANGED,
+  TOOL_CHANGED,
   LAST_SIGNAL
 };
 
@@ -261,6 +262,14 @@ gdk_device_class_init (GdkDeviceClass *klass)
                   0, NULL, NULL,
                   g_cclosure_marshal_VOID__VOID,
                   G_TYPE_NONE, 0);
+
+  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
@@ -1833,6 +1842,21 @@ gdk_device_lookup_tool (GdkDevice *device,
   return 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);
+  g_return_if_fail (!tool || gdk_device_lookup_tool (device, gdk_device_tool_get_serial (tool)) != NULL);
+
+  if (device->last_tool == tool)
+    return;
+
+  device->last_tool = tool;
+  g_signal_emit (device, signals[TOOL_CHANGED], 0, tool);
+}
+
 /**
  * gdk_device_tool_get_serial:
  * @tool: a #GdkDeviceTool
diff --git a/gdk/gdkdeviceprivate.h b/gdk/gdkdeviceprivate.h
index 902fe4f..e9bf917 100644
--- a/gdk/gdkdeviceprivate.h
+++ b/gdk/gdkdeviceprivate.h
@@ -58,6 +58,7 @@ struct _GdkDevice
   GArray *axes;
 
   GPtrArray *tools;
+  GdkDeviceTool *last_tool;
 };
 
 struct _GdkDeviceClass
@@ -181,6 +182,8 @@ 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);
 
 G_END_DECLS
 


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