diff options
author | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2014-03-25 21:27:20 +0100 |
---|---|---|
committer | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2014-04-28 21:32:58 +0200 |
commit | 2c08ab1c6a68943ee1ae3ff1b641e11544091ced (patch) | |
tree | 5aeec8de624cbe1a930935b14d7cb17129d661cd /video | |
parent | 80ec0bac432bb9a059c6d305ed3b6eed1ad08869 (diff) | |
download | mpv-2c08ab1c6a68943ee1ae3ff1b641e11544091ced.tar.bz2 mpv-2c08ab1c6a68943ee1ae3ff1b641e11544091ced.tar.xz |
cocoa: add constraints to prevent the window to exit the screen
Previously the window could be made to completly exit the screen with a
combination or moving it close to an edge and halving it's size (via cmd+0).
This commit address the problem in the most simple way possibile by
constraining the window to the closest edge in these edge cases.
Diffstat (limited to 'video')
-rw-r--r-- | video/out/cocoa/window.m | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/video/out/cocoa/window.m b/video/out/cocoa/window.m index 9290c446d8..515ea5926e 100644 --- a/video/out/cocoa/window.m +++ b/video/out/cocoa/window.m @@ -127,19 +127,31 @@ if ([self isInFullScreenMode]) return [super constrainFrameRect:nf toScreen:screen]; - NSRect of = [self frame]; + NSRect cf = [self frame]; NSRect vf = [[self screen] visibleFrame]; - if (NSMaxY(nf) > NSMaxY(vf)) { - // If the new window is bigger than the visible frame, make sure it's - // titlebar is visible and at the top of the visible frame. + // Prevent the window's titlebar from exiting the screen on the top edge. + // This introduces a 'snap to top' behaviour. + if (NSMaxY(nf) > NSMaxY(vf)) nf.origin.y = NSMaxY(vf) - NSHeight(nf); - } else if (NSHeight(of) > NSHeight(vf)) { - // If the window is smaller than the visible frame, but it was bigger - // previously (so we ran the previous conditional branch), recenter - // the smaller window vertically. + + // Prevent window from exiting the screen on the bottom edge + if (NSMaxY(nf) < NSMinY(vf)) + nf.origin.y = NSMinY(vf); + + // Prevent window from exiting the screen on the right edge + if (NSMinX(nf) > NSMaxX(vf)) + nf.origin.x = NSMaxX(vf) - NSWidth(nf); + + // Prevent window from exiting the screen on the left + if (NSMaxX(nf) < NSMinX(vf)) + nf.origin.x = NSMinX(vf); + + if (NSHeight(nf) < NSHeight(vf) && NSHeight(cf) > NSHeight(vf)) + // If the window height is smaller than the visible frame, but it was + // bigger previously recenter the smaller window vertically. This is + // needed to counter the 'snap to top' behaviour. nf.origin.y = (NSHeight(vf) - NSHeight(nf)) / 2; - } return nf; } |