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 | |
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')
-rw-r--r-- | src/plugins/platforms/ios/qiosintegration.h | 3 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qiosintegration.mm | 8 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qiosscreen.h | 4 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qiosscreen.mm | 96 |
4 files changed, 87 insertions, 24 deletions
diff --git a/src/plugins/platforms/ios/qiosintegration.h b/src/plugins/platforms/ios/qiosintegration.h index d0183af99d..89ca0349d9 100644 --- a/src/plugins/platforms/ios/qiosintegration.h +++ b/src/plugins/platforms/ios/qiosintegration.h @@ -84,13 +84,14 @@ public: QTouchDevice *touchDevice(); QPlatformAccessibility *accessibility() const Q_DECL_OVERRIDE; + void addScreen(QPlatformScreen *screen) { screenAdded(screen); } + static QIOSIntegration *instance(); private: QPlatformFontDatabase *m_fontDatabase; QPlatformClipboard *m_clipboard; QPlatformInputContext *m_inputContext; - QPlatformScreen *m_screen; QTouchDevice *m_touchDevice; QIOSApplicationState m_applicationState; QIOSServices *m_platformServices; diff --git a/src/plugins/platforms/ios/qiosintegration.mm b/src/plugins/platforms/ios/qiosintegration.mm index c788756640..5ed37c3525 100644 --- a/src/plugins/platforms/ios/qiosintegration.mm +++ b/src/plugins/platforms/ios/qiosintegration.mm @@ -73,7 +73,6 @@ QIOSIntegration::QIOSIntegration() : m_fontDatabase(new QCoreTextFontDatabase) , m_clipboard(new QIOSClipboard) , m_inputContext(new QIOSInputContext) - , m_screen(new QIOSScreen(QIOSScreen::MainScreen)) , m_platformServices(new QIOSServices) , m_accessibility(0) { @@ -89,7 +88,8 @@ QIOSIntegration::QIOSIntegration() // Set current directory to app bundle folder QDir::setCurrent(QString::fromUtf8([[[NSBundle mainBundle] bundlePath] UTF8String])); - screenAdded(m_screen); + for (UIScreen *screen in [UIScreen screens]) + addScreen(new QIOSScreen(screen)); m_touchDevice = new QTouchDevice; m_touchDevice->setType(QTouchDevice::TouchScreen); @@ -110,8 +110,8 @@ QIOSIntegration::~QIOSIntegration() delete m_inputContext; m_inputContext = 0; - delete m_screen; - m_screen = 0; + foreach (QScreen *screen, QGuiApplication::screens()) + delete screen->handle(); delete m_platformServices; m_platformServices = 0; diff --git a/src/plugins/platforms/ios/qiosscreen.h b/src/plugins/platforms/ios/qiosscreen.h index 173bd11719..a6ef7a2593 100644 --- a/src/plugins/platforms/ios/qiosscreen.h +++ b/src/plugins/platforms/ios/qiosscreen.h @@ -55,11 +55,9 @@ class QIOSScreen : public QObject, public QPlatformScreen Q_OBJECT public: - QIOSScreen(unsigned int screenIndex); + QIOSScreen(UIScreen *screen); ~QIOSScreen(); - enum ScreenIndex { MainScreen = 0 }; - QRect geometry() const; QRect availableGeometry() const; int depth() const; 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); |