From d2ee5811d0dbd9afeb5e1979c4bbd80aab93591a Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 6 Nov 2024 16:50:06 +0100 Subject: [PATCH] QCocoaDrag: consistently update the last view and event pointers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As pointed out in the qcocoadrag.h header, we need QCocoaDrag to record the original event and view when handling an event in QNSView. For that, NSView's handleMouseEvent implementation called setLastMouseEvent. This was not done for tablet or touch events, although both of those event types might initiate and participate in drag'n'drop operation. Do that consistently now, and rename the setter accordingly to setLastInputEvent. Task-number: QTBUG-116554 Pick-to: 6.5 Change-Id: I9646adbec3a2301ebca123f0f25328db63c782a8 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 0a40266788021aaa2f501aeef6db2e222669c6e9) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/cocoa/qcocoadrag.h | 2 +- src/plugins/platforms/cocoa/qcocoadrag.mm | 2 +- src/plugins/platforms/cocoa/qnsview_mouse.mm | 2 +- src/plugins/platforms/cocoa/qnsview_tablet.mm | 3 +++ src/plugins/platforms/cocoa/qnsview_touch.mm | 12 ++++++++++++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoadrag.h b/src/plugins/platforms/cocoa/qcocoadrag.h index dedf8a7fd9c..f470fa39a9f 100644 --- a/src/plugins/platforms/cocoa/qcocoadrag.h +++ b/src/plugins/platforms/cocoa/qcocoadrag.h @@ -35,7 +35,7 @@ public: * to meet NSView dragImage:at guarantees, we need to record the original * event and view when handling an event in QNSView */ - void setLastMouseEvent(NSEvent *event, NSView *view); + void setLastInputEvent(NSEvent *event, NSView *view); void setAcceptedAction(Qt::DropAction act); void exitDragLoop(); diff --git a/src/plugins/platforms/cocoa/qcocoadrag.mm b/src/plugins/platforms/cocoa/qcocoadrag.mm index 3a9f5a87941..3b736db39b3 100644 --- a/src/plugins/platforms/cocoa/qcocoadrag.mm +++ b/src/plugins/platforms/cocoa/qcocoadrag.mm @@ -31,7 +31,7 @@ QCocoaDrag::~QCocoaDrag() [m_lastEvent release]; } -void QCocoaDrag::setLastMouseEvent(NSEvent *event, NSView *view) +void QCocoaDrag::setLastInputEvent(NSEvent *event, NSView *view) { [m_lastEvent release]; m_lastEvent = [event copy]; diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm index 2fd57fe68e6..c566e499b73 100644 --- a/src/plugins/platforms/cocoa/qnsview_mouse.mm +++ b/src/plugins/platforms/cocoa/qnsview_mouse.mm @@ -117,7 +117,7 @@ static const QPointingDevice *pointingDeviceFor(qint64 deviceID) ulong timestamp = [theEvent timestamp] * 1000; QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag(); - nativeDrag->setLastMouseEvent(theEvent, self); + nativeDrag->setLastInputEvent(theEvent, self); const auto modifiers = QAppleKeyMapper::fromCocoaModifiers(theEvent.modifierFlags); auto button = cocoaButton2QtButton(theEvent); diff --git a/src/plugins/platforms/cocoa/qnsview_tablet.mm b/src/plugins/platforms/cocoa/qnsview_tablet.mm index 4c6e351b3f4..09553aee5f6 100644 --- a/src/plugins/platforms/cocoa/qnsview_tablet.mm +++ b/src/plugins/platforms/cocoa/qnsview_tablet.mm @@ -28,6 +28,9 @@ Q_GLOBAL_STATIC(QCocoaTabletDeviceMap, devicesInProximity) ulong timestamp = [theEvent timestamp] * 1000; + QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag(); + nativeDrag->setLastInputEvent(theEvent, self); + QPointF windowPoint; QPointF screenPoint; [self convertFromScreen:[self screenMousePoint:theEvent] toWindowPoint: &windowPoint andScreenPoint: &screenPoint]; diff --git a/src/plugins/platforms/cocoa/qnsview_touch.mm b/src/plugins/platforms/cocoa/qnsview_touch.mm index 97ed5b76249..5d93d2c688a 100644 --- a/src/plugins/platforms/cocoa/qnsview_touch.mm +++ b/src/plugins/platforms/cocoa/qnsview_touch.mm @@ -37,6 +37,10 @@ Q_LOGGING_CATEGORY(lcQpaTouch, "qt.qpa.input.touch") return; const NSTimeInterval timestamp = [event timestamp]; + + QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag(); + nativeDrag->setLastInputEvent(event, self); + const QList points = QCocoaTouch::getCurrentTouchPointList(event, [self shouldSendSingleTouch]); qCDebug(lcQpaTouch) << "touchesMovedWithEvent" << points << "from device" << Qt::hex << [event deviceID]; QWindowSystemInterface::handleTouchEvent( @@ -51,6 +55,10 @@ Q_LOGGING_CATEGORY(lcQpaTouch, "qt.qpa.input.touch") return; const NSTimeInterval timestamp = [event timestamp]; + + QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag(); + nativeDrag->setLastInputEvent(event, self); + const QList points = QCocoaTouch::getCurrentTouchPointList(event, [self shouldSendSingleTouch]); qCDebug(lcQpaTouch) << "touchesEndedWithEvent" << points << "from device" << Qt::hex << [event deviceID]; QWindowSystemInterface::handleTouchEvent( @@ -65,6 +73,10 @@ Q_LOGGING_CATEGORY(lcQpaTouch, "qt.qpa.input.touch") return; const NSTimeInterval timestamp = [event timestamp]; + + QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag(); + nativeDrag->setLastInputEvent(event, self); + const QList points = QCocoaTouch::getCurrentTouchPointList(event, [self shouldSendSingleTouch]); qCDebug(lcQpaTouch) << "touchesCancelledWithEvent" << points << "from device" << Qt::hex << [event deviceID]; QWindowSystemInterface::handleTouchEvent(