From f2111ff1d7ce3b521f447baf1a6bb42bfad83d9d Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 27 Mar 2014 14:48:54 +0100 Subject: NSScreen screens may be empty so add the main screen in that case In some circumstances NSScreen screens can be empty yet there is still a valid main screen so we prevent any problems arising by ensuring we work with the main screen in that instance. Task-number: QTBUG-37876 Change-Id: I5827009a9894eb8c1d4f5addc6c6f59e1c50c3d0 Reviewed-by: Shawn Rutledge --- src/plugins/platforms/cocoa/qcocoaintegration.mm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 65a9f87e2d..412818ae47 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -316,11 +316,17 @@ QCocoaIntegration *QCocoaIntegration::instance() */ void QCocoaIntegration::updateScreens() { - NSArray *screens = [NSScreen screens]; + NSArray *scrs = [NSScreen screens]; + NSMutableArray *screens = [NSMutableArray arrayWithArray:scrs]; + if ([screens count] == 0) + if ([NSScreen mainScreen]) + [screens addObject:[NSScreen mainScreen]]; + if ([screens count] == 0) + return; QSet remainingScreens = QSet::fromList(mScreens); QList siblings; for (uint i = 0; i < [screens count]; i++) { - NSScreen* scr = [[NSScreen screens] objectAtIndex:i]; + NSScreen* scr = [screens objectAtIndex:i]; CGDirectDisplayID dpy = [[[scr deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue]; // If this screen is a mirror and is not the primary one of the mirror set, ignore it. if (CGDisplayIsInMirrorSet(dpy)) { -- cgit v1.2.3