mirror of
https://github.com/mpv-player/mpv
synced 2025-02-03 05:31:34 +00:00
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.
This commit is contained in:
parent
80ec0bac43
commit
2c08ab1c6a
@ -127,19 +127,31 @@
|
|||||||
if ([self isInFullScreenMode])
|
if ([self isInFullScreenMode])
|
||||||
return [super constrainFrameRect:nf toScreen:screen];
|
return [super constrainFrameRect:nf toScreen:screen];
|
||||||
|
|
||||||
NSRect of = [self frame];
|
NSRect cf = [self frame];
|
||||||
NSRect vf = [[self screen] visibleFrame];
|
NSRect vf = [[self screen] visibleFrame];
|
||||||
|
|
||||||
if (NSMaxY(nf) > NSMaxY(vf)) {
|
// Prevent the window's titlebar from exiting the screen on the top edge.
|
||||||
// If the new window is bigger than the visible frame, make sure it's
|
// This introduces a 'snap to top' behaviour.
|
||||||
// titlebar is visible and at the top of the visible frame.
|
if (NSMaxY(nf) > NSMaxY(vf))
|
||||||
nf.origin.y = NSMaxY(vf) - NSHeight(nf);
|
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
|
// Prevent window from exiting the screen on the bottom edge
|
||||||
// previously (so we ran the previous conditional branch), recenter
|
if (NSMaxY(nf) < NSMinY(vf))
|
||||||
// the smaller window vertically.
|
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;
|
nf.origin.y = (NSHeight(vf) - NSHeight(nf)) / 2;
|
||||||
}
|
|
||||||
|
|
||||||
return nf;
|
return nf;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user