From a0871ad225bc0a7ceed67fa2eb5ed16e475ebd93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 27 Nov 2017 11:40:12 +0100 Subject: iOS: Deliver all QWindowSystemInterface events synchronously On iOS we want all delivery of events from the system to be handled synchronously, as that's what the system expects. We don't need to add a delivery template argument to each function in QWindowSystemInterface that we want to delivery synchronously; that's only needed for functions that a platform normally sends asynch, but in some cases want to delivery synchronously. For always delivering events synchronously we just need to change the default delivery method. The only events affected by this are the screen changes, and window state change, which were not synchronous before, but should be. All other events were already synchronous, though either explicit delivery, of a flush. Change-Id: Ib20ca342d1c076be0fbcf018c83735a416769cfe Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/ios/qiosapplicationstate.mm | 2 +- src/plugins/platforms/ios/qioseventdispatcher.mm | 2 ++ src/plugins/platforms/ios/qiostextresponder.mm | 1 - src/plugins/platforms/ios/quiview.mm | 14 +++++++------- 4 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src/plugins/platforms/ios') diff --git a/src/plugins/platforms/ios/qiosapplicationstate.mm b/src/plugins/platforms/ios/qiosapplicationstate.mm index 13e7e1150f..7c8e1f9927 100644 --- a/src/plugins/platforms/ios/qiosapplicationstate.mm +++ b/src/plugins/platforms/ios/qiosapplicationstate.mm @@ -75,7 +75,7 @@ static void handleApplicationStateChanged(UIApplicationState uiApplicationState) { Qt::ApplicationState state = qtApplicationState(uiApplicationState); qCDebug(lcQpaApplication) << "moved to" << state; - QWindowSystemInterface::handleApplicationStateChanged(state); + QWindowSystemInterface::handleApplicationStateChanged(state); } QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/ios/qioseventdispatcher.mm b/src/plugins/platforms/ios/qioseventdispatcher.mm index f49f81912e..429b7d9591 100644 --- a/src/plugins/platforms/ios/qioseventdispatcher.mm +++ b/src/plugins/platforms/ios/qioseventdispatcher.mm @@ -422,6 +422,8 @@ QIOSEventDispatcher::QIOSEventDispatcher(QObject *parent) , m_processEventLevel(0) , m_runLoopExitObserver(this, &QIOSEventDispatcher::handleRunLoopExit, kCFRunLoopExit) { + // We want all delivery of events from the system to be handled synchronously + QWindowSystemInterface::setSynchronousWindowSystemEvents(true); } bool __attribute__((returns_twice)) QIOSEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm index 001985a128..33a0b6a42e 100644 --- a/src/plugins/platforms/ios/qiostextresponder.mm +++ b/src/plugins/platforms/ios/qiostextresponder.mm @@ -377,7 +377,6 @@ QScopedValueRollback rollback(m_inSendEventToFocusObject, true); QWindowSystemInterface::handleKeyEvent(qApp->focusWindow(), QEvent::KeyPress, key, modifiers); QWindowSystemInterface::handleKeyEvent(qApp->focusWindow(), QEvent::KeyRelease, key, modifiers); - QWindowSystemInterface::flushWindowSystemEvents(); } #ifndef QT_NO_SHORTCUT diff --git a/src/plugins/platforms/ios/quiview.mm b/src/plugins/platforms/ios/quiview.mm index bf26feac9f..a405fecee2 100644 --- a/src/plugins/platforms/ios/quiview.mm +++ b/src/plugins/platforms/ios/quiview.mm @@ -166,7 +166,7 @@ QWindow *window = m_qioswindow->window(); qCDebug(lcQpaWindow) << m_qioswindow->window() << "new geometry is" << actualGeometry; - QWindowSystemInterface::handleGeometryChange(window, actualGeometry, previousGeometry); + QWindowSystemInterface::handleGeometryChange(window, actualGeometry, previousGeometry); if (actualGeometry.size() != previousGeometry.size()) { // Trigger expose event on resize @@ -199,7 +199,7 @@ } qCDebug(lcQpaWindow) << m_qioswindow->window() << region << "isExposed" << m_qioswindow->isExposed(); - QWindowSystemInterface::handleExposeEvent(m_qioswindow->window(), region); + QWindowSystemInterface::handleExposeEvent(m_qioswindow->window(), region); } // ------------------------------------------------------------------------- @@ -230,7 +230,7 @@ } if (qGuiApp->focusWindow() != m_qioswindow->window()) - QWindowSystemInterface::handleWindowActivated(m_qioswindow->window()); + QWindowSystemInterface::handleWindowActivated(m_qioswindow->window()); else qImDebug() << m_qioswindow->window() << "already active, not sending window activation"; @@ -268,7 +268,7 @@ UIResponder *newResponder = FirstResponderCandidate::currentCandidate(); if ([self responderShouldTriggerWindowDeactivation:newResponder]) - QWindowSystemInterface::handleWindowActivated(0); + QWindowSystemInterface::handleWindowActivated(0); return YES; } @@ -359,7 +359,7 @@ - (void)sendTouchEventWithTimestamp:(ulong)timeStamp { QIOSIntegration *iosIntegration = QIOSIntegration::instance(); - QWindowSystemInterface::handleTouchEvent(m_qioswindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values()); + QWindowSystemInterface::handleTouchEvent(m_qioswindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values()); } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event @@ -438,7 +438,7 @@ NSTimeInterval timestamp = event ? event.timestamp : [[NSProcessInfo processInfo] systemUptime]; QIOSIntegration *iosIntegration = static_cast(QGuiApplicationPrivate::platformIntegration()); - QWindowSystemInterface::handleTouchCancelEvent(m_qioswindow->window(), ulong(timestamp * 1000), iosIntegration->touchDevice()); + QWindowSystemInterface::handleTouchCancelEvent(m_qioswindow->window(), ulong(timestamp * 1000), iosIntegration->touchDevice()); } - (int)mapPressTypeToKey:(UIPress*)press @@ -466,7 +466,7 @@ int key = [self mapPressTypeToKey:press]; if (key == Qt::Key_unknown) continue; - if (QWindowSystemInterface::handleKeyEvent(m_qioswindow->window(), type, key, Qt::NoModifier)) + if (QWindowSystemInterface::handleKeyEvent(m_qioswindow->window(), type, key, Qt::NoModifier)) handled = true; } -- cgit v1.2.3 From 81908abd5e62d3ee3e24c37801892ef500de2fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 28 Nov 2017 19:28:36 +0100 Subject: iOS: Update screen metrics (physical DPI) for the latest set of devices We were missing some recent iPads, and the iPhone 8 Plus and X. Change-Id: Ib65644a277a1cbd75ccb360b79b9ac8af935c741 Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/ios/qiosscreen.mm | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src/plugins/platforms/ios') diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index 3514bf63bb..deea4d86a0 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -181,12 +181,12 @@ QT_BEGIN_NAMESPACE /*! Returns the model identifier of the device. - - When running under the simulator, the identifier will not - match the simulated device, but will be x86_64 or i386. */ static QString deviceModelIdentifier() { +#if TARGET_OS_SIMULATOR + return QString::fromLocal8Bit(qgetenv("SIMULATOR_MODEL_IDENTIFIER")); +#else static const char key[] = "hw.machine"; size_t size; @@ -196,6 +196,7 @@ static QString deviceModelIdentifier() sysctlbyname(key, &value, &size, NULL, 0); return QString::fromLatin1(value); +#endif } QIOSScreen::QIOSScreen(UIScreen *screen) @@ -210,19 +211,24 @@ QIOSScreen::QIOSScreen(UIScreen *screen) // Based on https://en.wikipedia.org/wiki/List_of_iOS_devices#Display // iPhone (1st gen), 3G, 3GS, and iPod Touch (1st–3rd gen) are 18-bit devices - if (deviceIdentifier.contains(QRegularExpression("^(iPhone1,[12]|iPhone2,1|iPod[1-3],1)$"))) - m_depth = 18; - else - m_depth = 24; + static QRegularExpression lowBitDepthDevices("^(iPhone1,[12]|iPhone2,1|iPod[1-3],1)$"); + m_depth = deviceIdentifier.contains(lowBitDepthDevices) ? 18 : 24; + + static QRegularExpression iPhoneXModels("^iPhone(10,[36])$"); + static QRegularExpression iPhonePlusModels("^iPhone(7,1|8,2|9,[24]|10,[25])$"); + static QRegularExpression iPadMiniModels("^iPad(2,[567]|4,[4-9]|5,[12])$"); - if (deviceIdentifier.contains(QRegularExpression("^iPhone(7,1|8,2|9,2|9,4)$"))) { - // iPhone Plus models + if (deviceIdentifier.contains(iPhoneXModels)) { + m_physicalDpi = 458; + } else if (deviceIdentifier.contains(iPhonePlusModels)) { m_physicalDpi = 401; - } else if (deviceIdentifier.contains(QRegularExpression("^iPad(1,1|2,[1-4]|3,[1-6]|4,[1-3]|5,[3-4]|6,[7-8])$"))) { - // All iPads except the iPad Mini series - m_physicalDpi = 132 * devicePixelRatio(); + } else if (deviceIdentifier.startsWith("iPad")) { + if (deviceIdentifier.contains(iPadMiniModels)) + m_physicalDpi = 163 * devicePixelRatio(); + else + m_physicalDpi = 132 * devicePixelRatio(); } else { - // All non-Plus iPhones, and iPad Minis + // All normal iPhones, and iPods m_physicalDpi = 163 * devicePixelRatio(); } } else { -- cgit v1.2.3 From 038e473cfac43f80bd8d54bb6c6da5bf6391efa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 28 Nov 2017 19:38:31 +0100 Subject: iOS: Don't treat AppleTV as an iDevice when resolving physical DPI Change-Id: I07ac92a7b2d8c65b7d70a4f2ed5f96f8f4d99ef0 Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/ios/qiosscreen.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms/ios') diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index deea4d86a0..74e81dedf4 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -205,9 +205,9 @@ QIOSScreen::QIOSScreen(UIScreen *screen) , m_uiWindow(0) , m_orientationListener(0) { - if (screen == [UIScreen mainScreen]) { - QString deviceIdentifier = deviceModelIdentifier(); + QString deviceIdentifier = deviceModelIdentifier(); + if (screen == [UIScreen mainScreen] && !deviceIdentifier.startsWith("AppleTV")) { // Based on https://en.wikipedia.org/wiki/List_of_iOS_devices#Display // iPhone (1st gen), 3G, 3GS, and iPod Touch (1st–3rd gen) are 18-bit devices -- cgit v1.2.3 From 85eef0e5e05e84b1640a1887fe872e3adbc0ac5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 29 Nov 2017 16:12:40 +0100 Subject: iOS: Improve logging during application startup Change-Id: I15c1980d7c532c94b34e612bb781c8ed5bf096a0 Reviewed-by: Jake Petroules --- src/plugins/platforms/ios/qioseventdispatcher.mm | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/plugins/platforms/ios') diff --git a/src/plugins/platforms/ios/qioseventdispatcher.mm b/src/plugins/platforms/ios/qioseventdispatcher.mm index 429b7d9591..7194d5bed1 100644 --- a/src/plugins/platforms/ios/qioseventdispatcher.mm +++ b/src/plugins/platforms/ios/qioseventdispatcher.mm @@ -294,7 +294,7 @@ static bool rootLevelRunLoopIntegration() { [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(applicationDidFinishLaunching) + selector:@selector(applicationDidFinishLaunching:) name:UIApplicationDidFinishLaunchingNotification object:nil]; @@ -320,8 +320,10 @@ static bool rootLevelRunLoopIntegration() # error "Unknown processor family" #endif -+ (void)applicationDidFinishLaunching ++ (void)applicationDidFinishLaunching:(NSNotification *)notification { + qCDebug(lcQpaApplication) << "Application launched with options" << notification.userInfo; + if (!isQtApplication()) return; @@ -329,7 +331,7 @@ static bool rootLevelRunLoopIntegration() // We schedule the main-redirection for the next run-loop pass, so that we // can return from this function and let UIApplicationMain finish its job. // This results in running Qt's application eventloop as a nested runloop. - qEventDispatcherDebug() << "Scheduling main() on next run-loop pass"; + qCDebug(lcQpaApplication) << "Scheduling main() on next run-loop pass"; CFRunLoopTimerRef userMainTimer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent(), 0, 0, 0, ^(CFRunLoopTimerRef) { user_main_trampoline(); }); CFRunLoopAddTimer(CFRunLoopGetMain(), userMainTimer, kCFRunLoopCommonModes); @@ -339,7 +341,7 @@ static bool rootLevelRunLoopIntegration() switch (setjmp(processEventEnterJumpPoint)) { case kJumpPointSetSuccessfully: - qEventDispatcherDebug() << "Running main() on separate stack"; qIndent(); + qCDebug(lcQpaApplication) << "Running main() on separate stack"; qIndent(); // Redirect the stack pointer to the start of the reserved stack. This ensures // that when we longjmp out of the event dispatcher and continue execution, the @@ -358,7 +360,7 @@ static bool rootLevelRunLoopIntegration() case kJumpedFromEventDispatcherProcessEvents: // We've returned from the longjmp in the event dispatcher, // and the stack has been restored to its old self. - qUnIndent(); qEventDispatcherDebug() << "Returned from processEvents"; + qUnIndent(); qCDebug(lcQpaApplication) << "Returned from processEvents"; if (Q_UNLIKELY(debugStackUsage)) userMainStack.printUsage(); -- cgit v1.2.3