Cocoa: implement QScreen::orientation
Get the rotation value from the Core Graphics API, and map it to the Qt::ScreenOrientation values. Change-Id: I9bc9f37f34e00affee15e6ce0eace70d853eab0c Reviewed-by: Doris Verria <doris.verria@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>bb10
parent
cea33d7387
commit
f4c32f729c
|
|
@ -41,6 +41,7 @@ public:
|
|||
QWindow *topLevelAt(const QPoint &point) const override;
|
||||
QList<QPlatformScreen *> virtualSiblings() const override;
|
||||
QPlatformScreen::SubpixelAntialiasingType subpixelAntialiasingTypeHint() const override;
|
||||
Qt::ScreenOrientation orientation() const override;
|
||||
|
||||
// ----------------------------------------------------
|
||||
|
||||
|
|
@ -90,6 +91,7 @@ private:
|
|||
QSizeF m_physicalSize;
|
||||
QCocoaCursor *m_cursor;
|
||||
qreal m_devicePixelRatio = 0;
|
||||
qreal m_rotation = 0;
|
||||
|
||||
CVDisplayLinkRef m_displayLink = nullptr;
|
||||
dispatch_source_t m_displayLinkSource = nullptr;
|
||||
|
|
|
|||
|
|
@ -248,6 +248,7 @@ void QCocoaScreen::update(CGDirectDisplayID displayId)
|
|||
const QRect previousGeometry = m_geometry;
|
||||
const QRect previousAvailableGeometry = m_availableGeometry;
|
||||
const qreal previousRefreshRate = m_refreshRate;
|
||||
const double previousRotation = m_rotation;
|
||||
|
||||
// The reference screen for the geometry is always the primary screen
|
||||
QRectF primaryScreenGeometry = QRectF::fromCGRect(CGDisplayBounds(CGMainDisplayID()));
|
||||
|
|
@ -272,6 +273,7 @@ void QCocoaScreen::update(CGDirectDisplayID displayId)
|
|||
QCFType<CGDisplayModeRef> displayMode = CGDisplayCopyDisplayMode(m_displayId);
|
||||
float refresh = CGDisplayModeGetRefreshRate(displayMode);
|
||||
m_refreshRate = refresh > 0 ? refresh : 60.0;
|
||||
m_rotation = CGDisplayRotation(displayId);
|
||||
|
||||
if (@available(macOS 10.15, *))
|
||||
m_name = QString::fromNSString(nsScreen.localizedName);
|
||||
|
|
@ -280,6 +282,9 @@ void QCocoaScreen::update(CGDirectDisplayID displayId)
|
|||
|
||||
const bool didChangeGeometry = m_geometry != previousGeometry || m_availableGeometry != previousAvailableGeometry;
|
||||
|
||||
if (m_rotation != previousRotation)
|
||||
QWindowSystemInterface::handleScreenOrientationChange(screen(), orientation());
|
||||
|
||||
if (didChangeGeometry)
|
||||
QWindowSystemInterface::handleScreenGeometryChange(screen(), geometry(), availableGeometry());
|
||||
if (m_refreshRate != previousRefreshRate)
|
||||
|
|
@ -522,6 +527,19 @@ QPlatformScreen::SubpixelAntialiasingType QCocoaScreen::subpixelAntialiasingType
|
|||
return type;
|
||||
}
|
||||
|
||||
Qt::ScreenOrientation QCocoaScreen::orientation() const
|
||||
{
|
||||
if (m_rotation == 0)
|
||||
return Qt::LandscapeOrientation;
|
||||
if (m_rotation == 90)
|
||||
return Qt::PortraitOrientation;
|
||||
if (m_rotation == 180)
|
||||
return Qt::InvertedLandscapeOrientation;
|
||||
if (m_rotation == 270)
|
||||
return Qt::InvertedPortraitOrientation;
|
||||
return QPlatformScreen::orientation();
|
||||
}
|
||||
|
||||
QWindow *QCocoaScreen::topLevelAt(const QPoint &point) const
|
||||
{
|
||||
__block QWindow *window = nullptr;
|
||||
|
|
|
|||
Loading…
Reference in New Issue