[gtk+/wip/wayland-tablet: 537/555] x11: Update GdkDevices on "Wacom Serial IDs" property changes
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/wayland-tablet: 537/555] x11: Update GdkDevices on "Wacom Serial IDs" property changes
- Date: Tue, 29 Mar 2016 18:20:36 +0000 (UTC)
commit ae6b632f16e2f401b2f373d03f42a2fc8191b935
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Jan 6 14:56:02 2015 +0100
x11: Update GdkDevices on "Wacom Serial IDs" property changes
This takes care of the emission of GdkDevice::tool-changed, plus the
updating of the internal device accounting.
gdk/x11/gdkdevicemanager-xi2.c | 70 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index ad6babe..2dbc326 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -726,6 +726,7 @@ gdk_x11_device_manager_xi2_constructed (GObject *object)
screen = gdk_display_get_default_screen (display);
XISetMask (mask, XI_HierarchyChanged);
XISetMask (mask, XI_DeviceChanged);
+ XISetMask (mask, XI_PropertyEvent);
event_mask.deviceid = XIAllDevices;
event_mask.mask_len = sizeof (mask);
@@ -966,6 +967,70 @@ handle_device_changed (GdkX11DeviceManagerXI2 *device_manager,
_gdk_device_xi2_reset_scroll_valuators (GDK_X11_DEVICE_XI2 (source_device));
}
+static guint
+device_get_tool_serial (GdkDevice *device)
+{
+ GdkDisplay *display;
+ gulong nitems, bytes_after;
+ guint serial_id = 0;
+ guint32 *data;
+ int rc, format;
+ Atom type;
+
+ display = gdk_device_get_display (device);
+
+ gdk_x11_display_error_trap_push (display);
+
+ rc = XIGetProperty (GDK_DISPLAY_XDISPLAY (display),
+ gdk_x11_device_get_id (device),
+ gdk_x11_get_xatom_by_name_for_display (display, "Wacom Serial IDs"),
+ 0, 4, False, XA_INTEGER, &type, &format, &nitems, &bytes_after,
+ (guchar **) &data);
+ gdk_x11_display_error_trap_pop_ignored (display);
+
+ if (rc != Success)
+ return 0;
+
+ if (type == XA_INTEGER && format == 32 && nitems >= 4)
+ serial_id = data[3];
+
+ XFree (data);
+
+ return serial_id;
+}
+
+static void
+handle_property_change (GdkX11DeviceManagerXI2 *device_manager,
+ XIPropertyEvent *ev)
+{
+ GdkDevice *device;
+
+ device = g_hash_table_lookup (device_manager->id_table,
+ GUINT_TO_POINTER (ev->deviceid));
+
+ if (ev->property == gdk_x11_get_xatom_by_name ("Wacom Serial IDs"))
+ {
+ GdkDeviceTool *tool = NULL;
+ guint serial_id;
+ GdkSeat *seat;
+
+ if (ev->what != XIPropertyDeleted)
+ {
+ serial_id = device_get_tool_serial (device);
+ seat = gdk_device_get_seat (device);
+ tool = gdk_seat_get_tool (seat, serial_id);
+
+ if (!tool && serial_id > 0)
+ {
+ tool = gdk_device_tool_new (serial_id);
+ gdk_seat_default_add_tool (GDK_SEAT_DEFAULT (seat), tool);
+ }
+ }
+
+ gdk_device_update_tool (device, tool);
+ }
+}
+
static GdkCrossingMode
translate_crossing_mode (gint mode)
{
@@ -1366,6 +1431,11 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
(XIDeviceChangedEvent *) ev);
return_val = FALSE;
break;
+ case XI_PropertyEvent:
+ handle_property_change (device_manager,
+ (XIPropertyEvent *) ev);
+ return_val = FALSE;
+ break;
case XI_KeyPress:
case XI_KeyRelease:
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]