From 787b2213085d8bc8fe832033a3e0834f7389fe8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 11 Oct 2024 13:01:51 +0200 Subject: [PATCH] qwsi: Teach handleContextMenuEvent about synchronous delivery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Which also lets it return the acceptance state of the event. At the moment the acceptance state of QContextMenuEvent is a bit of a mess, so the QWSI acceptance state can't be trusted, but this opens up the door to using it at a later point. Task-number: QTBUG-67331 Change-Id: I75b586f90e25122bc9e25880d3787740b025c892 Reviewed-by: Morten Johan Sørvig Reviewed-by: Fabian Kosmale Reviewed-by: Ulf Hermann Reviewed-by: Shawn Rutledge (cherry picked from commit bbc3a7d7ba683c71de4662a1eeac0b7d3dfa6b11) Reviewed-by: Qt Cherry-pick Bot --- src/gui/compat/removed_api.cpp | 11 +++++++++++ src/gui/kernel/qguiapplication.cpp | 1 + src/gui/kernel/qwindowsysteminterface.cpp | 6 +++--- src/gui/kernel/qwindowsysteminterface.h | 7 +++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/gui/compat/removed_api.cpp b/src/gui/compat/removed_api.cpp index c052ce6a250..34e64cd03e6 100644 --- a/src/gui/compat/removed_api.cpp +++ b/src/gui/compat/removed_api.cpp @@ -68,6 +68,17 @@ bool QPageLayout::setBottomMargin(qreal bottomMargin) return setBottomMargin(bottomMargin, OutOfBoundsPolicy::Reject); } +#ifndef QT_NO_CONTEXTMENU +#include +void QWindowSystemInterface::handleContextMenuEvent(QWindow *window, bool mouseTriggered, + const QPoint &pos, const QPoint &globalPos, + Qt::KeyboardModifiers modifiers) +{ + handleContextMenuEvent( + window, mouseTriggered, pos, globalPos, modifiers); +} +#endif // QT_NO_CONTEXTMENU + // #include "qotherheader.h" // // implement removed functions from qotherheader.h // order sections alphabetically diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index e0cee816454..97610802635 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -3072,6 +3072,7 @@ void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePriva QContextMenuEvent ev(QContextMenuEvent::Keyboard, e->pos, e->globalPos, e->modifiers); QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev); + e->eventAccepted = ev.isAccepted(); } #endif diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 1875594300c..7154dac6884 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -1028,12 +1028,12 @@ void QWindowSystemInterface::handlePlatformPanelEvent(QWindow *w) } #ifndef QT_NO_CONTEXTMENU -void QWindowSystemInterface::handleContextMenuEvent(QWindow *window, bool mouseTriggered, +QT_DEFINE_QPA_EVENT_HANDLER(bool, handleContextMenuEvent, QWindow *window, bool mouseTriggered, const QPoint &pos, const QPoint &globalPos, Qt::KeyboardModifiers modifiers) { - handleWindowSystemEvent(window, - mouseTriggered, pos, globalPos, modifiers); + return handleWindowSystemEvent( + window, mouseTriggered, pos, globalPos, modifiers); } #endif diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h index 4fc61a475d2..1fba8ce8231 100644 --- a/src/gui/kernel/qwindowsysteminterface.h +++ b/src/gui/kernel/qwindowsysteminterface.h @@ -248,10 +248,17 @@ public: #endif // QT_NO_GESTURES static void handlePlatformPanelEvent(QWindow *window); + #ifndef QT_NO_CONTEXTMENU +#if QT_GUI_REMOVED_SINCE(6, 8) static void handleContextMenuEvent(QWindow *window, bool mouseTriggered, const QPoint &pos, const QPoint &globalPos, Qt::KeyboardModifiers modifiers); +#endif + template + static bool handleContextMenuEvent(QWindow *window, bool mouseTriggered, + const QPoint &pos, const QPoint &globalPos, + Qt::KeyboardModifiers modifiers); #endif #if QT_CONFIG(whatsthis) static void handleEnterWhatsThisEvent();