summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorArthur Krebsbach <Arthur.Krebsbach@Wacom.com>2013-10-08 15:51:23 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-16 06:16:33 (GMT)
commitc2f6d747ea997e0ba6bb970f5ec18ae3fe68514d (patch)
tree610d76b065eab6d398bef1ad41016fedb37660f0 /src/gui
parent0726127285413829f58618b5b82fb3e2da0c3a74 (diff)
downloadQt-c2f6d747ea997e0ba6bb970f5ec18ae3fe68514d.zip
Qt-c2f6d747ea997e0ba6bb970f5ec18ae3fe68514d.tar.gz
Qt-c2f6d747ea997e0ba6bb970f5ec18ae3fe68514d.tar.bz2
Windows: Fix tablet position in relative (mouse) mode.
When in "mouse" or "relative" mode with the pen position information would not be calculated correctly resulting in a significant offset between the tablet pen location and the mouse cursor location. Logic was added to detect when the two were not in sync and use the mouse location when this happens. Change-Id: Id3db5f2de0a657a0d072cee95c6b27179ea9182a Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com> (cherry picked from qtbase/17ebcd2b4690f73c8fd2332b0ba55b3ee3e2e8bb)
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qapplication_win.cpp42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp
index bbb1fca..ef9f582 100644
--- a/src/gui/kernel/qapplication_win.cpp
+++ b/src/gui/kernel/qapplication_win.cpp
@@ -260,6 +260,7 @@ static PtrWTGet ptrWTGet = 0;
static PACKET localPacketBuf[QT_TABLET_NPACKETQSIZE]; // our own tablet packet queue.
HCTX qt_tablet_context; // the hardware context for the tablet (like a window handle)
bool qt_tablet_tilt_support;
+QPointF oldHiResTabletGlobalPosF;
// flags for extensions for special Languages, currently only for RTL languages
bool qt_use_rtl_extensions = false;
@@ -3607,6 +3608,19 @@ bool QETWidget::translateTabletEvent(const MSG &msg, PACKET *localPacketBuf,
int z = 0;
qreal rotation = 0.0;
qreal tangentialPressure;
+ // The tablet can be used in 2 different modes, depending on it settings:
+ // 1) Absolute (pen) mode:
+ // The coordinates are scaled to the virtual desktop (by default). The user
+ // can also choose to scale to the monitor or a region of the screen.
+ // When entering proximity, the tablet driver snaps the mouse pointer to the
+ // tablet position scaled to that area and keeps it in sync.
+ // 2) Relative (mouse) mode:
+ // The pen follows the mouse. The constant 'absoluteRange' specifies the
+ // manhattanLength difference for detecting if a tablet input device is in this mode,
+ // in which case we snap the position to the mouse position.
+ // It seems there is no way to find out the mode programmatically, the LOGCONTEXT orgX/Y/Ext
+ // area is always the virtual desktop.
+ enum { absoluteRange = 20 };
// the most common event that we get...
t = QEvent::TabletMove;
@@ -3629,9 +3643,13 @@ bool QETWidget::translateTabletEvent(const MSG &msg, PACKET *localPacketBuf,
#endif // QT_NO_TABLETEVENT
prsNew = 0.0;
QRect desktopArea = QApplication::desktop()->geometry();
- QPointF hiResGlobal = currentTabletPointer.scaleCoord(ptNew.x, ptNew.y, desktopArea.left(),
- desktopArea.width(), desktopArea.top(),
- desktopArea.height());
+
+ // This code is to delay the tablet data one cycle to sync with the mouse location.
+ QPointF hiResTabletGlobalPosF = oldHiResTabletGlobalPosF;
+ oldHiResTabletGlobalPosF =
+ currentTabletPointer.scaleCoord(ptNew.x, ptNew.y, desktopArea.left(),
+ desktopArea.width(), desktopArea.top(),
+ desktopArea.height());
if (btnNew) {
#ifndef QT_NO_TABLETEVENT
@@ -3647,7 +3665,21 @@ bool QETWidget::translateTabletEvent(const MSG &msg, PACKET *localPacketBuf,
t = QEvent::TabletRelease;
button_pressed = false;
}
- QPoint globalPos(qRound(hiResGlobal.x()), qRound(hiResGlobal.y()));
+ QPoint globalPos = hiResTabletGlobalPosF.toPoint();
+
+ // Get Mouse Position and compare to tablet info
+ // Positions should be almost the same if we are in absolute
+ // mode. If they are not, use the mouse location.
+#ifndef Q_WS_WINCE
+ POINT mouseLocationP;
+ if (GetCursorPos(&mouseLocationP)) {
+ const QPoint mouseLocation(mouseLocationP.x, mouseLocationP.y);
+ if ((mouseLocation - globalPos).manhattanLength() > absoluteRange) {
+ globalPos = mouseLocation;
+ hiResTabletGlobalPosF = globalPos;
+ }
+ }
+#endif // !Q_WS_WINCE
if (t == QEvent::TabletPress)
{
@@ -3714,7 +3746,7 @@ bool QETWidget::translateTabletEvent(const MSG &msg, PACKET *localPacketBuf,
rotation = ort.orTwist;
}
#ifndef QT_NO_TABLETEVENT
- QTabletEvent e(t, localPos, globalPos, hiResGlobal, currentTabletPointer.currentDevice,
+ QTabletEvent e(t, localPos, globalPos, hiResTabletGlobalPosF, currentTabletPointer.currentDevice,
currentTabletPointer.currentPointerType, prsNew, tiltX, tiltY,
tangentialPressure, rotation, z, QApplication::keyboardModifiers(), currentTabletPointer.llId);
sendEvent = QApplication::sendSpontaneousEvent(w, &e);