summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2012-09-26 15:14:48 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-09-26 19:55:00 +0200
commitce1f994e9bcdea963a81a4bf562a8317cf6e0089 (patch)
treea813d673456eca96462e7f9f59309a49d543d724
parent9362474805fa4d58a9f457c647aa8011b28b84d0 (diff)
Fix QScreen::orientation() not always being updated after changing the update orientation mask
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>
-rw-r--r--src/gui/kernel/qscreen.cpp2
-rw-r--r--tests/auto/gui/kernel/qscreen/tst_qscreen.cpp15
2 files changed, 17 insertions, 0 deletions
diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp
index 0deb5271c5..0c30de498c 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 <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);
}
/*!
diff --git a/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp b/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp
index cc08379251..5567f127c9 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 <tst_qscreen.moc>