@@ -292,13 +292,6 @@ - (void)cleanup
292292
293293 [[NSNotificationCenter defaultCenter ] removeObserver: self ];
294294
295- if (fullScreenEnabled) {
296- // If we are closed while still in full-screen, end full-screen mode,
297- // release ourselves (because this won't happen in MMWindowController)
298- // and perform close operation on the original window.
299- [self leaveFullScreen ];
300- }
301-
302295 vimController = nil ;
303296
304297 [vimView removeFromSuperviewWithoutNeedingDisplay ];
@@ -309,7 +302,7 @@ - (void)cleanup
309302 // dialog is displayed.
310303 [decoratedWindow setDocumentEdited: NO ];
311304
312- [[self window ] orderOut: self ];
305+ [[self window ] close ];
313306}
314307
315308- (void )openWindow
@@ -344,14 +337,6 @@ - (BOOL)presentWindow:(id)unused
344337
345338 [decoratedWindow makeKeyAndOrderFront: self ];
346339
347- // HACK! Calling makeKeyAndOrderFront: may cause Cocoa to force the window
348- // into native full-screen mode (this happens e.g. if a new window is
349- // opened when MacVim is already in full-screen). In this case we don't
350- // want the decorated window to pop up before the animation into
351- // full-screen, so set its alpha to 0.
352- if (fullScreenEnabled && !fullScreenWindow)
353- [decoratedWindow setAlphaValue: 0 ];
354-
355340 [decoratedWindow setBlurRadius: blurRadius];
356341
357342 // Flag that the window is now placed on screen. From now on it is OK for
@@ -368,9 +353,6 @@ - (BOOL)presentWindow:(id)unused
368353 fullScreenEnabled = YES ;
369354 shouldResizeVimView = YES ;
370355 } else if (delayEnterFullScreen) {
371- // Set alpha to zero so that the decorated window doesn't pop up
372- // before we enter full-screen.
373- [decoratedWindow setAlphaValue: 0 ];
374356 [self enterNativeFullScreen ];
375357 }
376358
@@ -932,14 +914,14 @@ - (void)enterFullScreen:(int)fuoptions backgroundColor:(NSColor *)back
932914
933915 fullScreenOptions = fuoptions;
934916 if (useNativeFullScreen) {
935- // Enter native full-screen mode. Only supported on Mac OS X 10.7+.
917+ // Enter native full-screen mode.
936918 if (windowPresented) {
937919 [self enterNativeFullScreen ];
938920 } else {
939921 delayEnterFullScreen = YES ;
940922 }
941923 } else {
942- // Enter custom full-screen mode. Always supported.
924+ // Enter custom full-screen mode.
943925 ASLogInfo (@" Enter custom full-screen" );
944926
945927 // fullScreenWindow could be non-nil here if this is called multiple
@@ -1380,46 +1362,6 @@ - (NSApplicationPresentationOptions)window:(NSWindow *)window
13801362 return opt | NSApplicationPresentationAutoHideToolbar;
13811363}
13821364
1383- - (NSArray *)customWindowsToEnterFullScreenForWindow : (NSWindow *)window
1384- {
1385- return [NSArray arrayWithObject: decoratedWindow];
1386- }
1387-
1388- - (void )window : (NSWindow *)window
1389- startCustomAnimationToEnterFullScreenWithDuration : (NSTimeInterval )duration
1390- {
1391- // Fade out window, remove title bar and maximize, then fade back in.
1392- // (There is a small delay before window is maximized but usually this is
1393- // not noticeable on a relatively modern Mac.)
1394-
1395- // Fade out
1396- [NSAnimationContext runAnimationGroup: ^(NSAnimationContext *context) {
1397- [context setDuration: 0.5 *duration];
1398- [[window animator ] setAlphaValue: 0 ];
1399- } completionHandler: ^{
1400- [window setStyleMask: ([window styleMask ] | NSWindowStyleMaskFullScreen)];
1401- NSString *tabBarStyle = [[self class ] tabBarStyleForUnified ];
1402- [[vimView tabBarControl ] setStyleNamed: tabBarStyle];
1403- [self updateTablineSeparator ];
1404-
1405- // Stay dark for some time to wait for things to sync, then do the full screen operation
1406- [NSAnimationContext runAnimationGroup: ^(NSAnimationContext *context) {
1407- [context setDuration: 0.5 *duration];
1408- [[window animator ] setAlphaValue: 0 ];
1409- } completionHandler: ^{
1410- [self maximizeWindow: fullScreenOptions];
1411-
1412- // Fade in
1413- [NSAnimationContext runAnimationGroup: ^(NSAnimationContext *context) {
1414- [context setDuration: 0.5 *duration];
1415- [[window animator ] setAlphaValue: 1 ];
1416- } completionHandler: ^{
1417- // Do nothing
1418- }];
1419- }];
1420- }];
1421- }
1422-
14231365- (void )windowWillEnterFullScreen : (NSNotification *)notification
14241366{
14251367 // Store window frame and use it when exiting full-screen.
@@ -1455,67 +1397,32 @@ - (void)windowDidEnterFullScreen:(NSNotification *)notification
14551397 // when titlebar is configured as hidden. Simply re-assert it to make sure
14561398 // text is still focused.
14571399 [decoratedWindow makeFirstResponder: [vimView textView ]];
1400+
1401+ if (!fullScreenEnabled) {
1402+ // In case for some odd sequence of events (e.g. getting a
1403+ // windowDidFailToEnterFullScreen, then this call), if we have
1404+ // mismatched state, just reset it back to the correct one.
1405+ fullScreenEnabled = YES ;
1406+ [vimController addVimInput: @" <C-\\ ><C-N>:set fu<CR>" ];
1407+ }
14581408}
14591409
14601410- (void )windowDidFailToEnterFullScreen : (NSWindow *)window
14611411{
1462- // NOTE: This message can be called without
1463- // window:startCustomAnimationToEnterFullScreenWithDuration: ever having
1464- // been called so any state to store before entering full-screen must be
1465- // stored in windowWillEnterFullScreen: which always gets called.
14661412 ASLogNotice (@" Failed to ENTER full-screen, restoring window frame..." );
14671413
14681414 fullScreenEnabled = NO ;
1469- [window setAlphaValue: 1 ];
1470- [window setStyleMask: ([window styleMask ] & ~NSWindowStyleMaskFullScreen)];
1471- NSString *tabBarStyle = [[self class ] tabBarStyleForMetal ];
1472- [[vimView tabBarControl ] setStyleNamed: tabBarStyle];
1473- [self updateTablineSeparator ];
14741415 [window setFrame: preFullScreenFrame display: YES ];
14751416
14761417 // Sometimes full screen will de-focus the text view. This seems to happen
14771418 // when titlebar is configured as hidden. Simply re-assert it to make sure
14781419 // text is still focused.
14791420 [decoratedWindow makeFirstResponder: [vimView textView ]];
1480- }
1481-
1482- - (NSArray *)customWindowsToExitFullScreenForWindow : (NSWindow *)window
1483- {
1484- return [NSArray arrayWithObject: decoratedWindow];
1485- }
1486-
1487- - (void )window : (NSWindow *)window
1488- startCustomAnimationToExitFullScreenWithDuration : (NSTimeInterval )duration
1489- {
1490- if (!setupDone) {
1491- // HACK! The window has closed but Cocoa still brings it back to life
1492- // and shows a grey box the size of the window unless we explicitly
1493- // hide it by setting its alpha to 0 here.
1494- [window setAlphaValue: 0 ];
1495- return ;
1496- }
14971421
1498- // Fade out window, add back title bar and restore window frame, then fade
1499- // back in. (There is a small delay before window contents is drawn after
1500- // the window frame is set but usually this is not noticeable on a
1501- // relatively modern Mac.)
1502- [NSAnimationContext runAnimationGroup: ^(NSAnimationContext *context) {
1503- [context setDuration: 0.5 *duration];
1504- [[window animator ] setAlphaValue: 0 ];
1505- } completionHandler: ^{
1506- [window setStyleMask: ([window styleMask ] & ~NSWindowStyleMaskFullScreen)];
1507- NSString *tabBarStyle = [[self class ] tabBarStyleForMetal ];
1508- [[vimView tabBarControl ] setStyleNamed: tabBarStyle];
1509- [self updateTablineSeparator ];
1510- [window setFrame: preFullScreenFrame display: YES ];
1511-
1512- [NSAnimationContext runAnimationGroup: ^(NSAnimationContext *context) {
1513- [context setDuration: 0.5 *duration];
1514- [[window animator ] setAlphaValue: 1 ];
1515- } completionHandler: ^{
1516- // Do nothing
1517- }];
1518- }];
1422+ // Vim needs to be told that it's no longer in full screen. Because we
1423+ // already set fullScreenEnabled=NO, this won't do anything other than
1424+ // updating Vim's state.
1425+ [vimController addVimInput: @" <C-\\ ><C-N>:set nofu<CR>" ];
15191426}
15201427
15211428- (void )windowWillExitFullScreen : (NSNotification *)notification
@@ -1546,26 +1453,33 @@ - (void)windowDidExitFullScreen:(NSNotification *)notification
15461453 // when titlebar is configured as hidden. Simply re-assert it to make sure
15471454 // text is still focused.
15481455 [decoratedWindow makeFirstResponder: [vimView textView ]];
1456+
1457+ if (fullScreenEnabled) {
1458+ // Sometimes macOS will first send a windowDidFailToExitFullScreen
1459+ // notification (e.g. if user is in the middle of switching spaces)
1460+ // before actually sending windowDidExitFullScreen. Just to be safe, if
1461+ // we are actually confused here, simply reset the state back.
1462+ fullScreenEnabled = NO ;
1463+ [vimController addVimInput: @" <C-\\ ><C-N>:set nofu<CR>" ];
1464+ }
15491465}
15501466
15511467- (void )windowDidFailToExitFullScreen : (NSWindow *)window
15521468{
1553- // TODO: Is this the correct way to deal with this message? Are we still
1554- // in full-screen at this point?
15551469 ASLogNotice (@" Failed to EXIT full-screen, maximizing window..." );
15561470
15571471 fullScreenEnabled = YES ;
1558- [window setAlphaValue: 1 ];
1559- [window setStyleMask: ([window styleMask ] | NSWindowStyleMaskFullScreen)];
1560- NSString *tabBarStyle = [[self class ] tabBarStyleForUnified ];
1561- [[vimView tabBarControl ] setStyleNamed: tabBarStyle];
1562- [self updateTablineSeparator ];
15631472 [self maximizeWindow: fullScreenOptions];
15641473
15651474 // Sometimes full screen will de-focus the text view. This seems to happen
15661475 // when titlebar is configured as hidden. Simply re-assert it to make sure
15671476 // text is still focused.
15681477 [decoratedWindow makeFirstResponder: [vimView textView ]];
1478+
1479+ // Vim needs to be told that it's still in full screen. Because we already
1480+ // set fullScreenEnabled=YES, this won't do anything other than updating
1481+ // Vim's state.
1482+ [vimController addVimInput: @" <C-\\ ><C-N>:set fu<CR>" ];
15691483}
15701484
15711485#endif // (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
@@ -1868,6 +1782,10 @@ - (void)updateToolbar
18681782
18691783- (BOOL )maximizeWindow : (int )options
18701784{
1785+ // Note:
1786+ // This is deprecated code and will be removed later. 'fuopt' should be
1787+ // handled in processInputQueueDidFinish instead.
1788+
18711789 if (floor (NSAppKitVersionNumber ) > NSAppKitVersionNumber10_10_Max ) {
18721790 // NOTE: Prevent to resize the window in Split View on El Capitan or
18731791 // later.
0 commit comments