From a3d59c7c7f675b0a4e128efeb781aa1c2f7db4c0 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 15 Aug 2017 10:29:16 +0200 Subject: [PATCH] Block input to a window shown while an application modal dialog is visible Although the window is refused input for the most part from the system, it does not act like that it is blocked by the application modal dialog. This ensures that it is the case and prevents things like being able to double click on the title bar to maximize the window on Windows. Task-number: QTBUG-49102 Change-Id: If1582819b90cb2ec9d891f664da24f13bfec7103 Reviewed-by: Paul Olav Tvete --- src/gui/kernel/qwindow.cpp | 2 + tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index cf4a75dfce6..eb9d7a88685 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -576,6 +576,8 @@ void QWindow::setVisible(bool visible) QGuiApplicationPrivate::showModalWindow(this); else QGuiApplicationPrivate::hideModalWindow(this); + } else if (visible && QGuiApplication::modalWindow()) { + QGuiApplicationPrivate::updateBlockedStatus(this); } #ifndef QT_NO_CURSOR diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 92f71822492..e1366ce2eb0 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -105,6 +105,7 @@ private slots: void stateChange(); void flags(); void cleanup(); + void testBlockingWindowShownAfterModalDialog(); private: QPoint m_availableTopLeft; @@ -2241,6 +2242,47 @@ void tst_QWindow::flags() QCOMPARE(window.flags(), baseFlags | Qt::WindowStaysOnTopHint); } +class EventWindow : public QWindow +{ +public: + EventWindow() : QWindow(), gotBlocked(false) {} + bool gotBlocked; +protected: + bool event(QEvent *e) + { + if (e->type() == QEvent::WindowBlocked) + gotBlocked = true; + return QWindow::event(e); + } +}; + +void tst_QWindow::testBlockingWindowShownAfterModalDialog() +{ + EventWindow normalWindow; + normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80)); + normalWindow.resize(m_testWindowSize); + normalWindow.show(); + QVERIFY(QTest::qWaitForWindowExposed(&normalWindow)); + QVERIFY(!normalWindow.gotBlocked); + + QWindow dialog; + dialog.setFramePosition(m_availableTopLeft + QPoint(200, 200)); + dialog.resize(m_testWindowSize); + dialog.setModality(Qt::ApplicationModal); + dialog.setFlags(Qt::Dialog); + dialog.show(); + QVERIFY(QTest::qWaitForWindowExposed(&dialog)); + QVERIFY(normalWindow.gotBlocked); + + EventWindow normalWindowAfter; + normalWindowAfter.setFramePosition(m_availableTopLeft + QPoint(80, 80)); + normalWindowAfter.resize(m_testWindowSize); + QVERIFY(!normalWindowAfter.gotBlocked); + normalWindowAfter.show(); + QVERIFY(QTest::qWaitForWindowExposed(&normalWindowAfter)); + QVERIFY(normalWindowAfter.gotBlocked); +} + #include QTEST_MAIN(tst_QWindow)