2
0

Update screen capture code to accurately capture the active display only.

This commit is contained in:
Maarten Billemont 2014-06-28 00:04:40 -04:00
parent f294a8c9f5
commit 34d8dc375f

View File

@ -526,15 +526,14 @@
return; return;
PearlProfiler *profiler = [PearlProfiler profilerForTask:@"fadeIn"]; PearlProfiler *profiler = [PearlProfiler profilerForTask:@"fadeIn"];
CGWindowID windowID = (CGWindowID)[self.window windowNumber]; CGDirectDisplayID displayID = [self.window.screen.deviceDescription[@"NSScreenNumber"] unsignedIntValue];
CGImageRef capturedImage = CGWindowListCreateImage( CGRectInfinite, kCGWindowListOptionOnScreenBelowWindow, windowID, CGImageRef capturedImage = CGDisplayCreateImage( displayID );
kCGWindowImageBoundsIgnoreFraming ); if (!capturedImage || CGImageGetWidth( capturedImage ) <= 1) {
if (CGImageGetWidth( capturedImage ) <= 1) { wrn( @"Failed to capture screen image for display: %d", displayID );
wrn( @"Failed to capture screen image for window: %d", windowID );
return; 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( NSImage *screenImage = [[NSImage alloc] initWithCGImage:capturedImage size:NSMakeSize(
CGImageGetWidth( capturedImage ) / self.window.backingScaleFactor, CGImageGetWidth( capturedImage ) / self.window.backingScaleFactor,
CGImageGetHeight( capturedImage ) / self.window.backingScaleFactor )]; CGImageGetHeight( capturedImage ) / self.window.backingScaleFactor )];
@ -543,6 +542,7 @@
NSImage *smallImage = [[NSImage alloc] initWithSize:NSMakeSize( NSImage *smallImage = [[NSImage alloc] initWithSize:NSMakeSize(
CGImageGetWidth( capturedImage ) / 20, CGImageGetWidth( capturedImage ) / 20,
CGImageGetHeight( capturedImage ) / 20 )]; CGImageGetHeight( capturedImage ) / 20 )];
CFRelease( capturedImage );
[smallImage lockFocus]; [smallImage lockFocus];
[screenImage drawInRect:(NSRect){ .origin = CGPointZero, .size = smallImage.size, } [screenImage drawInRect:(NSRect){ .origin = CGPointZero, .size = smallImage.size, }
fromRect:NSZeroRect fromRect:NSZeroRect