10#include <qpa/qwindowsysteminterface.h>
17#include <QtCore/private/qcore_mac_p.h>
19#include <QtGui/qpointingdevice.h>
20#include <QtGui/private/qwindow_p.h>
21#include <QtGui/private/qguiapplication_p.h>
22#include <private/qcoregraphics_p.h>
23#include <qpa/qwindowsysteminterface.h>
25#include <sys/sysctl.h>
31@implementation UIScreen (DisplayLinkBlock)
34 return [
self displayLinkWithTarget:[[block copy] autorelease]
35 selector:@selector(invokeDisplayLinkBlock:)];
39@implementation NSObject (DisplayLinkBlock)
40- (
void)invokeDisplayLinkBlock:(CADisplayLink *)sender
50#if !defined(Q_OS_VISIONOS)
55 if (platformScreen->
uiScreen() == uiScreen)
56 return platformScreen;
69 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
70 [center addObserver:self selector:@selector(screenConnected:)
71 name:UIScreenDidConnectNotification object:nil];
72 [center addObserver:self selector:@selector(screenDisconnected:)
73 name:UIScreenDidDisconnectNotification object:nil];
74 [center addObserver:self selector:@selector(screenModeChanged:)
75 name:UIScreenModeDidChangeNotification object:nil];
78+ (
void)screenConnected:(NSNotification*)notification
86+ (
void)screenDisconnected:(NSNotification*)notification
97+ (
void)screenModeChanged:(NSNotification*)notification
105 screen->updateProperties();
118#if !defined(Q_OS_VISIONOS)
124#if TARGET_OS_SIMULATOR
127 static const char key[] =
"hw.machine";
130 sysctlbyname(
key, NULL, &
size, NULL, 0);
140#if defined(Q_OS_VISIONOS)
149 if (
screen == [UIScreen mainScreen] && !deviceIdentifier.startsWith(
"AppleTV")) {
153 static QRegularExpression lowBitDepthDevices(
"^(iPhone1,[12]|iPhone2,1|iPod[1-3],1)$");
154 m_depth = deviceIdentifier.contains(lowBitDepthDevices) ? 18 : 24;
160 if (deviceIdentifier.contains(iPhoneXModels)) {
162 }
else if (deviceIdentifier.contains(iPhonePlusModels)) {
164 }
else if (deviceIdentifier.startsWith(
"iPad")) {
165 if (deviceIdentifier.contains(iPadMiniModels))
179 m_displayLink = [m_uiScreen displayLinkWithBlock:^(CADisplayLink *) { deliverUpdateRequests(); }];
180 m_displayLink.paused = YES;
181 [m_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
190 [m_displayLink invalidate];
195#if defined(Q_OS_VISIONOS)
198 if (m_uiScreen == [UIScreen mainScreen])
199 return QString::fromNSString([UIDevice currentDevice].
model) +
" built-in display"_L1;
201 return "External display"_L1;
207 QRect previousGeometry = m_geometry;
208 QRect previousAvailableGeometry = m_availableGeometry;
210#if defined(Q_OS_VISIONOS)
212 m_geometry =
QRect(0, 0, 1194, 834);
215 m_geometry = QRectF::fromCGRect(m_uiScreen.bounds).toRect();
217 if (m_geometry != previousGeometry) {
228 static const qreal millimetersPerInch = 25.4;
229 m_physicalSize = physicalGeometry.size() / m_physicalDpi * millimetersPerInch;
238 m_availableGeometry = m_geometry;
255 if (m_geometry != previousGeometry || m_availableGeometry != previousAvailableGeometry)
261 m_displayLink.paused = paused;
264void QIOSScreen::deliverUpdateRequests()
const
266 bool pauseUpdates =
true;
271 if (platformScreenForWindow(
window) !=
this)
285 pauseUpdates =
false;
289 m_displayLink.paused = pauseUpdates;
299 return m_availableGeometry;
314 return m_physicalSize;
324#if defined(Q_OS_VISIONOS)
327 return [m_uiScreen scale];
333#if defined(Q_OS_VISIONOS)
336 return m_uiScreen.maximumFramesPerSecond;
342#if defined(Q_OS_VISIONOS)
346 CGRect nativeBounds =
348 m_uiScreen.nativeBounds;
355 return nativeBounds.size.width >= nativeBounds.size.height ?
373 if (
window && ![
reinterpret_cast<id>(
window) isKindOfClass:[UIView class]])
384 CGRect captureRect = [view.window convertRect:CGRectMake(x, y, width, height) fromView:view];
385 captureRect = CGRectIntersection(captureRect,
view.window.bounds);
387 UIGraphicsBeginImageContextWithOptions(captureRect.size, NO, 0.0);
389 CGContextTranslateCTM(
context, -captureRect.origin.x, -captureRect.origin.y);
396 [view.window drawViewHierarchyInRect:view.window.bounds afterScreenUpdates:NO];
398 UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
399 UIGraphicsEndImageContext();
404#if !defined(Q_OS_VISIONOS)
413#include "moc_qiosscreen.cpp"
static QWindowList allWindows()
Returns a list of all the windows in the application.
static QList< QScreen * > screens()
Returns a list of all the screens associated with the windowing system the application is connected t...
static QIOSIntegration * instance()
qreal devicePixelRatio() const override
Reimplement this function in subclass to return the device pixel ratio for the screen.
void setUpdatesPaused(bool)
int depth() const override
Reimplement in subclass to return current depth of the screen.
QRect availableGeometry() const override
Reimplement in subclass to return the pixel geometry of the available space This normally is the desk...
Qt::ScreenOrientation nativeOrientation() const override
Reimplement this function in subclass to return the native orientation of the screen,...
QIOSScreen(UIScreen *screen)
qreal refreshRate() const override
Reimplement this function in subclass to return the vertical refresh rate of the screen,...
QImage::Format format() const override
Reimplement in subclass to return the image format which corresponds to the screen format.
QSizeF physicalSize() const override
Reimplement this function in subclass to return the physical size of the screen, in millimeters.
QRect geometry() const override
Reimplement in subclass to return the pixel geometry of the screen.
Qt::ScreenOrientation orientation() const override
Reimplement this function in subclass to return the current orientation of the screen,...
QDpi logicalBaseDpi() const override
Reimplement to return the base logical DPI for the platform.
QPixmap grabWindow(WId window, int x, int y, int width, int height) const override
This function is called when Qt needs to be able to grab the content of a window.
UIScreen * uiScreen() const
QString name() const override
Format
The following image formats are available in Qt.
@ Format_ARGB32_Premultiplied
qsizetype size() const noexcept
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr int width() const noexcept
Returns the width of the rectangle.
\inmodule QtCore \reentrant
The QScreen class is used to query screen properties. \inmodule QtGui.
QPlatformScreen * handle() const
Get the platform screen handle.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static void handleScreenGeometryChange(QScreen *screen, const QRect &newGeometry, const QRect &newAvailableGeometry)
static void handleScreenAdded(QPlatformScreen *screen, bool isPrimary=false)
Should be called by the implementation whenever a new screen is added.
static void handleScreenRemoved(QPlatformScreen *screen)
Should be called by the implementation whenever a screen is removed.
static void handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation newOrientation)
int width
the width of the window's geometry
int height
the height of the window's geometry
Combined button and popup list for selecting options.
QImage qt_mac_toQImage(CGImageRef image)
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]
QPair< qreal, qreal > QDpi
UIView * rootViewForScreen(QScreen *)
static QString deviceModelIdentifier()
Returns the model identifier of the device.
void(^ DisplayLinkBlock)(CADisplayLink *displayLink)
static QIOSScreen * qtPlatformScreenFor(UIScreen *uiScreen)
constexpr const T & qMax(const T &a, const T &b)
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
struct CGContext * CGContextRef
#define Q_ASSERT_X(cond, x, msg)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)