Skip to content

Commit 479629e

Browse files
committed
Fix non-native fullscreen not hiding menu/dock in secondary screens
Previously non-native full scrren mode would only hide the menu bar and dock when used in the primary screen. This made sense in 10.7 Lion because only the primary screen would have the menu/dock. However, 10.9 Mavericks introduced a new default where each screen would now have its own space, and therefore menu bar and dock. Make non-native full screen mode aware of this and make sure to hide the menu bar and dock when it needs to. Fix #7.
1 parent afeb743 commit 479629e

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

src/MacVim/MMFullScreenWindow.m

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#import "MMVimView.h"
3030
#import "MMWindowController.h"
3131
#import "Miscellaneous.h"
32-
#import <Carbon/Carbon.h>
3332
#import <PSMTabBarControl/PSMTabBarControl.h>
3433

3534
// These have to be the same as in option.h
@@ -47,6 +46,7 @@
4746

4847
@interface MMFullScreenWindow (Private)
4948
- (BOOL)isOnPrimaryScreen;
49+
- (BOOL)screenHasDockAndMenu;
5050
- (void)windowDidBecomeMain:(NSNotification *)notification;
5151
- (void)windowDidResignMain:(NSNotification *)notification;
5252
- (void)windowDidMove:(NSNotification *)notification;
@@ -137,10 +137,12 @@ - (void)enterFullScreen
137137
{
138138
ASLogDebug(@"Enter full-screen now");
139139

140-
// Hide Dock and menu bar now to avoid the hide animation from playing
141-
// after the fade to black (see also windowDidBecomeMain:).
142-
if ([self isOnPrimaryScreen])
143-
SetSystemUIMode(kUIModeAllSuppressed, 0);
140+
// Hide Dock and menu bar when going to full screen. Only do so if the current screen
141+
// has a menu bar and dock.
142+
if ([self screenHasDockAndMenu]) {
143+
[NSApplication sharedApplication].presentationOptions =
144+
NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar;
145+
}
144146

145147
// fade to black
146148
Boolean didBlend = NO;
@@ -441,32 +443,38 @@ - (BOOL)isOnPrimaryScreen
441443
if (screens == nil || [screens count] < 1)
442444
return NO;
443445

444-
return [self screen] == [screens objectAtIndex:0];
446+
NSScreen* primaryScreen = [screens objectAtIndex:0];
447+
448+
// We cannot compare the NSScreen pointers directly because they are not
449+
// guaranteed to match. Instead use the screen number as a more canonical
450+
// way to compare them.
451+
NSNumber* primaryScreenNum = primaryScreen.deviceDescription[@"NSScreenNumber"];
452+
NSNumber* selfScreenNum = [self screen].deviceDescription[@"NSScreenNumber"];
453+
return selfScreenNum == primaryScreenNum;
445454
}
446455

447-
- (void)windowDidBecomeMain:(NSNotification *)notification
456+
- (BOOL)screenHasDockAndMenu
448457
{
449-
// Hide menu and dock, both appear on demand.
450-
//
451-
// Another way to deal with several full-screen windows would be to hide/
452-
// reveal the dock only when the first full-screen window is created and
453-
// show it again after the last one has been closed, but toggling on each
454-
// focus gain/loss works better with Spaces. The downside is that the
455-
// menu bar flashes shortly when switching between two full-screen windows.
456-
457-
// XXX: If you have a full-screen window on a secondary monitor and unplug
458-
// the monitor, this will probably not work right.
458+
return NSScreen.screensHaveSeparateSpaces || [self isOnPrimaryScreen];
459+
}
459460

460-
if ([self isOnPrimaryScreen]) {
461-
SetSystemUIMode(kUIModeAllSuppressed, 0); //requires 10.3
461+
- (void)windowDidBecomeMain:(NSNotification *)notification
462+
{
463+
// Hide menu and dock when this window gets focus.
464+
if ([self screenHasDockAndMenu]) {
465+
[NSApplication sharedApplication].presentationOptions =
466+
NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar;
462467
}
463468
}
464469

470+
465471
- (void)windowDidResignMain:(NSNotification *)notification
466472
{
467-
// order menu and dock back in
468-
if ([self isOnPrimaryScreen]) {
469-
SetSystemUIMode(kUIModeNormal, 0);
473+
// Un-hide menu/dock when we lose focus. This makes sure if we have multiple
474+
// windows opened, when the non-fullscreen windows get focus they will have the
475+
// dock and menu showing (since presentationOptions is per-app, not per-window).
476+
if ([self screenHasDockAndMenu]) {
477+
[NSApplication sharedApplication].presentationOptions = NSApplicationPresentationDefault;
470478
}
471479
}
472480

0 commit comments

Comments
 (0)