diff options
author | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2014-07-03 19:14:06 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2014-07-21 15:27:50 +0200 |
commit | 3c5d405f34141b6200d1a3d7a614f856e8ba9142 (patch) | |
tree | effdac13320b7b8e95dd411dc51c2f5079ed360f /src/plugins/platforms/ios/qiosscreen.mm | |
parent | f1724e4d8ac363f903e189d466d7138e07db78d9 (diff) |
iOS: Detect external screen connections and expose as additional QScreen
The additional QScreen can not be used for anything yet, since we don't
set up a window and root view controller for it.
Change-Id: I335b796bdd89fc58a27ec4e20c5ed355be0cab66
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Diffstat (limited to 'src/plugins/platforms/ios/qiosscreen.mm')
-rw-r--r-- | src/plugins/platforms/ios/qiosscreen.mm | 96 |
1 files changed, 80 insertions, 16 deletions
diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index 5331d05ae9..a53e42ce50 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qiosglobal.h" +#include "qiosintegration.h" #include "qiosscreen.h" #include "qioswindow.h" #include <qpa/qwindowsysteminterface.h> @@ -48,6 +49,63 @@ #include <sys/sysctl.h> +// ------------------------------------------------------------------------- + +static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen) +{ + foreach (QScreen *screen, QGuiApplication::screens()) { + QIOSScreen *platformScreen = static_cast<QIOSScreen *>(screen->handle()); + if (platformScreen->uiScreen() == uiScreen) + return platformScreen; + } + + return 0; +} + +@interface QIOSScreenTracker : NSObject +@end + +@implementation QIOSScreenTracker + ++ (void)load +{ + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + [center addObserver:self selector:@selector(screenConnected:) + name:UIScreenDidConnectNotification object:nil]; + [center addObserver:self selector:@selector(screenDisconnected:) + name:UIScreenDidDisconnectNotification object:nil]; + [center addObserver:self selector:@selector(screenModeChanged:) + name:UIScreenModeDidChangeNotification object:nil]; +} + ++ (void)screenConnected:(NSNotification*)notification +{ + QIOSIntegration *integration = QIOSIntegration::instance(); + Q_ASSERT_X(integration, Q_FUNC_INFO, "Screen connected before QIOSIntegration creation"); + + integration->addScreen(new QIOSScreen([notification object])); +} + ++ (void)screenDisconnected:(NSNotification*)notification +{ + QIOSScreen *screen = qtPlatformScreenFor([notification object]); + Q_ASSERT_X(screen, Q_FUNC_INFO, "Screen disconnected that we didn't know about"); + + delete screen; +} + ++ (void)screenModeChanged:(NSNotification*)notification +{ + QIOSScreen *screen = qtPlatformScreenFor([notification object]); + Q_ASSERT_X(screen, Q_FUNC_INFO, "Screen changed that we didn't know about"); + + screen->updateProperties(); +} + +@end + +// ------------------------------------------------------------------------- + @interface QIOSOrientationListener : NSObject { @public QIOSScreen *m_screen; @@ -99,6 +157,8 @@ @end +// ------------------------------------------------------------------------- + /*! Returns the model identifier of the device. @@ -118,27 +178,31 @@ static QString deviceModelIdentifier() return QString::fromLatin1(value); } -QIOSScreen::QIOSScreen(unsigned int screenIndex) +QIOSScreen::QIOSScreen(UIScreen *screen) : QPlatformScreen() - , m_uiScreen([[UIScreen screens] count] > screenIndex - ? [[UIScreen screens] objectAtIndex:screenIndex] - : [UIScreen mainScreen]) + , m_uiScreen(screen) , m_orientationListener(0) { - QString deviceIdentifier = deviceModelIdentifier(); - - if (deviceIdentifier == QStringLiteral("iPhone2,1") /* iPhone 3GS */ - || deviceIdentifier == QStringLiteral("iPod3,1") /* iPod touch 3G */) { - m_depth = 18; + if (screen == [UIScreen mainScreen]) { + QString deviceIdentifier = deviceModelIdentifier(); + + if (deviceIdentifier == QStringLiteral("iPhone2,1") /* iPhone 3GS */ + || deviceIdentifier == QStringLiteral("iPod3,1") /* iPod touch 3G */) { + m_depth = 18; + } else { + m_depth = 24; + } + + if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad + && !deviceIdentifier.contains(QRegularExpression("^iPad2,[567]$")) /* excluding iPad Mini */) { + m_unscaledDpi = 132; + } else { + m_unscaledDpi = 163; // Regular iPhone DPI + } } else { + // External display, hard to say m_depth = 24; - } - - if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad - && !deviceIdentifier.contains(QRegularExpression("^iPad2,[567]$")) /* excluding iPad Mini */) { - m_unscaledDpi = 132; - } else { - m_unscaledDpi = 163; // Regular iPhone DPI + m_unscaledDpi = 96; } connect(qGuiApp, &QGuiApplication::focusWindowChanged, this, &QIOSScreen::updateStatusBarVisibility); |