From 57571b5da3dde82816f5ed7f4371dd7670e55565 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 1 Jun 2013 22:52:21 +0200 Subject: cocoa_common: autohide dock/menubar on fs only if on same screen Autohide the menubar and/or dock only if they are present in the screen the player is going to go fullscreen into. I thought the GUI would handle this for me when I switched 0057aa476 but lack of hardware to test made me embarass myself yet again. I reimplemented this feature with nicer code and behaviour. The code checks separately wether to hide menubar and dock separatly, while the old code used a single check possibly hiding stuff without need. Added the key checks as a some category additions to NSScreen for readability. --- video/out/cocoa_common.m | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index d74f508523..28dbf58923 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -74,6 +74,11 @@ static bool RightAltPressed(NSEvent *event) @property(nonatomic, assign, getter=hasMouseDown) BOOL mouseDown; @end +@interface NSScreen (mpvadditions) +- (BOOL)hasDock; +- (BOOL)hasMenubar; +@end + struct vo_cocoa_input_queue { NSMutableArray *fifo; }; @@ -686,14 +691,19 @@ int vo_cocoa_cgl_color_size(struct vo *vo) struct vo_cocoa_state *s = self.videoOutput->cocoa; if (willBeFullscreen) { + NSApplicationPresentationOptions popts = + NSApplicationPresentationDefault; + + if ([s->fs_screen hasMenubar]) + popts |= NSApplicationPresentationAutoHideMenuBar; + + if ([s->fs_screen hasDock]) + popts |= NSApplicationPresentationAutoHideDock; + NSDictionary *fsopts = @{ - NSFullScreenModeWindowLevel : - @(NSFloatingWindowLevel), - NSFullScreenModeAllScreens : - @NO, - NSFullScreenModeApplicationPresentationOptions : - @(NSApplicationPresentationAutoHideDock | - NSApplicationPresentationAutoHideMenuBar) + NSFullScreenModeWindowLevel : @(NSFloatingWindowLevel), + NSFullScreenModeAllScreens : @NO, + NSFullScreenModeApplicationPresentationOptions : @(popts) }; [s->view enterFullScreenMode:s->fs_screen withOptions:fsopts]; @@ -999,3 +1009,23 @@ int vo_cocoa_cgl_color_size(struct vo *vo) } } @end + +@implementation NSScreen (mpvadditions) +- (BOOL)hasDock +{ + NSRect vF = [self visibleFrame]; + NSRect f = [self frame]; + return + // The visible frame's width is smaller: dock is on left or right end + // of this method's receiver. + vF.size.width < f.size.width || + // The visible frame's veritical origin is bigger is smaller: dock is + // on the bottom of this method's receiver. + vF.origin.y > f.origin.y; + +} +- (BOOL)hasMenubar +{ + return [self isEqual: [NSScreen screens][0]]; +} +@end -- cgit v1.2.3