Warning, /graphics/krita/3rdparty/ext_qt/0024-Fetch-stylus-button-remapping-from-WinTab-driver.patch is written in an unsupported language. File is not indexed.
0001 From abf7f3d27f0382476f4b1e2848815c2a2547bf25 Mon Sep 17 00:00:00 2001 0002 From: Dmitry Kazakov <dimula73@gmail.com> 0003 Date: Sat, 13 Apr 2019 18:08:33 +0300 0004 Subject: [PATCH 05/47] Fetch stylus button remapping from WinTab driver 0005 0006 The user can remap the stylus buttons using tablet driver settings. 0007 This information is available to the application via CSR_SYSBTNMAP 0008 WinTab feature. We should fetch this information every time the 0009 stylus gets into proximity, because the user can change these settings 0010 on the fly. 0011 0012 Change-Id: Idc839905c3485179d782814f78fa862fd4a99127 0013 --- 0014 .../windows/qwindowstabletsupport.cpp | 72 ++++++++++++++++++- 0015 .../platforms/windows/qwindowstabletsupport.h | 2 + 0016 2 files changed, 73 insertions(+), 1 deletion(-) 0017 0018 diff --git a/src/plugins/platforms/windows/qwindowstabletsupport.cpp b/src/plugins/platforms/windows/qwindowstabletsupport.cpp 0019 index fa209f09c4..44b94d044d 100644 0020 --- a/src/plugins/platforms/windows/qwindowstabletsupport.cpp 0021 +++ b/src/plugins/platforms/windows/qwindowstabletsupport.cpp 0022 @@ -435,6 +435,27 @@ bool QWindowsTabletSupport::translateTabletProximityEvent(WPARAM /* wParam */, L 0023 m_currentDevice = m_devices.size(); 0024 m_devices.push_back(tabletInit(uniqueId, cursorType)); 0025 } 0026 + 0027 + /** 0028 + * We should check button map for changes on every proximity event, not 0029 + * only during initialization phase. 0030 + * 0031 + * WARNING: in 2016 there were some Wacom table drivers, which could mess up 0032 + * button mapping if the remapped button was pressed, while the 0033 + * application **didn't have input focus**. This bug is somehow 0034 + * related to the fact that Wacom drivers allow user to configure 0035 + * per-application button-mappings. If the bug shows up again, 0036 + * just move this button-map fetching into initialization block. 0037 + * 0038 + * See https://bugs.kde.org/show_bug.cgi?id=359561 0039 + */ 0040 + BYTE logicalButtons[32]; 0041 + memset(logicalButtons, 0, 32); 0042 + m_winTab32DLL.wTInfo(WTI_CURSORS + currentCursor, CSR_SYSBTNMAP, &logicalButtons); 0043 + m_devices[m_currentDevice].buttonsMap[0x1] = logicalButtons[0]; 0044 + m_devices[m_currentDevice].buttonsMap[0x2] = logicalButtons[1]; 0045 + m_devices[m_currentDevice].buttonsMap[0x4] = logicalButtons[2]; 0046 + 0047 m_devices[m_currentDevice].currentPointerType = pointerType(currentCursor); 0048 m_state = PenProximity; 0049 qCDebug(lcQpaTablet) << "enter proximity for device #" 0050 @@ -446,6 +467,52 @@ bool QWindowsTabletSupport::translateTabletProximityEvent(WPARAM /* wParam */, L 0051 return true; 0052 } 0053 0054 +Qt::MouseButton buttonValueToEnum(DWORD button, 0055 + const QWindowsTabletDeviceData &tdd) { 0056 + 0057 + enum : unsigned { 0058 + leftButtonValue = 0x1, 0059 + middleButtonValue = 0x2, 0060 + rightButtonValue = 0x4, 0061 + doubleClickButtonValue = 0x7 0062 + }; 0063 + 0064 + button = tdd.buttonsMap.value(button); 0065 + 0066 + return button == leftButtonValue ? Qt::LeftButton : 0067 + button == rightButtonValue ? Qt::RightButton : 0068 + button == doubleClickButtonValue ? Qt::MiddleButton : 0069 + button == middleButtonValue ? Qt::MiddleButton : 0070 + button ? Qt::LeftButton /* fallback item */ : 0071 + Qt::NoButton; 0072 +} 0073 + 0074 +Qt::MouseButtons convertTabletButtons(DWORD btnNew, 0075 + const QWindowsTabletDeviceData &tdd) { 0076 + 0077 + Qt::MouseButtons buttons = Qt::NoButton; 0078 + for (unsigned int i = 0; i < 3; i++) { 0079 + unsigned int btn = 0x1 << i; 0080 + 0081 + if (btn & btnNew) { 0082 + Qt::MouseButton convertedButton = 0083 + buttonValueToEnum(btn, tdd); 0084 + 0085 + buttons |= convertedButton; 0086 + 0087 + /** 0088 + * If a button that is present in hardware input is 0089 + * mapped to a Qt::NoButton, it means that it is going 0090 + * to be eaten by the driver, for example by its 0091 + * "Pan/Scroll" feature. Therefore we shouldn't handle 0092 + * any of the events associated to it. We'll just return 0093 + * Qt::NoButtons here. 0094 + */ 0095 + } 0096 + } 0097 + return buttons; 0098 +} 0099 + 0100 bool QWindowsTabletSupport::translateTabletPacketEvent() 0101 { 0102 static PACKET localPacketBuf[TabletPacketQSize]; // our own tablet packet queue. 0103 @@ -552,9 +619,12 @@ bool QWindowsTabletSupport::translateTabletPacketEvent() 0104 << tiltY << "tanP:" << tangentialPressure << "rotation:" << rotation; 0105 } 0106 0107 + Qt::MouseButtons buttons = 0108 + convertTabletButtons(packet.pkButtons, m_devices.at(m_currentDevice)); 0109 + 0110 QWindowSystemInterface::handleTabletEvent(target, packet.pkTime, QPointF(localPos), globalPosF, 0111 currentDevice, currentPointer, 0112 - static_cast<Qt::MouseButtons>(packet.pkButtons), 0113 + buttons, 0114 pressureNew, tiltX, tiltY, 0115 tangentialPressure, rotation, z, 0116 uniqueId, 0117 diff --git a/src/plugins/platforms/windows/qwindowstabletsupport.h b/src/plugins/platforms/windows/qwindowstabletsupport.h 0118 index d91701d6a5..8f97982308 100644 0119 --- a/src/plugins/platforms/windows/qwindowstabletsupport.h 0120 +++ b/src/plugins/platforms/windows/qwindowstabletsupport.h 0121 @@ -45,6 +45,7 @@ 0122 0123 #include <QtCore/qvector.h> 0124 #include <QtCore/qpoint.h> 0125 +#include <QtCore/qhash.h> 0126 0127 #include <wintab.h> 0128 0129 @@ -100,6 +101,7 @@ struct QWindowsTabletDeviceData 0130 qint64 uniqueId = 0; 0131 int currentDevice = 0; 0132 int currentPointerType = 0; 0133 + QHash<quint8, quint8> buttonsMap; 0134 }; 0135 0136 #ifndef QT_NO_DEBUG_STREAM 0137 -- 0138 2.20.1.windows.1 0139