macOS: Provide helper property for resolving the display ID of a screen

Change-Id: I144bd33a2c122d53ea1435a53483a3d8b46fd093
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
This commit is contained in:
Tor Arne Vestbø 2018-03-20 17:31:43 +01:00
parent ffc20153d1
commit 321c2d29fb
3 changed files with 15 additions and 3 deletions

View File

@ -244,7 +244,7 @@ void QCocoaIntegration::updateScreens()
uint screenCount = [screens count];
for (uint i = 0; i < screenCount; i++) {
NSScreen* scr = [screens objectAtIndex:i];
CGDirectDisplayID dpy = [[[scr deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
CGDirectDisplayID dpy = scr.qt_displayId;
// If this screen is a mirror and is not the primary one of the mirror set, ignore it.
// Exception: The NSScreen API has been observed to a return a screen list with one
// mirrored, non-primary screen when Qt is running as a startup item. Always use the

View File

@ -104,5 +104,9 @@ QDebug operator<<(QDebug debug, const QCocoaScreen *screen);
QT_END_NAMESPACE
@interface NSScreen (QtExtras)
@property(readonly) CGDirectDisplayID qt_displayId;
@end
#endif

View File

@ -121,8 +121,7 @@ void QCocoaScreen::updateGeometry()
m_format = QImage::Format_RGB32;
m_depth = NSBitsPerPixelFromDepth([nsScreen depth]);
NSDictionary *devDesc = [nsScreen deviceDescription];
CGDirectDisplayID dpy = [[devDesc objectForKey:@"NSScreenNumber"] unsignedIntValue];
CGDirectDisplayID dpy = nsScreen.qt_displayId;
CGSize size = CGDisplayScreenSize(dpy);
m_physicalSize = QSizeF(size.width, size.height);
m_logicalDpi.first = 72;
@ -310,3 +309,12 @@ QDebug operator<<(QDebug debug, const QCocoaScreen *screen)
#endif // !QT_NO_DEBUG_STREAM
QT_END_NAMESPACE
@implementation NSScreen (QtExtras)
- (CGDirectDisplayID)qt_displayId
{
return [self.deviceDescription[@"NSScreenNumber"] unsignedIntValue];
}
@end