8#include <qpa/qwindowsysteminterface.h>
14#include <QtCore/private/qcore_mac_p.h>
16#include <QtGui/qpointingdevice.h>
17#include <QtGui/private/qwindow_p.h>
18#include <QtGui/private/qguiapplication_p.h>
19#include <private/qcoregraphics_p.h>
20#include <qpa/qwindowsysteminterface.h>
22#include <sys/sysctl.h>
28@implementation UIScreen (DisplayLinkBlock)
31 return [
self displayLinkWithTarget:[[block copy] autorelease]
32 selector:@selector(invokeDisplayLinkBlock:)];
36@implementation NSObject (DisplayLinkBlock)
37- (
void)invokeDisplayLinkBlock:(CADisplayLink *)sender
51 if (platformScreen->
uiScreen() == uiScreen)
52 return platformScreen;
65 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
66 [center addObserver:self selector:@selector(screenConnected:)
67 name:UIScreenDidConnectNotification object:nil];
68 [center addObserver:self selector:@selector(screenDisconnected:)
69 name:UIScreenDidDisconnectNotification object:nil];
70 [center addObserver:self selector:@selector(screenModeChanged:)
71 name:UIScreenModeDidChangeNotification object:nil];
74+ (
void)screenConnected:(NSNotification*)notification
82+ (
void)screenDisconnected:(NSNotification*)notification
93+ (
void)screenModeChanged:(NSNotification*)notification
101 screen->updateProperties();
121 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
122 [[NSNotificationCenter defaultCenter]
124 selector:@selector(orientationChanged:)
125 name:@"UIDeviceOrientationDidChangeNotification" object:nil];
134 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
135 [[NSNotificationCenter defaultCenter]
137 name:@"UIDeviceOrientationDidChangeNotification" object:nil];
142- (
void)orientationChanged:(NSNotification *)notification
145 m_screen->updateProperties();
150@interface UIScreen (Compatibility)
151@property (nonatomic, readonly) CGRect qt_applicationFrame;
154@implementation UIScreen (Compatibility)
155- (CGRect)qt_applicationFrame
158 return self.applicationFrame;
169- (instancetype)initWithFrame:(CGRect)frame
171 if ((self = [super initWithFrame:
frame]))
172 self->_sendingEvent = NO;
177- (
void)sendEvent:(UIEvent *)event
180 [
super sendEvent:event];
183- (
void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
185 [
super traitCollectionDidChange:previousTraitCollection];
188 == UIUserInterfaceStyleDark
192 if (
self.screen == UIScreen.mainScreen) {
195 if (previousTraitCollection.userInterfaceStyle !=
self.traitCollection.userInterfaceStyle
198 QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
216#if TARGET_OS_SIMULATOR
219 static const char key[] =
"hw.machine";
222 sysctlbyname(
key, NULL, &
size, NULL, 0);
235 , m_orientationListener(0)
239 if (
screen == [UIScreen mainScreen] && !deviceIdentifier.
startsWith(
"AppleTV")) {
243 static QRegularExpression lowBitDepthDevices(
"^(iPhone1,[12]|iPhone2,1|iPod[1-3],1)$");
244 m_depth = deviceIdentifier.
contains(lowBitDepthDevices) ? 18 : 24;
250 if (deviceIdentifier.
contains(iPhoneXModels)) {
252 }
else if (deviceIdentifier.
contains(iPhonePlusModels)) {
254 }
else if (deviceIdentifier.
startsWith(
"iPad")) {
255 if (deviceIdentifier.
contains(iPadMiniModels))
271 if (existingWindow.screen == m_uiScreen) {
272 m_uiWindow = [existingWindow retain];
279 m_uiWindow = [[
QUIWindow alloc] initWithFrame:[m_uiScreen bounds]];
280 m_uiWindow.rootViewController = [[[
QIOSViewController alloc] initWithQIOSScreen:this] autorelease];
288 m_displayLink = [m_uiScreen displayLinkWithBlock:^(CADisplayLink *) { deliverUpdateRequests(); }];
289 m_displayLink.paused = YES;
290 [m_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
295 [m_displayLink invalidate];
298 [m_uiWindow release];
303 if (m_uiScreen == [UIScreen mainScreen])
304 return QString::fromNSString([UIDevice currentDevice].
model) +
" built-in display"_L1;
306 return "External display"_L1;
311 QRect previousGeometry = m_geometry;
312 QRect previousAvailableGeometry = m_availableGeometry;
314 m_geometry = QRectF::fromCGRect(m_uiScreen.bounds).toRect();
320 QRect applicationFrame = QRectF::fromCGRect(m_uiScreen.qt_applicationFrame).toRect();
321 UIEdgeInsets safeAreaInsets = m_uiWindow.qt_safeAreaInsets;
322 m_availableGeometry = m_geometry.
adjusted(safeAreaInsets.left, safeAreaInsets.top,
323 -safeAreaInsets.right, -safeAreaInsets.bottom).
intersected(applicationFrame);
326 if (m_uiScreen == [UIScreen mainScreen]) {
344 m_geometry =
transform.mapRect(m_geometry);
345 m_availableGeometry =
transform.mapRect(m_availableGeometry);
350 if (m_geometry != previousGeometry) {
361 static const qreal millimetersPerInch = 25.4;
362 m_physicalSize = physicalGeometry.
size() / m_physicalDpi * millimetersPerInch;
380 if (m_geometry != previousGeometry || m_availableGeometry != previousAvailableGeometry)
386 m_displayLink.paused = paused;
389void QIOSScreen::deliverUpdateRequests()
const
391 bool pauseUpdates =
true;
396 if (platformScreenForWindow(
window) !=
this)
410 pauseUpdates =
false;
414 m_displayLink.paused = pauseUpdates;
424 return m_availableGeometry;
439 return m_physicalSize;
449 return [m_uiScreen scale];
454 return m_uiScreen.maximumFramesPerSecond;
459 CGRect nativeBounds =
461 m_uiScreen.nativeBounds;
468 return nativeBounds.size.width >= nativeBounds.size.height ?
478 if (m_uiScreen != [UIScreen mainScreen])
481 UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
495 if (deviceOrientation == UIDeviceOrientationFaceUp || deviceOrientation == UIDeviceOrientationFaceDown) {
506 if (
window && ![
reinterpret_cast<id>(
window) isKindOfClass:[UIView class]])
516 CGRect captureRect = [m_uiWindow convertRect:CGRectMake(x, y, width, height) fromView:view];
517 captureRect = CGRectIntersection(captureRect, m_uiWindow.bounds);
519 UIGraphicsBeginImageContextWithOptions(captureRect.size, NO, 0.0);
521 CGContextTranslateCTM(
context, -captureRect.origin.x, -captureRect.origin.y);
528 [m_uiWindow drawViewHierarchyInRect:m_uiWindow.bounds afterScreenUpdates:NO];
530 UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
531 UIGraphicsEndImageContext();
548#include "moc_qiosscreen.cpp"
static QPlatformTheme * platformTheme()
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.
UIWindow * uiWindow() const
UIScreen * uiScreen() const
QString name() const override
static void initializeSystemPalette()
Format
The following image formats are available in Qt.
@ Format_ARGB32_Premultiplied
qsizetype size() const noexcept
const_reference at(qsizetype i) 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
constexpr QSizeF size() const noexcept
Returns the size of the rectangle.
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height of the rectangle.
QRect intersected(const QRect &other) const noexcept
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
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.
Qt::ScreenOrientation orientation
the screen orientation
QPlatformScreen * handle() const
Get the platform screen handle.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
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...
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
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
UIInterfaceOrientation lockedOrientation
Combined button and popup list for selecting options.
bool qt_apple_isApplicationExtension()
AppleApplication * qt_apple_sharedApplication()
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
Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation)
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]
GLuint GLenum GLenum transform
struct CGContext * CGContextRef
#define Q_ASSERT_X(cond, x, msg)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)