Fix QScreen::orientation() not always being updated after changing the update orienta...
authorSimon Hausmann <simon.hausmann@digia.com>
Wed, 26 Sep 2012 13:14:48 +0000 (15:14 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 26 Sep 2012 17:55:00 +0000 (19:55 +0200)
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 <samuel.rodal@digia.com>
Reviewed-by: Laszlo Papp <lpapp@kde.org>
src/gui/kernel/qscreen.cpp
tests/auto/gui/kernel/qscreen/tst_qscreen.cpp

index 0deb527..0c30de4 100644 (file)
@@ -42,6 +42,7 @@
 #include "qscreen.h"
 #include "qscreen_p.h"
 #include "qpixmap.h"
+#include "qguiapplication_p.h"
 #include <qpa/qplatformscreen.h>
 
 #include <QtCore/private/qobject_p.h>
@@ -367,6 +368,7 @@ void QScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask)
     Q_D(QScreen);
     d->orientationUpdateMask = mask;
     d->platformScreen->setOrientationUpdateMask(mask);
+    QGuiApplicationPrivate::updateFilteredScreenOrientation(this);
 }
 
 /*!
index cc08379..5567f12 100644 (file)
@@ -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 <tst_qscreen.moc>