12#include <QtCore/private/qcore_mac_p.h>
16Q_LOGGING_CATEGORY(lcQpaApplication,
"qt.qpa.application");
29 return QIOSEventDispatcher::isQtApplication();
34 static bool result = []{
36 return NSClassFromString(@
"UIWindowSceneGeometryPreferencesVision");
44 Qt::ScreenOrientation qtOrientation;
45 switch (uiDeviceOrientation) {
46 case UIDeviceOrientationPortraitUpsideDown:
47 qtOrientation = Qt::InvertedPortraitOrientation;
49 case UIDeviceOrientationLandscapeLeft:
50 qtOrientation = Qt::LandscapeOrientation;
52 case UIDeviceOrientationLandscapeRight:
53 qtOrientation = Qt::InvertedLandscapeOrientation;
55 case UIDeviceOrientationFaceUp:
56 case UIDeviceOrientationFaceDown:
57 qWarning(
"Falling back to Qt::PortraitOrientation for UIDeviceOrientationFaceUp/UIDeviceOrientationFaceDown");
58 qtOrientation = Qt::PortraitOrientation;
61 qtOrientation = Qt::PortraitOrientation;
69 UIDeviceOrientation uiOrientation;
70 switch (qtOrientation) {
71 case Qt::LandscapeOrientation:
72 uiOrientation = UIDeviceOrientationLandscapeLeft;
74 case Qt::InvertedLandscapeOrientation:
75 uiOrientation = UIDeviceOrientationLandscapeRight;
77 case Qt::InvertedPortraitOrientation:
78 uiOrientation = UIDeviceOrientationPortraitUpsideDown;
80 case Qt::PrimaryOrientation:
81 case Qt::PortraitOrientation:
83 uiOrientation = UIDeviceOrientationPortrait;
92 static NSBundle *bundle = [NSBundle mainBundle];
93 NSNumber* value = [bundle objectForInfoDictionaryKey:key];
94 return value ? [value intValue] : defaultValue;
99 UIWindow *uiWindow = window ?
reinterpret_cast<UIView *>(window->winId()).window :
nullptr;
101 auto *scenes = [qt_apple_sharedApplication().connectedScenes allObjects];
102 if (scenes.count > 0) {
103 auto *windowScene =
static_cast<UIWindowScene*>(scenes[0]);
104 uiWindow = windowScene.keyWindow;
105 if (!uiWindow && windowScene.windows.count)
106 uiWindow = windowScene.windows[0];
116 const auto *iosScreen =
static_cast<
const QIOSScreen *>(screen);
117 for (UIScene *scene in [qt_apple_sharedApplication().connectedScenes allObjects]) {
118 if (![scene isKindOfClass:UIWindowScene.
class])
121 auto *windowScene =
static_cast<UIWindowScene*>(scene);
123#if !defined(Q_OS_VISIONOS)
124 if (windowScene.screen != iosScreen->uiScreen())
130 UIWindow *uiWindow = qt_objc_cast<QUIWindow*>(windowScene.keyWindow);
132 for (UIWindow *win in windowScene.windows) {
133 if (qt_objc_cast<QUIWindow*>(win)) {
140 return uiWindow.rootViewController.view;
150@interface QtFirstResponderEvent : UIEvent
151@property (nonatomic, strong) id firstResponder;
154@implementation QtFirstResponderEvent
157 self.firstResponder = 0;
163@implementation UIView (QtFirstResponder)
164- (UIView*)qt_findFirstResponder
166 if ([self isFirstResponder])
169 for (UIView *subview in self.subviews) {
170 if (UIView *firstResponder = [subview qt_findFirstResponder])
171 return firstResponder;
178@implementation UIResponder (QtFirstResponder)
180+ (id)qt_currentFirstResponder
182 if (qt_apple_isApplicationExtension()) {
183 qWarning() <<
"can't get first responder in application extensions!";
187 QtFirstResponderEvent *event = [[[QtFirstResponderEvent alloc] init] autorelease];
188 [qt_apple_sharedApplication() sendAction:@selector(qt_findFirstResponder:event:) to:nil from:nil forEvent:event];
189 return event.firstResponder;
192- (
void)qt_findFirstResponder:(id)sender event:(QtFirstResponderEvent *)event
196 if ([self isKindOfClass:[UIView
class]])
197 event.firstResponder = [
static_cast<UIView *>(self) qt_findFirstResponder];
199 event.firstResponder = [self isFirstResponder] ? self : nil;
205FirstResponderCandidate::FirstResponderCandidate(UIResponder *responder)
206 : QScopedValueRollback<UIResponder *>(s_firstResponderCandidate, responder)
210UIResponder *FirstResponderCandidate::s_firstResponderCandidate =
nullptr;
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
Q_DECLARE_LOGGING_CATEGORY(lcQpaWindowScene)
UIView * rootViewForScreen(const QPlatformScreen *)
UIWindow * presentationWindow(QWindow *)
int infoPlistValue(NSString *key, int defaultValue)
Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation)
bool isRunningOnVisionOS()
UIDeviceOrientation fromQtScreenOrientation(Qt::ScreenOrientation qtOrientation)
Q_DECLARE_LOGGING_CATEGORY(lcQpaWindow)