[gnome-settings-daemon] common: Add helper to get the last tool ID



commit 0b74fb69defa8f80fed4e2fea367ef6e750eab61
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Dec 13 16:45:12 2011 +0000

    common: Add helper to get the last tool ID
    
    From a Wacom device.

 plugins/common/gsd-input-helper.c |   55 +++++++++++++++++++++++++++++++++++++
 plugins/common/gsd-input-helper.h |    5 ++-
 2 files changed, 58 insertions(+), 2 deletions(-)
---
diff --git a/plugins/common/gsd-input-helper.c b/plugins/common/gsd-input-helper.c
index 47e9931..a4d09c3 100644
--- a/plugins/common/gsd-input-helper.c
+++ b/plugins/common/gsd-input-helper.c
@@ -289,6 +289,61 @@ out:
         return NULL;
 }
 
+int
+xdevice_get_last_tool_id (int deviceid)
+{
+        Atom           prop;
+        Atom           act_type;
+        int            act_format;
+        unsigned long  nitems, bytes_after;
+        unsigned char *data, *ptr;
+        int            id;
+
+        id = 0x0;
+
+        gdk_display_sync (gdk_display_get_default ());
+
+        prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Wacom Serial IDs", False);
+        if (!prop)
+                return id;
+
+        gdk_error_trap_push ();
+
+        if (!XIGetProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
+                            deviceid, prop, 0, 1000, False,
+                            AnyPropertyType, &act_type, &act_format,
+                            &nitems, &bytes_after, &data) == Success) {
+                gdk_error_trap_pop_ignored ();
+                return 0x0;
+        }
+
+        if (gdk_error_trap_pop ())
+                goto out;
+
+	if (nitems != 4)
+		goto out;
+
+	if (act_type != XA_INTEGER)
+		goto out;
+
+	if (act_format != 32)
+		goto out;
+
+	/* item 0 = tablet ID
+	 * item 1 = old device serial number (== last tool in proximity)
+	 * item 2 = old hardware serial number (including tool ID)
+	 * item 3 = current serial number (0 if no tool in proximity) */
+	ptr = data;
+	ptr += act_format/8 * 2;
+
+	id = *((int32_t*)ptr);
+	id = id & 0xfffff;
+
+out:
+        XFree (data);
+        return id;
+}
+
 gboolean
 set_device_enabled (int device_id,
                     gboolean enabled)
diff --git a/plugins/common/gsd-input-helper.h b/plugins/common/gsd-input-helper.h
index 0bc205b..0f35af9 100644
--- a/plugins/common/gsd-input-helper.h
+++ b/plugins/common/gsd-input-helper.h
@@ -69,8 +69,9 @@ gboolean  device_set_property     (XDevice                *xdevice,
 gboolean  run_custom_command      (GdkDevice              *device,
                                    CustomCommand           command);
 
-GList *   get_disabled_devices    (GdkDeviceManager       *manager);
-char *    xdevice_get_device_node (int                     deviceid);
+GList *   get_disabled_devices     (GdkDeviceManager       *manager);
+char *    xdevice_get_device_node  (int                     deviceid);
+int       xdevice_get_last_tool_id (int                     deviceid);
 
 G_END_DECLS
 



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