Skip to content

Commit fda838c

Browse files
committed
Merge pull request '[macos] Fix window snapshot of view in global display coordinate space' (#499) from fix/blink-tabs into release/v9.1.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/desktop-apps/pulls/499
2 parents 7a63057 + 43e5deb commit fda838c

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

macos/ONLYOFFICE/Code/Extensions/NSView+Extensions.m

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)