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>bb10
parent
f1724e4d8a
commit
3c5d405f34
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 (screen == [UIScreen mainScreen]) {
|
||||
QString deviceIdentifier = deviceModelIdentifier();
|
||||
|
||||
if (deviceIdentifier == QStringLiteral("iPhone2,1") /* iPhone 3GS */
|
||||
|| deviceIdentifier == QStringLiteral("iPod3,1") /* iPod touch 3G */) {
|
||||
m_depth = 18;
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue