14#include <QtCore/private/qcore_mac_p.h>
16#include <QtGui/private/qwindow_p.h>
17#include <QtGui/private/qhighdpiscaling_p.h>
18#include <qpa/qplatformintegration.h>
21#import <QuartzCore/CAEAGLLayer.h>
25#import <QuartzCore/CAMetalLayer.h>
42 m_view =
reinterpret_cast<UIView *
>(nativeHandle);
50 m_view = [[QUIMetalView alloc] initWithQIOSWindow:
this];
53 m_view = [[
QUIView alloc] initWithQIOSWindow:
this];
81 dispatch_async(dispatch_get_main_queue(), ^{
94 [m_view touchesCancelled:[NSSet
set] withEvent:0];
104 [m_view removeFromSuperview];
112 return window()->requestedFormat();
116bool QIOSWindow::blockedByModal()
119 return modalWindow && modalWindow !=
window();
124 m_view.hidden = !visible;
125 [m_view setNeedsDisplay];
135 if (blockedByModal()) {
144 }
else if (!visible && [
quiview_cast(m_view) isActiveWindow]) {
147 NSArray<UIView *> *subviews = m_view.viewController.view.subviews;
148 for (
int i =
int(subviews.count) - 1;
i >= 0; --
i) {
149 UIView *
view = [subviews objectAtIndex:
i];
154 if (!
w || !
w->isTopLevel())
158 if (!iosWindow->shouldAutoActivateWindow())
169 if (![m_view canBecomeFirstResponder])
186 m_normalGeometry =
rect;
193 [m_view setNeedsLayout];
204 [m_view layoutIfNeeded];
213void QIOSWindow::applyGeometry(
const QRect &
rect)
221 m_view.frame =
rect.toCGRect();
225 [m_view setNeedsLayout];
228 [m_view layoutIfNeeded];
233 UIEdgeInsets safeAreaInsets = m_view.safeAreaInsets;
234 return QMargins(safeAreaInsets.left, safeAreaInsets.top,
235 safeAreaInsets.right, safeAreaInsets.bottom);
252 [m_view.qtViewController updateProperties];
255 applyGeometry(
QRect());
257 QRect uiWindowBounds = QRectF::fromCGRect(m_view.window.bounds).toRect();
258 if (NSProcessInfo.processInfo.iOSAppOnMac) {
266 applyGeometry(uiWindowBounds);
271 applyGeometry(uiWindowBounds);
274 QRect maximizedGeometry = fullscreenGeometry;
276#if !defined(Q_OS_VISIONOS)
282 UIScreen *uiScreen = m_view.window.windowScene.screen;
283 UIEdgeInsets safeAreaInsets = m_view.window.safeAreaInsets;
284 if (m_view.window.bounds.size.width == uiScreen.bounds.size.width)
285 maximizedGeometry.adjust(safeAreaInsets.left, 0, -safeAreaInsets.right, 0);
286 if (m_view.window.bounds.size.height == uiScreen.bounds.size.height)
287 maximizedGeometry.adjust(0, safeAreaInsets.top, 0, -safeAreaInsets.bottom);
292 applyGeometry(fullscreenGeometry.intersected(uiWindowBounds));
294 applyGeometry(maximizedGeometry.intersected(uiWindowBounds));
297 applyGeometry(m_normalGeometry);
303 UIView *superview =
nullptr;
305 superview =
reinterpret_cast<UIView *
>(parentWindow->
winId());
310 [superview addSubview:m_view];
312 [m_view removeFromSuperview];
320 if (blockedByModal())
323 [m_view.window makeKeyWindow];
324 [m_view becomeFirstResponder];
326 if (
window()->isTopLevel())
330void QIOSWindow::raiseOrLower(
bool raise)
335 NSArray<UIView *> *subviews = m_view.superview.subviews;
336 if (subviews.count == 1)
339 if (m_view.superview == m_view.qtViewController.view) {
342 for (
int i =
int(subviews.count) - 1;
i >= 0; --
i) {
343 UIView *
view =
static_cast<UIView *
>([subviews objectAtIndex:
i]);
348 [m_view.superview insertSubview:m_view aboveSubview:
view];
352 [m_view.superview insertSubview:m_view atIndex:0];
356 [m_view.superview bringSubviewToFront:m_view];
358 [m_view.superview sendSubviewToBack:m_view];
362void QIOSWindow::updateWindowLevel()
370 else if (
window()->isModal())
383 QIOSWindow *transientParentWindow = transientParent ?
static_cast<QIOSWindow *
>(transientParent->handle()) : 0;
384 if (transientParentWindow)
385 m_windowLevel =
qMax(transientParentWindow->m_windowLevel, m_windowLevel);
399 return m_view.contentScaleFactor;
418 QCFType<CGMutablePathRef> maskPath = CGPathCreateMutable();
419 for (
const QRect &
r : region)
420 CGPathAddRect(maskPath,
nullptr,
r.toCGRect());
421 CAShapeLayer *maskLayer = [CAShapeLayer
layer];
422 maskLayer.path = maskPath;
423 m_view.layer.mask = maskLayer;
425 m_view.layer.mask = nil;
430CAEAGLLayer *QIOSWindow::eaglLayer()
const
432 Q_ASSERT([m_view.layer isKindOfClass:[CAEAGLLayer class]]);
433 return static_cast<CAEAGLLayer *
>(m_view.layer);
437#ifndef QT_NO_DEBUG_STREAM
468 return qt_objc_cast<QUIView *>(
view);
473 return ![m_view isKindOfClass:
QUIView.class];
483#include "moc_qioswindow.cpp"
static QWindow * modalWindow()
Returns the most recently shown modal window.
void applicationStateChanged(Qt::ApplicationState state)
bool isForeignWindow() const override
bool shouldAutoActivateWindow() const
void setParent(const QPlatformWindow *window) override
This function is called to enable native child window in QPA.
void clearAccessibleCache()
void setWindowState(Qt::WindowStates state) override
Requests setting the window state of this surface to type.
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
void requestUpdate() override
Requests an QEvent::UpdateRequest event.
void setMask(const QRegion ®ion) override
Reimplement to be able to let Qt set the mask of a window.
void setOpacity(qreal level) override
Reimplement to be able to let Qt set the opacity level of a window.
QIOSWindow(QWindow *window, WId nativeHandle=0)
qreal devicePixelRatio() const override
Reimplement this function in subclass to return the device pixel ratio for the window.
bool isExposed() const override
Returns if this window is exposed in the windowing system.
void raise() override
Reimplement to be able to let Qt raise windows to the top of the desktop.
QMargins safeAreaMargins() const override
The safe area margins of a window represent the area that is safe to place content within,...
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
QSurfaceFormat format() const override
Returns the actual surface format of the window.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
\inmodule QtCore\reentrant
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
The QRegion class specifies a clip region for a painter.
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
static void handleWindowStateChanged(QWindow *window, Qt::WindowStates newState, int oldState=-1)
SurfaceType surfaceType() const override
Returns the surface type of the window.
Qt::ScreenOrientation contentOrientation
the orientation of the window's contents
qreal opacity
The opacity of the window in the windowing system.
QRegion toNativeLocalRegion(const QRegion &pointRegion, const QWindow *window)
Combined button and popup list for selecting options.
@ MaximizeUsingFullscreenGeometryHint
UIView * rootViewForScreen(QScreen *)
bool isRunningOnVisionOS()
QDebug operator<<(QDebug debug, const QIOSWindow *window)
QUIView * quiview_cast(UIView *view)
Returns the view cast to a QUIview if possible.
constexpr const T & qBound(const T &min, const T &val, const T &max)
constexpr const T & qMax(const T &a, const T &b)
GLenum GLuint GLint level
GLfloat GLfloat GLfloat w
[0]
Q_GUI_EXPORT QWindowPrivate * qt_window_private(QWindow *window)
QFuture< QSet< QChar > > set
[10]
QT_BEGIN_NAMESPACE bool toBool(const QString &str)