From 6a56b95b3053b0834b053c1305b7716e02b5395d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Tue, 20 Sep 2011 15:45:29 +0200 Subject: [PATCH] Cocoa: Adjust touch point rectangle by -0.5. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The actual touch point is supposed to be in the center of the rectangle, and since the rectangle is 1x1 it means we have to subtract 0.5 from x and y. Change-Id: Ica4aba26dbe61328c8e7cbdcf8b02c96e2f41a40 Reviewed-on: http://codereview.qt-project.org/5256 Reviewed-by: Qt Sanity Bot Reviewed-by: Bjørn Erik Nilsen --- src/plugins/platforms/cocoa/qmultitouch_mac.mm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac.mm b/src/plugins/platforms/cocoa/qmultitouch_mac.mm index 2f9aefca52..88c583cc7a 100644 --- a/src/plugins/platforms/cocoa/qmultitouch_mac.mm +++ b/src/plugins/platforms/cocoa/qmultitouch_mac.mm @@ -87,12 +87,19 @@ void QCocoaTouch::updateTouchData(NSTouch *nstouch, NSTouchPhase phase) _screenReferencePos = qt_mac_flipPoint([NSEvent mouseLocation]); } + QPointF screenPos = _screenReferencePos; + NSSize dsize = [nstouch deviceSize]; float ppiX = (qnpos.x() - _trackpadReferencePos.x()) * dsize.width; float ppiY = (qnpos.y() - _trackpadReferencePos.y()) * dsize.height; QPointF relativePos = _trackpadReferencePos - QPointF(ppiX, ppiY); + screenPos -= relativePos; // Mac does not support area touch, only points, hence set width/height to 1. - _touchPoint.area = QRectF(_screenReferencePos - relativePos, QSize(1, 1)); + // The touch point is supposed to be in the center of '_touchPoint.area', and + // since width/height is 1 it means we must subtract 0.5 from x and y. + screenPos.rx() -= 0.5; + screenPos.ry() -= 0.5; + _touchPoint.area = QRectF(screenPos, QSize(1, 1)); } QCocoaTouch *QCocoaTouch::findQCocoaTouch(NSTouch *nstouch)