From be6c50a2511fc95b165b702cae1f54a9e06fa67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 15 Jan 2015 17:19:07 +0100 Subject: iOS: Make screen orientation reporting more consistent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ic21efb939639711c4071161e3c742525a55d41be Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiosglobal.mm | 2 +- src/plugins/platforms/ios/qiosscreen.mm | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/plugins/platforms/ios/qiosglobal.mm b/src/plugins/platforms/ios/qiosglobal.mm index 3ecd0ca61f..be55a9e027 100644 --- a/src/plugins/platforms/ios/qiosglobal.mm +++ b/src/plugins/platforms/ios/qiosglobal.mm @@ -95,7 +95,7 @@ Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientat break; case UIDeviceOrientationFaceUp: case UIDeviceOrientationFaceDown: - // FIXME: Use cached device orientation, or fall back to interface orientation + qWarning() << "Falling back to Qt::PortraitOrientation for UIDeviceOrientationFaceUp/UIDeviceOrientationFaceDown"; qtOrientation = Qt::PortraitOrientation; break; default: diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index 0713a95522..e9b2c546d4 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -143,17 +143,7 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen) - (void) orientationChanged:(NSNotification *)notification { Q_UNUSED(notification); - - UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; - switch (deviceOrientation) { - case UIDeviceOrientationFaceUp: - case UIDeviceOrientationFaceDown: - // We ignore these events, as iOS will send events with the 'regular' - // orientations alongside these two orientations. - return; - default: - QWindowSystemInterface::handleScreenOrientationChange(m_screen->screen(), m_screen->orientation()); - } + m_screen->updateProperties(); } @end @@ -261,6 +251,14 @@ void QIOSScreen::updateProperties() m_availableGeometry = transform.mapRect(m_availableGeometry); } + if (screen() && screen()->orientation() != orientation()) + QWindowSystemInterface::handleScreenOrientationChange(screen(), orientation()); + + // Note: The screen orientation change and the geometry changes are not atomic, so when + // the former is emitted, the latter has not been reported and reflected in the QScreen + // API yet. But conceptually it makes sense that the orientation update happens first, + // and the geometry updates caused by auto-rotation happen after that. + if (m_geometry != previousGeometry || m_availableGeometry != previousAvailableGeometry) { const qreal millimetersPerInch = 25.4; m_physicalSize = QSizeF(m_geometry.size()) / m_unscaledDpi * millimetersPerInch; @@ -331,6 +329,14 @@ Qt::ScreenOrientation QIOSScreen::orientation() const if (deviceOrientation == UIDeviceOrientationUnknown) deviceOrientation = UIDeviceOrientation([UIApplication sharedApplication].statusBarOrientation); + // If the device reports face up or face down orientations, we can't map + // them to Qt orientations, so we pretend we're in the same orientation + // as before. + if (deviceOrientation == UIDeviceOrientationFaceUp || deviceOrientation == UIDeviceOrientationFaceDown) { + Q_ASSERT(screen()); + return screen()->orientation(); + } + return toQtScreenOrientation(deviceOrientation); } @@ -341,6 +347,7 @@ void QIOSScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask) m_orientationListener = 0; } else if (!m_orientationListener) { m_orientationListener = [[QIOSOrientationListener alloc] initWithQIOSScreen:this]; + updateProperties(); } } -- cgit v1.2.3