|
29 | 29 | #import "MMVimView.h" |
30 | 30 | #import "MMWindowController.h" |
31 | 31 | #import "Miscellaneous.h" |
32 | | -#import <Carbon/Carbon.h> |
33 | 32 | #import <PSMTabBarControl/PSMTabBarControl.h> |
34 | 33 |
|
35 | 34 | // These have to be the same as in option.h |
|
47 | 46 |
|
48 | 47 | @interface MMFullScreenWindow (Private) |
49 | 48 | - (BOOL)isOnPrimaryScreen; |
| 49 | +- (BOOL)screenHasDockAndMenu; |
50 | 50 | - (void)windowDidBecomeMain:(NSNotification *)notification; |
51 | 51 | - (void)windowDidResignMain:(NSNotification *)notification; |
52 | 52 | - (void)windowDidMove:(NSNotification *)notification; |
@@ -137,10 +137,12 @@ - (void)enterFullScreen |
137 | 137 | { |
138 | 138 | ASLogDebug(@"Enter full-screen now"); |
139 | 139 |
|
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 | + } |
144 | 146 |
|
145 | 147 | // fade to black |
146 | 148 | Boolean didBlend = NO; |
@@ -441,32 +443,38 @@ - (BOOL)isOnPrimaryScreen |
441 | 443 | if (screens == nil || [screens count] < 1) |
442 | 444 | return NO; |
443 | 445 |
|
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; |
445 | 454 | } |
446 | 455 |
|
447 | | -- (void)windowDidBecomeMain:(NSNotification *)notification |
| 456 | +- (BOOL)screenHasDockAndMenu |
448 | 457 | { |
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 | +} |
459 | 460 |
|
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; |
462 | 467 | } |
463 | 468 | } |
464 | 469 |
|
| 470 | + |
465 | 471 | - (void)windowDidResignMain:(NSNotification *)notification |
466 | 472 | { |
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; |
470 | 478 | } |
471 | 479 | } |
472 | 480 |
|
|
0 commit comments