From 61a57465ea2120bcaf5a28c9a99136b01c86d858 Mon Sep 17 00:00:00 2001 From: Andrew Chadwick Date: Sat, 19 Nov 2016 18:34:29 +0000 Subject: [PATCH] win32: Fix tilt from Wintab devices Move the orientation sanity-checks into the packet decode func. Rationale: the packet handling func may otherwise read beyond the end of device->last_axis_data. Also expand them to cope with my test Huion's weird reporting. Also correct the azimuth angle to align with GDK's presentation. Most importantly, fix annoying comment typo. https://bugzilla.gnome.org/show_bug.cgi?id=774265 --- gdk/win32/gdkdevicemanager-win32.c | 34 ++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/gdk/win32/gdkdevicemanager-win32.c b/gdk/win32/gdkdevicemanager-win32.c index 0d4467e8ac..4699ab6533 100644 --- a/gdk/win32/gdkdevicemanager-win32.c +++ b/gdk/win32/gdkdevicemanager-win32.c @@ -625,17 +625,12 @@ wintab_init_check (GdkDeviceManagerWin32 *device_manager) num_axes++; } - /* The wintab driver for the Wacom ArtPad II reports - * PK_ORIENTATION in CSR_PKTDATA, but the tablet doesn't - * actually sense tilt. Catch this by noticing that the - * orientation axis's azimuth resolution is zero. - */ - if ((device->pktdata & PK_ORIENTATION) && axis_or[0].axResolution == 0) + if (device->pktdata & PK_ORIENTATION) { device->orientation_axes[0] = axis_or[0]; device->orientation_axes[1] = axis_or[1]; - /* Wintab gives us aximuth and altitude, which + /* Wintab gives us azimuth and altitude, which * we convert to x and y tilt in the -1000..1000 range */ _gdk_device_add_axis (GDK_DEVICE (device), @@ -817,11 +812,32 @@ decode_tilt (gint *axis_data, { double az, el; - /* As I don't have a tilt-sensing tablet, - * I cannot test this code. + /* The wintab driver for the Wacom ArtPad II reports + * PK_ORIENTATION in CSR_PKTDATA, but the tablet doesn't + * actually sense tilt. Catch this by noticing that the + * orientation axis's azimuth resolution is zero. + * + * The same is true of the Huion H610PRO, but in this case + * it's the altitude resolution that's zero. GdkEvents with + * sensible tilts will need both, so only add the GDK tilt axes + * if both wintab axes are going to be well-behaved in use. + */ + if ((axes == NULL) || (axis_data == NULL) || + (axes[0].axResolution == 0) || + (axes[1].axResolution == 0)) + { + axis_data[0] = 0; + axis_data[1] = 0; + return; + } + + /* + * Tested with a Wacom Intuos 5 touch M (PTH-650) + Wacom drivers 6.3.18-5. + * Wintab's reference angle leads gdk's by 90 degrees. */ az = TWOPI * packet->pkOrientation.orAzimuth / (axes[0].axResolution / 65536.); + az -= G_PI / 2; el = TWOPI * packet->pkOrientation.orAltitude / (axes[1].axResolution / 65536.);