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:
parent
ffc20153d1
commit
321c2d29fb
@ -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
|
||||
|
@ -104,5 +104,9 @@ QDebug operator<<(QDebug debug, const QCocoaScreen *screen);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
@interface NSScreen (QtExtras)
|
||||
@property(readonly) CGDirectDisplayID qt_displayId;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user