Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qiosglobal.mm
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qiosglobal.h"
7#include "qiosscreen.h"
8#include "quiwindow.h"
10
11#include <QtCore/private/qcore_mac_p.h>
12
14
15Q_LOGGING_CATEGORY(lcQpaApplication, "qt.qpa.application");
16Q_LOGGING_CATEGORY(lcQpaInputMethods, "qt.qpa.input.methods");
17Q_LOGGING_CATEGORY(lcQpaWindow, "qt.qpa.window");
18Q_LOGGING_CATEGORY(lcQpaWindowScene, "qt.qpa.window.scene");
19
21{
22 // Returns \c true if the plugin is in full control of the whole application. This means
23 // that we control the application delegate and the top view controller, and can take
24 // actions that impacts all parts of the application. The opposite means that we are
25 // embedded inside a native iOS application, and should be more focused on playing along
26 // with native UIControls, and less inclined to change structures that lies outside the
27 // scope of our QWindows/UIViews.
29}
30
32{
33 static bool result = []{
34 // This class is documented to only be available on visionOS
35 return NSClassFromString(@"UIWindowSceneGeometryPreferencesVision");
36 }();
37 return result;
38}
39
40#ifndef Q_OS_TVOS
41Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation)
42{
43 Qt::ScreenOrientation qtOrientation;
44 switch (uiDeviceOrientation) {
45 case UIDeviceOrientationPortraitUpsideDown:
46 qtOrientation = Qt::InvertedPortraitOrientation;
47 break;
48 case UIDeviceOrientationLandscapeLeft:
49 qtOrientation = Qt::LandscapeOrientation;
50 break;
51 case UIDeviceOrientationLandscapeRight:
53 break;
54 case UIDeviceOrientationFaceUp:
55 case UIDeviceOrientationFaceDown:
56 qWarning("Falling back to Qt::PortraitOrientation for UIDeviceOrientationFaceUp/UIDeviceOrientationFaceDown");
57 qtOrientation = Qt::PortraitOrientation;
58 break;
59 default:
60 qtOrientation = Qt::PortraitOrientation;
61 break;
62 }
63 return qtOrientation;
64}
65
66UIDeviceOrientation fromQtScreenOrientation(Qt::ScreenOrientation qtOrientation)
67{
68 UIDeviceOrientation uiOrientation;
69 switch (qtOrientation) {
71 uiOrientation = UIDeviceOrientationLandscapeLeft;
72 break;
74 uiOrientation = UIDeviceOrientationLandscapeRight;
75 break;
77 uiOrientation = UIDeviceOrientationPortraitUpsideDown;
78 break;
81 default:
82 uiOrientation = UIDeviceOrientationPortrait;
83 break;
84 }
85 return uiOrientation;
86}
87#endif
88
89int infoPlistValue(NSString* key, int defaultValue)
90{
91 static NSBundle *bundle = [NSBundle mainBundle];
92 NSNumber* value = [bundle objectForInfoDictionaryKey:key];
93 return value ? [value intValue] : defaultValue;
94}
95
97{
98 UIWindow *uiWindow = window ? reinterpret_cast<UIView *>(window->winId()).window : nullptr;
99 if (!uiWindow) {
100 auto *scenes = [qt_apple_sharedApplication().connectedScenes allObjects];
101 if (scenes.count > 0) {
102 auto *windowScene = static_cast<UIWindowScene*>(scenes[0]);
103 uiWindow = windowScene.keyWindow;
104 if (!uiWindow && windowScene.windows.count)
105 uiWindow = windowScene.windows[0];
106 }
107 }
108 return uiWindow;
109}
110
112{
113 const auto *iosScreen = static_cast<QIOSScreen *>(screen->handle());
114 for (UIScene *scene in [qt_apple_sharedApplication().connectedScenes allObjects]) {
115 if (![scene isKindOfClass:UIWindowScene.class])
116 continue;
117
118 auto *windowScene = static_cast<UIWindowScene*>(scene);
119
120#if !defined(Q_OS_VISIONOS)
121 if (windowScene.screen != iosScreen->uiScreen())
122 continue;
123#else
124 Q_UNUSED(iosScreen);
125#endif
126
127 UIWindow *uiWindow = qt_objc_cast<QUIWindow*>(windowScene.keyWindow);
128 if (!uiWindow) {
129 for (UIWindow *win in windowScene.windows) {
130 if (qt_objc_cast<QUIWindow*>(win)) {
131 uiWindow = win;
132 break;
133 }
134 }
135 }
136
137 return uiWindow.rootViewController.view;
138 }
139
140 return nullptr;
141}
142
144
145// -------------------------------------------------------------------------
146
147@interface QtFirstResponderEvent : UIEvent
148@property (nonatomic, strong) id firstResponder;
149@end
150
151@implementation QtFirstResponderEvent
152- (void)dealloc
153{
154 self.firstResponder = 0;
155 [super dealloc];
156}
157@end
158
159
160@implementation UIView (QtFirstResponder)
161- (UIView*)qt_findFirstResponder
162{
163 if ([self isFirstResponder])
164 return self;
165
166 for (UIView *subview in self.subviews) {
167 if (UIView *firstResponder = [subview qt_findFirstResponder])
168 return firstResponder;
169 }
170
171 return nil;
172}
173@end
174
175@implementation UIResponder (QtFirstResponder)
176
177+ (id)qt_currentFirstResponder
178{
180 qWarning() << "can't get first responder in application extensions!";
181 return nil;
182 }
183
184 QtFirstResponderEvent *event = [[[QtFirstResponderEvent alloc] init] autorelease];
185 [qt_apple_sharedApplication() sendAction:@selector(qt_findFirstResponder:event:) to:nil from:nil forEvent:event];
186 return event.firstResponder;
187}
188
189- (void)qt_findFirstResponder:(id)sender event:(QtFirstResponderEvent *)event
190{
191 Q_UNUSED(sender);
192
193 if ([self isKindOfClass:[UIView class]])
194 event.firstResponder = [static_cast<UIView *>(self) qt_findFirstResponder];
195 else
196 event.firstResponder = [self isFirstResponder] ? self : nil;
197}
198@end
199
201
203 : QScopedValueRollback<UIResponder *>(s_firstResponderCandidate, responder)
204{
205}
206
207UIResponder *FirstResponderCandidate::s_firstResponderCandidate = nullptr;
208
210
FirstResponderCandidate(UIResponder *)
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
QPlatformScreen * handle() const
Get the platform screen handle.
Definition qscreen.cpp:83
\inmodule QtGui
Definition qwindow.h:63
Combined button and popup list for selecting options.
ScreenOrientation
Definition qnamespace.h:271
@ InvertedLandscapeOrientation
Definition qnamespace.h:276
@ InvertedPortraitOrientation
Definition qnamespace.h:275
@ LandscapeOrientation
Definition qnamespace.h:274
@ PortraitOrientation
Definition qnamespace.h:273
@ PrimaryOrientation
Definition qnamespace.h:272
QString self
Definition language.cpp:58
bool qt_apple_isApplicationExtension()
Definition qcore_mac.mm:424
AppleApplication * qt_apple_sharedApplication()
Definition qcore_mac.mm:431
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
UIWindow * presentationWindow(QWindow *window)
Definition qiosglobal.mm:96
int infoPlistValue(NSString *key, int defaultValue)
Definition qiosglobal.mm:89
UIView * rootViewForScreen(QScreen *screen)
Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation)
Definition qiosglobal.mm:41
bool isQtApplication()
Definition qiosglobal.mm:20
bool isRunningOnVisionOS()
Definition qiosglobal.mm:31
UIDeviceOrientation fromQtScreenOrientation(Qt::ScreenOrientation qtOrientation)
Definition qiosglobal.mm:66
#define qWarning
Definition qlogging.h:166
#define Q_LOGGING_CATEGORY(name,...)
GLuint64 key
GLenum GLuint id
[7]
struct _cl_event * event
GLuint in
GLuint64EXT * result
[6]
QScreen * screen
[1]
Definition main.cpp:29
#define Q_UNUSED(x)
QWidget * win
Definition settings.cpp:6
QSharedPointer< int > strong
QGraphicsScene scene
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]