From ce1f994e9bcdea963a81a4bf562a8317cf6e0089 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 26 Sep 2012 15:14:48 +0200 Subject: [PATCH] Fix QScreen::orientation() not always being updated after changing the update orientation mask MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The back-end might report screen orientation changes at any point and we record it in screen.d->orientation. However QScreen::orientation() returns the orientation filtered according to the mask. Changing the mask sends a notification to the back-end, which might send another update as a result of a possible subscription to system services (accelerometer). However on platforms where no subscription is required, where the platform plugin ignores the mask and always sends the latest orientation, we should "simulate" the update by updating the filtered orientation according to the new mask. The function is cheap to call as it won't emit any signals unless the orientation actually changes. This patch also adds missing flush() calls after handleScreenOrientationChange calls in the tests to ensure that the (synthetic) window system events are actually delivered to QScreen/QGuiApplication. Change-Id: Iebdd050f947e658ff5bc388629aa4cb31ab497fe Reviewed-by: Samuel Rødal Reviewed-by: Laszlo Papp --- src/gui/kernel/qscreen.cpp | 2 ++ tests/auto/gui/kernel/qscreen/tst_qscreen.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp index 0deb527..0c30de4 100644 --- a/src/gui/kernel/qscreen.cpp +++ b/src/gui/kernel/qscreen.cpp @@ -42,6 +42,7 @@ #include "qscreen.h" #include "qscreen_p.h" #include "qpixmap.h" +#include "qguiapplication_p.h" #include #include @@ -367,6 +368,7 @@ void QScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask) Q_D(QScreen); d->orientationUpdateMask = mask; d->platformScreen->setOrientationUpdateMask(mask); + QGuiApplicationPrivate::updateFilteredScreenOrientation(this); } /*! diff --git a/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp b/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp index cc08379..5567f12 100644 --- a/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp +++ b/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp @@ -185,19 +185,34 @@ void tst_QScreen::orientationChange() screen->setOrientationUpdateMask(Qt::LandscapeOrientation | Qt::PortraitOrientation); QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation); + QWindowSystemInterface::flushWindowSystemEvents(); QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation); QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::PortraitOrientation); + QWindowSystemInterface::flushWindowSystemEvents(); QTRY_COMPARE(screen->orientation(), Qt::PortraitOrientation); QSignalSpy spy(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation))); QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedLandscapeOrientation); + QWindowSystemInterface::flushWindowSystemEvents(); QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedPortraitOrientation); + QWindowSystemInterface::flushWindowSystemEvents(); QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation); + QWindowSystemInterface::flushWindowSystemEvents(); QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation); QCOMPARE(spy.count(), 1); + + spy.clear(); + QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedLandscapeOrientation); + QWindowSystemInterface::flushWindowSystemEvents(); + QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation); + QCOMPARE(spy.count(), 0); + + screen->setOrientationUpdateMask(screen->orientationUpdateMask() | Qt::InvertedLandscapeOrientation); + QTRY_COMPARE(screen->orientation(), Qt::InvertedLandscapeOrientation); + QCOMPARE(spy.count(), 1); } #include -- 2.7.4