[vlc-commits] macosx: only hide dock and menu bar when necessary

David Fuhrmann git at videolan.org
Sun Nov 18 13:21:46 CET 2012


vlc | branch: master | David Fuhrmann <david.fuhrmann at googlemail.com> | Sun Nov 18 11:59:58 2012 +0100| [784f47a244308736948a5e526357cfa094f359d8] | committer: David Fuhrmann

macosx: only hide dock and menu bar when necessary

Please note: For whatever reason, Cocoa only allows to hide the menu bar
when we also hide the dock. On the other hand, the dock can be hidden while
the menu bar stays visible.

close #4681

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=784f47a244308736948a5e526357cfa094f359d8
---

 modules/gui/macosx/Windows.m |   16 ++++++++++++----
 modules/gui/macosx/misc.h    |    4 ++--
 modules/gui/macosx/misc.m    |   25 ++++++++++++++++++++++---
 3 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/modules/gui/macosx/Windows.m b/modules/gui/macosx/Windows.m
index 6973b1d..67ab5d0 100644
--- a/modules/gui/macosx/Windows.m
+++ b/modules/gui/macosx/Windows.m
@@ -578,8 +578,12 @@
                 CGDisplayFade(token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
             }
 
-            if ([screen mainScreen])
-                [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
+            NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
+            if ([screen hasMenuBar])
+                presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
+            if ([screen hasMenuBar] || [screen hasDock])
+                presentationOpts |= NSApplicationPresentationAutoHideDock;
+            [NSApp setPresentationOptions:presentationOpts];
 
             [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
             [o_temp_view setFrame:[o_video_view frame]];
@@ -629,8 +633,12 @@
         [o_fullscreen_anim2 release];
     }
 
-    if ([screen mainScreen])
-        [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
+    NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
+    if ([screen hasMenuBar])
+        presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
+    if ([screen hasMenuBar] || [screen hasDock])
+        presentationOpts |= NSApplicationPresentationAutoHideDock;
+    [NSApp setPresentationOptions:presentationOpts];
 
     dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
     dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
diff --git a/modules/gui/macosx/misc.h b/modules/gui/macosx/misc.h
index 3520d3c..9d9767c 100644
--- a/modules/gui/macosx/misc.h
+++ b/modules/gui/macosx/misc.h
@@ -58,9 +58,9 @@
 
 @interface NSScreen (VLCAdditions)
 
- at property (readonly) BOOL mainScreen;
-
 + (NSScreen *)screenWithDisplayID: (CGDirectDisplayID)displayID;
+- (BOOL)hasMenuBar;
+- (BOOL)hasDock;
 - (BOOL)isScreen: (NSScreen*)screen;
 - (CGDirectDisplayID)displayID;
 - (void)blackoutOtherScreens;
diff --git a/modules/gui/macosx/misc.m b/modules/gui/macosx/misc.m
index 6c03a3b..ab6cbb5 100644
--- a/modules/gui/macosx/misc.m
+++ b/modules/gui/macosx/misc.m
@@ -183,11 +183,26 @@ static NSMutableArray *blackoutWindows = NULL;
     return nil;
 }
 
-- (BOOL)mainScreen
+- (BOOL)hasMenuBar
 {
     return ([self displayID] == [[[NSScreen screens] objectAtIndex:0] displayID]);
 }
 
+- (BOOL)hasDock
+{
+    NSRect screen_frame = [self frame];
+    NSRect screen_visible_frame = [self visibleFrame];
+    CGFloat f_menu_bar_thickness = [self hasMenuBar] ? [[NSStatusBar systemStatusBar] thickness] : 0.0;
+
+    BOOL b_found_dock = NO;
+    if (screen_visible_frame.size.width < screen_frame.size.width)
+        b_found_dock = YES;
+    else if (screen_visible_frame.size.height + f_menu_bar_thickness < screen_frame.size.height)
+        b_found_dock = YES;
+
+    return b_found_dock;
+}
+
 - (BOOL)isScreen: (NSScreen*)screen
 {
     return ([self displayID] == [screen displayID]);
@@ -231,8 +246,12 @@ static NSMutableArray *blackoutWindows = NULL;
         [blackoutWindows addObject: blackoutWindow];
         [blackoutWindow release];
 
-        if ( [screen mainScreen] )
-            [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
+        NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
+        if ([screen hasMenuBar])
+            presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
+        if ([screen hasMenuBar] || [screen hasDock])
+            presentationOpts |= NSApplicationPresentationAutoHideDock;
+        [NSApp setPresentationOptions:presentationOpts];
     }
 }
 



More information about the vlc-commits mailing list