@@ -269,24 +269,14 @@ - (nullable NSImage *)windowScreenshot {
269269 if (self.window ) {
270270 NSRect viewFrameInWindow = [self convertRect: self .bounds toView: nil ];
271271 NSRect windowFrame = [self .window convertRectToScreen: viewFrameInWindow];
272+ CGRect mainDisplayBounds = CGDisplayBounds (CGMainDisplayID ());
272273
273- // Find the maximum Y coordinate across all screens for proper coordinate conversion
274- CGFloat maxY = 0 ;
275- for (NSScreen *screen in [NSScreen screens ]) {
276- CGFloat screenMaxY = screen.frame .origin .y + screen.frame .size .height ;
277- if (screenMaxY > maxY) {
278- maxY = screenMaxY;
279- }
280- }
281-
282- CGFloat captureX = windowFrame.origin .x ;
283- CGFloat captureY = (maxY - windowFrame.origin .y - windowFrame.size .height );
284- CGFloat captureWidth = windowFrame.size .width ;
285- CGFloat captureHeight = windowFrame.size .height ;
274+ CGFloat cgX = windowFrame.origin .x ;
275+ CGFloat cgY = mainDisplayBounds.size .height - windowFrame.origin .y - windowFrame.size .height ;
286276
287277 CGImageRef cgImage = CGWindowListCreateImage
288278 (
289- CGRectMake (captureX, captureY, captureWidth, captureHeight ),
279+ CGRectMake (cgX, cgY, windowFrame. size . width , windowFrame. size . height ),
290280 kCGWindowListOptionIncludingWindow ,
291281 (CGWindowID)[self .window windowNumber ],
292282 kCGWindowImageBoundsIgnoreFraming | kCGWindowImageShouldBeOpaque
0 commit comments