From bb65ac80977c277b6cba1abee423ccfd5f1b1f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 4 Oct 2019 13:59:06 +0200 Subject: Modernize QWindowSystemInterface::handleCloseEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The base WindowSystemEvent has had an eventAccepted flag since 2014. Change-Id: Ia0aa795083cd98ece83a4c1cc010d3a25e2489fd Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qguiapplication.cpp | 5 ++--- src/gui/kernel/qplatformwindow.cpp | 4 +--- src/gui/kernel/qwindowsysteminterface.cpp | 10 ++++------ src/gui/kernel/qwindowsysteminterface.h | 2 +- src/gui/kernel/qwindowsysteminterface_p.h | 5 ++--- src/plugins/platforms/cocoa/qcocoawindow.mm | 13 +++++-------- 6 files changed, 15 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index fe73278c62..13de8af8b5 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2527,9 +2527,8 @@ void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::Cl QCloseEvent event; QGuiApplication::sendSpontaneousEvent(e->window.data(), &event); - if (e->accepted) { - *(e->accepted) = event.isAccepted(); - } + + e->eventAccepted = event.isAccepted(); } void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e) diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index 4e95751397..2a0cb1094c 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -348,9 +348,7 @@ void QPlatformWindow::setWindowIcon(const QIcon &icon) { Q_UNUSED(icon); } */ bool QPlatformWindow::close() { - bool accepted = false; - QWindowSystemInterface::handleCloseEvent(window(), &accepted); - return accepted; + return QWindowSystemInterface::handleCloseEvent(window()); } /*! diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 40a298226a..03be72ca30 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -340,13 +340,11 @@ QT_DEFINE_QPA_EVENT_HANDLER(void, handleExposeEvent, QWindow *window, const QReg QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } -QT_DEFINE_QPA_EVENT_HANDLER(void, handleCloseEvent, QWindow *window, bool *accepted) +QT_DEFINE_QPA_EVENT_HANDLER(bool, handleCloseEvent, QWindow *window) { - if (window) { - QWindowSystemInterfacePrivate::CloseEvent *e = - new QWindowSystemInterfacePrivate::CloseEvent(window, accepted); - QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); - } + Q_ASSERT(window); + auto *event = new QWindowSystemInterfacePrivate::CloseEvent(window); + return QWindowSystemInterfacePrivate::handleWindowSystemEvent(event); } /*! diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h index fd70eda9ff..4a0bc858a9 100644 --- a/src/gui/kernel/qwindowsysteminterface.h +++ b/src/gui/kernel/qwindowsysteminterface.h @@ -194,7 +194,7 @@ public: static void handleExposeEvent(QWindow *window, const QRegion ®ion); template - static void handleCloseEvent(QWindow *window, bool *accepted = nullptr); + static bool handleCloseEvent(QWindow *window); template static void handleEnterEvent(QWindow *window, const QPointF &local = QPointF(), const QPointF& global = QPointF()); diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index d6513f1836..540170f733 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -123,11 +123,10 @@ public: class CloseEvent : public WindowSystemEvent { public: - explicit CloseEvent(QWindow *w, bool *a = nullptr) - : WindowSystemEvent(Close), window(w), accepted(a) + explicit CloseEvent(QWindow *w) + : WindowSystemEvent(Close), window(w) { } QPointer window; - bool *accepted; }; class GeometryChangeEvent : public WindowSystemEvent { diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 35b7162346..a744a86695 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1275,14 +1275,11 @@ void QCocoaWindow::windowWillClose() bool QCocoaWindow::windowShouldClose() { qCDebug(lcQpaWindow) << "QCocoaWindow::windowShouldClose" << window(); - // This callback should technically only determine if the window - // should (be allowed to) close, but since our QPA API to determine - // that also involves actually closing the window we do both at the - // same time, instead of doing the latter in windowWillClose. - bool accepted = false; - QWindowSystemInterface::handleCloseEvent(window(), &accepted); - QWindowSystemInterface::flushWindowSystemEvents(); - return accepted; + // This callback should technically only determine if the window + // should (be allowed to) close, but since our QPA API to determine + // that also involves actually closing the window we do both at the + // same time, instead of doing the latter in windowWillClose. + return QWindowSystemInterface::handleCloseEvent(window()); } // ----------------------------- QPA forwarding ----------------------------- -- cgit v1.2.3