File indexing completed on 2025-02-09 05:07:31
0001 /* 0002 * SPDX-FileCopyrightText: 2015 The Qt Company Ltd. 0003 * Contact: https://www.qt.io/licensing/ 0004 * SPDX-FileCopyrightText: 2015 Michael Abrahms <miabraha@gmail.com> 0005 * 0006 * SPDX-License-Identifier: GPL-3.0-or-later 0007 */ 0008 0009 #ifndef KIS_TABLET_SUPPORT_WIN_P_H 0010 #define KIS_TABLET_SUPPORT_WIN_P_H 0011 0012 0013 #include <QVector> 0014 #include <QPointF> 0015 #include <QMap> 0016 #include <QRect> 0017 0018 #include "wintab.h" 0019 0020 QT_BEGIN_NAMESPACE 0021 0022 class QDebug; 0023 class QWindow; 0024 class QRect; 0025 class QWidget; 0026 0027 struct QWindowsWinTab32DLL 0028 { 0029 QWindowsWinTab32DLL() : wTOpen(0), wTClose(0), wTInfo(0), wTEnable(0), wTOverlap(0), wTPacketsGet(0), wTGet(0), 0030 wTQueueSizeGet(0), wTQueueSizeSet(0) {} 0031 0032 bool init(); 0033 0034 typedef HCTX (API *PtrWTOpen)(HWND, LPLOGCONTEXT, BOOL); 0035 typedef BOOL (API *PtrWTClose)(HCTX); 0036 typedef UINT (API *PtrWTInfo)(UINT, UINT, LPVOID); 0037 typedef BOOL (API *PtrWTEnable)(HCTX, BOOL); 0038 typedef BOOL (API *PtrWTOverlap)(HCTX, BOOL); 0039 typedef int (API *PtrWTPacketsGet)(HCTX, int, LPVOID); 0040 typedef BOOL (API *PtrWTGet)(HCTX, LPLOGCONTEXT); 0041 typedef int (API *PtrWTQueueSizeGet)(HCTX); 0042 typedef BOOL (API *PtrWTQueueSizeSet)(HCTX, int); 0043 0044 PtrWTOpen wTOpen; 0045 PtrWTClose wTClose; 0046 PtrWTInfo wTInfo; 0047 PtrWTEnable wTEnable; 0048 PtrWTOverlap wTOverlap; 0049 PtrWTPacketsGet wTPacketsGet; 0050 PtrWTGet wTGet; 0051 PtrWTQueueSizeGet wTQueueSizeGet; 0052 PtrWTQueueSizeSet wTQueueSizeSet; 0053 }; 0054 0055 struct QWindowsTabletDeviceData 0056 { 0057 QWindowsTabletDeviceData() : minPressure(0), maxPressure(0), minTanPressure(0), 0058 maxTanPressure(0), minX(0), maxX(0), minY(0), maxY(0), minZ(0), maxZ(0), 0059 uniqueId(0), currentDevice(0), currentPointerType(0) {} 0060 0061 QPointF scaleCoordinates(int coordX, int coordY,const QRect &targetArea) const; 0062 qreal scalePressure(qreal p) const { return p / qreal(maxPressure - minPressure); } 0063 qreal scaleTangentialPressure(qreal p) const { return p / qreal(maxTanPressure - minTanPressure); } 0064 0065 int minPressure; 0066 int maxPressure; 0067 int minTanPressure; 0068 int maxTanPressure; 0069 int minX, maxX, minY, maxY, minZ, maxZ; 0070 qint64 uniqueId; 0071 int currentDevice; 0072 int currentPointerType; 0073 QRect virtualDesktopArea; 0074 0075 // Added by Krita 0076 QMap<quint8, quint8> buttonsMap; 0077 }; 0078 0079 QDebug operator<<(QDebug d, const QWindowsTabletDeviceData &t); 0080 0081 class QWindowsTabletSupport 0082 { 0083 Q_DISABLE_COPY(QWindowsTabletSupport) 0084 0085 explicit QWindowsTabletSupport(HWND window, HCTX context); 0086 0087 public: 0088 ~QWindowsTabletSupport(); 0089 0090 static QWindowsTabletSupport *create(); 0091 0092 void notifyActivate(); 0093 QString description() const; 0094 0095 bool translateTabletProximityEvent(WPARAM wParam, LPARAM lParam); 0096 bool translateTabletPacketEvent(); 0097 0098 int absoluteRange() const { return m_absoluteRange; } 0099 void setAbsoluteRange(int a) { m_absoluteRange = a; } 0100 0101 0102 void tabletUpdateCursor(const int pkCursor); 0103 static QWindowsWinTab32DLL m_winTab32DLL; 0104 0105 private: 0106 unsigned options() const; 0107 QWindowsTabletDeviceData tabletInit(const quint64 uniqueId, const UINT cursorType) const; 0108 0109 const HWND m_window; 0110 const HCTX m_context; 0111 int m_absoluteRange; 0112 bool m_tiltSupport; 0113 QVector<QWindowsTabletDeviceData> m_devices; 0114 int m_currentDevice; 0115 0116 0117 QWidget *targetWidget{0}; 0118 /** 0119 * This is an inelegant solution to record pen / eraser switches. 0120 * On the Surface Pro 3 we are only notified of cursor changes at the last minute. 0121 * The recommended way to handle switches is WT_CSRCHANGE, but that doesn't work 0122 * unless we save packet ID information, and we cannot change the structure of the 0123 * PACKETDATA due to Qt restrictions. 0124 * 0125 * Furthermore, WT_CSRCHANGE only ever appears *after* we receive the packet. 0126 */ 0127 UINT currentPkCursor{0}; 0128 bool isSurfacePro3{false}; //< Only enable this on SP3 or other devices with the same issue. 0129 0130 }; 0131 0132 QT_END_NAMESPACE 0133 0134 #endif // KIS_TABLET_SUPPORT_WIN_P_H