From 92d93ede90db20a96dc6eed853eeaaaedeebdcb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=ABl=20Seghezzi?= Date: Sat, 9 Mar 2019 13:50:45 +0100 Subject: [PATCH] Add tablet termination and global cursor --- src/x11_init.c | 22 ++++++++++++++++++++++ src/x11_platform.h | 9 +++++---- src/x11_window.c | 5 ++--- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/x11_init.c b/src/x11_init.c index 1f27f8136..e753f0919 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -875,8 +875,11 @@ static float * getDeviceCoordinateTransformationMatrix(Display *display, int dev // static void initPenTablet(Display *display) { + _glfw.x11.xi.tablet_cursor = 0; _glfw.x11.xi.stylus_deviceid = 0; _glfw.x11.xi.eraser_deviceid = 0; + _glfw.x11.xi.stylus_CTMatrix = NULL; + _glfw.x11.xi.eraser_CTMatrix = NULL; if (_glfw.x11.xi.available) { @@ -927,6 +930,23 @@ static void initPenTablet(Display *display) } } +// XInput2 terminate pen tablet +// +static void terminatePenTablet(void) +{ + if (_glfw.x11.xi.stylus_CTMatrix) + { + XFree(_glfw.x11.xi.stylus_CTMatrix); + _glfw.x11.xi.stylus_CTMatrix = NULL; + } + + if (_glfw.x11.xi.eraser_CTMatrix) + { + XFree(_glfw.x11.xi.eraser_CTMatrix); + _glfw.x11.xi.eraser_CTMatrix = NULL; + } +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// @@ -1086,6 +1106,8 @@ int _glfwPlatformInit(void) void _glfwPlatformTerminate(void) { + terminatePenTablet(); + if (_glfw.x11.helperWindowHandle) { if (XGetSelectionOwner(_glfw.x11.display, _glfw.x11.CLIPBOARD) == diff --git a/src/x11_platform.h b/src/x11_platform.h index 5a05701e2..1858da1f3 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -392,10 +392,11 @@ typedef struct _GLFWlibraryX11 PFN_XIQueryDevice QueryDevice; PFN_XIGetProperty GetProperty; XIValuatorClassInfo stylus_ClassInfo[32]; - float *stylus_CTMatrix; - float *eraser_CTMatrix; - int stylus_deviceid; - int eraser_deviceid; + float *stylus_CTMatrix; + float *eraser_CTMatrix; + unsigned int tablet_cursor; + int stylus_deviceid; + int eraser_deviceid; } xi; struct { diff --git a/src/x11_window.c b/src/x11_window.c index 389e51124..e04d7d293 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1238,7 +1238,6 @@ static void processEvent(XEvent *event) if (re->deviceid == _glfw.x11.xi.stylus_deviceid || re->deviceid == _glfw.x11.xi.eraser_deviceid) { - static unsigned int s_cursor = 0; unsigned int cursor = re->deviceid == _glfw.x11.xi.stylus_deviceid ? 1 : 2; float x = 0.0f; float y = 0.0f; @@ -1246,10 +1245,10 @@ static void processEvent(XEvent *event) double tiltx = 0.0; double tilty = 0.0; - if (cursor != s_cursor) + if (cursor != _glfw.x11.xi.tablet_cursor) { _glfwInputPenTabletCursor(cursor); - s_cursor = cursor; + _glfw.x11.xi.tablet_cursor = cursor; } if (XIMaskIsSet(re->valuators.mask, 0))