cocoa: only move window into screen bounds when changing screens

when forcibly moving windows to a different screen with --screen or
--fs-screen we need to move the window into the screen bounds if the
window is out of bounds, otherwise it can end up on the wrong screen.
previously it always recalculated the bounds and moved the window when
toggling fullscreen, now it only does the bound calculation when
changing screens.

Fixes #4178
This commit is contained in:
Akemi 2017-02-23 19:48:36 +01:00
parent 9bd819a0bc
commit 9d549e6837
1 changed files with 9 additions and 3 deletions

View File

@ -93,7 +93,9 @@
//move window to target screen when going to fullscreen //move window to target screen when going to fullscreen
if (![self.adapter isInFullScreenMode] && ![[self targetScreen] isEqual:[self screen]]) { if (![self.adapter isInFullScreenMode] && ![[self targetScreen] isEqual:[self screen]]) {
[self setFrame:[self calculateWindowPositionForScreen:[self targetScreen]] display:YES]; NSRect frame = [self calculateWindowPositionForScreen:[self targetScreen]
withoutBounds:NO];
[self setFrame:frame display:YES];
} }
[super toggleFullScreen:sender]; [super toggleFullScreen:sender];
@ -115,7 +117,8 @@
- (void)setToWindow - (void)setToWindow
{ {
[self setStyleMask:([self styleMask] & ~NSWindowStyleMaskFullScreen)]; [self setStyleMask:([self styleMask] & ~NSWindowStyleMaskFullScreen)];
NSRect frame = [self calculateWindowPositionForScreen:[self targetScreen]]; NSRect frame = [self calculateWindowPositionForScreen:[self targetScreen]
withoutBounds:[[self targetScreen] isEqual:[self screen]]];
[self setFrame:frame display:YES]; [self setFrame:frame display:YES];
[self setContentAspectRatio:_unfs_content_frame.size]; [self setContentAspectRatio:_unfs_content_frame.size];
[self setCenteredContentSize:_unfs_content_frame.size]; [self setCenteredContentSize:_unfs_content_frame.size];
@ -277,7 +280,7 @@
animate:NO]; animate:NO];
} }
- (NSRect)calculateWindowPositionForScreen:(NSScreen *)screen - (NSRect)calculateWindowPositionForScreen:(NSScreen *)screen withoutBounds:(BOOL)withoutBounds
{ {
NSRect frame = [self frameRectForContentRect:_unfs_content_frame]; NSRect frame = [self frameRectForContentRect:_unfs_content_frame];
NSRect targetFrame = [screen frame]; NSRect targetFrame = [screen frame];
@ -292,6 +295,9 @@
frame.origin.y = targetFrame.origin.y + frame.origin.y = targetFrame.origin.y +
(targetFrame.size.height - frame.size.height)*y_per; (targetFrame.size.height - frame.size.height)*y_per;
if (withoutBounds)
return frame;
//screen bounds right and left //screen bounds right and left
if (frame.origin.x + frame.size.width > targetFrame.origin.x + targetFrame.size.width) if (frame.origin.x + frame.size.width > targetFrame.origin.x + targetFrame.size.width)
frame.origin.x = targetFrame.origin.x + targetFrame.size.width - frame.size.width; frame.origin.x = targetFrame.origin.x + targetFrame.size.width - frame.size.width;