From 34d8dc375f5a92bee2183986b8950ed245762639 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Sat, 28 Jun 2014 00:04:40 -0400 Subject: [PATCH] Update screen capture code to accurately capture the active display only. --- MasterPassword/ObjC/Mac/MPPasswordWindowController.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MasterPassword/ObjC/Mac/MPPasswordWindowController.m b/MasterPassword/ObjC/Mac/MPPasswordWindowController.m index 9ca4e6e8..3c6a3537 100644 --- a/MasterPassword/ObjC/Mac/MPPasswordWindowController.m +++ b/MasterPassword/ObjC/Mac/MPPasswordWindowController.m @@ -526,15 +526,14 @@ return; PearlProfiler *profiler = [PearlProfiler profilerForTask:@"fadeIn"]; - CGWindowID windowID = (CGWindowID)[self.window windowNumber]; - CGImageRef capturedImage = CGWindowListCreateImage( CGRectInfinite, kCGWindowListOptionOnScreenBelowWindow, windowID, - kCGWindowImageBoundsIgnoreFraming ); - if (CGImageGetWidth( capturedImage ) <= 1) { - wrn( @"Failed to capture screen image for window: %d", windowID ); + CGDirectDisplayID displayID = [self.window.screen.deviceDescription[@"NSScreenNumber"] unsignedIntValue]; + CGImageRef capturedImage = CGDisplayCreateImage( displayID ); + if (!capturedImage || CGImageGetWidth( capturedImage ) <= 1) { + wrn( @"Failed to capture screen image for display: %d", displayID ); return; } - [profiler finishJob:@"captured window: %d, on screen: %@", windowID, self.window.screen]; + [profiler finishJob:@"captured window: %d, on screen: %@", displayID, self.window.screen.deviceDescription]; NSImage *screenImage = [[NSImage alloc] initWithCGImage:capturedImage size:NSMakeSize( CGImageGetWidth( capturedImage ) / self.window.backingScaleFactor, CGImageGetHeight( capturedImage ) / self.window.backingScaleFactor )]; @@ -543,6 +542,7 @@ NSImage *smallImage = [[NSImage alloc] initWithSize:NSMakeSize( CGImageGetWidth( capturedImage ) / 20, CGImageGetHeight( capturedImage ) / 20 )]; + CFRelease( capturedImage ); [smallImage lockFocus]; [screenImage drawInRect:(NSRect){ .origin = CGPointZero, .size = smallImage.size, } fromRect:NSZeroRect