diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 6311c1f1f5..a50b9251b7 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -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 diff --git a/src/plugins/platforms/cocoa/qcocoascreen.h b/src/plugins/platforms/cocoa/qcocoascreen.h index 3d59c3de79..850ccaad7a 100644 --- a/src/plugins/platforms/cocoa/qcocoascreen.h +++ b/src/plugins/platforms/cocoa/qcocoascreen.h @@ -104,5 +104,9 @@ QDebug operator<<(QDebug debug, const QCocoaScreen *screen); QT_END_NAMESPACE +@interface NSScreen (QtExtras) +@property(readonly) CGDirectDisplayID qt_displayId; +@end + #endif diff --git a/src/plugins/platforms/cocoa/qcocoascreen.mm b/src/plugins/platforms/cocoa/qcocoascreen.mm index c963f33270..f5408d7c13 100644 --- a/src/plugins/platforms/cocoa/qcocoascreen.mm +++ b/src/plugins/platforms/cocoa/qcocoascreen.mm @@ -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