Skip to content

Commit 6128cf9

Browse files
committed
Remove fade-to-black animation for native/custom fullscreen
For native fullscreen, simply remove the custom animation as it doesn't look good and doesn't look native. This was added back when resizing the window rapidly would result in artifacts, but they should have all been fixed. As such, no need to hide everything under a black fade. For custom fullscreen, make it so that if `MMFullScreenFadeTime` is set to 0 (which is now the default), the fading animation will simply not be drawn as it simply flickers. Since it now defaults to 0, the user will have to manually set this back to 0.25 to get the old functionality, which is ok as it's somewhat a legacy feature anyway and there shouldn't be any flickering now during the transition. Also, update documentation on full-screen to provide more info on native vs custom, and clean up old outdated texts. Misc driveby fixes related to full screen: - Robustify the Touch Bar full screen button to listen to `OptionSet` event which is more robust than relying on `VimResized`, which also didn't work when 'fuoptions' is set to nothing. - Make MacVim handle the DidFailToEnter/ExitFullScreen events better. These events could fire when using native full screen while the user is e.g. switching space. We need to make sure to properly update the states when these two events happen and let Vim know what the current `'fullscreen'` state is so both sides are synced. - Fix up the preferences pane's full screen buttons to not trigger fontPropertiesChanged which was a mistake due to copy-and-paste in Interface Builder. See: - #292 / #289 which implemented the fade effect.
1 parent 38d2ba8 commit 6128cf9

7 files changed

Lines changed: 73 additions & 147 deletions

File tree

runtime/doc/gui_mac.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ this behaviour set MMLoginShellArgument to "--".
314314
==============================================================================
315315
4. MacVim appearance *macvim-appearance*
316316

317+
MacVim can be used in full screen mode, see 'fullscreen'.
318+
317319
*macvim-appearance-mode* *macvim-dark-mode*
318320
MacVim will by default use the system apperance mode (light or dark). However,
319321
you can manually force MacVim to use either light or dark mode in the

runtime/doc/options.txt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3580,27 +3580,30 @@ A jump table for the options with a short description can be found at |Q_op|.
35803580
(e.g. toolbar, title bar). The tab bar and scroll bars remain visible.
35813581
Updates to the window position are ignored in fullscreen mode.
35823582

3583+
By default, this will use macOS's native full screen feature, which
3584+
will put the MacVim window into another Space under Mission Control.
3585+
MacVim also provides a custom full screen solution which you can
3586+
select by setting |MMNativeFullScreen| to NO, or toggle it under
3587+
Preferences → Appearance. Under custom full-screen, the window will
3588+
not be put in another space, which makes it easier to Cmd-Tab to other
3589+
windows.
3590+
3591+
Custom / non-native full screen configuration:~
3592+
35833593
See 'fuoptions' for how Vim resizes and colors the background when
35843594
entering and leaving fullscreen mode.
35853595

3586-
You can use the hidden preference MMFullScreenFadeTime to adjust how
3587-
long the animation takes to fade in and out. The default is 0.25
3588-
seconds. See |macvim-preferences|for how to set hidden preferences.
3589-
3590-
Note: Setting 'fullscreen' usually changes the size of the Vim
3591-
control. However, for technical reasons, 'lines' and 'columns' will
3592-
currently only be updated when Vim runs its event loop. As a
3593-
consequence, if you set 'fullscreen' and 'lines' or 'columns' in a
3594-
Vim script file, you should always set 'fullscreen' after setting
3595-
'lines' and 'columns', else 'lines' and 'columns' will be overwritten
3596-
with the values 'fullscreen' sets after the script has been executed
3597-
and the event loop is ran again.
3598-
3599-
XXX: Add fuenter/fuleave autocommands? You might want to display
3600-
a NERDTree or a Tlist only in fullscreen for example. Then again, this
3601-
could probably be in a sizechanged autocommand that triggers if the
3602-
size is above a certain threshold.
3603-
XXX: Think about how 'fullscreen' and 'transparency' should interact.
3596+
There is an optional fade-to-black effect while transitioning that
3597+
could be turned on by using the hidden preference
3598+
|MMFullScreenFadeTime| (specified in seconds). It defaults to 0,
3599+
meaning this effect is turned off. Setting it to a positive value
3600+
(e.g. 0.25) will create an effect that fades to black during the full
3601+
screen transition to make it less jarring.
3602+
3603+
Note: While in 'fullscreen', you cannot set 'lines' or 'columns', as
3604+
they are determined by the size of the window. 'fuoptions' allows you
3605+
to override part of that behavior if using custom full screen.
3606+
36043607

36053608
*'fuoptions'* *'fuopt'*
36063609
'fuoptions' 'fuopt' string (default "maxvert,maxhorz")

runtime/menu.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,8 @@ if has("touchbar")
13831383
endfunc
13841384
aug FullScreenTouchBar
13851385
au!
1386-
au VimEnter,VimResized * call <SID>SetupFullScreenTouchBar()
1386+
au VimEnter * call <SID>SetupFullScreenTouchBar()
1387+
au OptionSet fullscreen call <SID>SetupFullScreenTouchBar()
13871388
aug END
13881389

13891390
" 2. Character (i.e. emojis) picker. Only in modes where user is actively

src/MacVim/Base.lproj/Preferences.xib

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,10 @@
342342
<font key="font" metaFont="system"/>
343343
</buttonCell>
344344
<connections>
345-
<action selector="fontPropertiesChanged:" target="-2" id="uaN-zX-Lvq"/>
346345
<binding destination="58" name="value" keyPath="values.MMNativeFullScreen" id="Y8t-au-n4b"/>
347346
</connections>
348347
</button>
349-
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="VAj-Yx-2uZ" userLabel="Full Sc">
348+
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="VAj-Yx-2uZ">
350349
<rect key="frame" x="-2" y="20" width="187" height="17"/>
351350
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
352351
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Full Screen:" id="bMQ-uG-iDR">
@@ -362,15 +361,14 @@
362361
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
363362
<font key="font" metaFont="system"/>
364363
<connections>
365-
<binding destination="58" name="enabled" keyPath="values.MMNativeFullScreen" id="Uw8-jM-9g1">
364+
<binding destination="58" name="enabled" keyPath="values.MMNativeFullScreen" id="YVo-6f-uND">
366365
<dictionary key="options">
367366
<string key="NSValueTransformerName">NSNegateBoolean</string>
368367
</dictionary>
369368
</binding>
370369
</connections>
371370
</buttonCell>
372371
<connections>
373-
<action selector="fontPropertiesChanged:" target="-2" id="1RM-UT-GNp"/>
374372
<binding destination="58" name="value" keyPath="values.MMNonNativeFullScreenShowMenu" id="5wX-jg-QPo"/>
375373
</connections>
376374
</button>

src/MacVim/MMAppController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ + (void)initialize
248248
#endif // INCLUDE_OLD_IM_CODE
249249
[NSNumber numberWithBool:NO], MMSuppressTerminationAlertKey,
250250
[NSNumber numberWithBool:YES], MMNativeFullScreenKey,
251-
[NSNumber numberWithDouble:0.25], MMFullScreenFadeTimeKey,
251+
[NSNumber numberWithDouble:0.0], MMFullScreenFadeTimeKey,
252252
[NSNumber numberWithBool:NO], MMNonNativeFullScreenShowMenuKey,
253253
[NSNumber numberWithBool:YES], MMShareFindPboardKey,
254254
nil];

src/MacVim/MMFullScreenWindow.m

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,12 @@ - (void)enterFullScreen
150150
// fade to black
151151
Boolean didBlend = NO;
152152
CGDisplayFadeReservationToken token;
153-
if (CGAcquireDisplayFadeReservation(fadeReservationTime, &token) == kCGErrorSuccess) {
154-
CGDisplayFade(token, fadeTime, kCGDisplayBlendNormal,
155-
kCGDisplayBlendSolidColor, .0, .0, .0, true);
156-
didBlend = YES;
153+
if (fadeTime > 0) {
154+
if (CGAcquireDisplayFadeReservation(fadeReservationTime, &token) == kCGErrorSuccess) {
155+
CGDisplayFade(token, fadeTime, kCGDisplayBlendNormal,
156+
kCGDisplayBlendSolidColor, .0, .0, .0, true);
157+
didBlend = YES;
158+
}
157159
}
158160

159161
// NOTE: The window may have moved to another screen in between init.. and
@@ -238,10 +240,12 @@ - (void)leaveFullScreen
238240
// fade to black
239241
Boolean didBlend = NO;
240242
CGDisplayFadeReservationToken token;
241-
if (CGAcquireDisplayFadeReservation(fadeReservationTime, &token) == kCGErrorSuccess) {
242-
CGDisplayFade(token, fadeTime, kCGDisplayBlendNormal,
243-
kCGDisplayBlendSolidColor, .0, .0, .0, true);
244-
didBlend = YES;
243+
if (fadeTime > 0) {
244+
if (CGAcquireDisplayFadeReservation(fadeReservationTime, &token) == kCGErrorSuccess) {
245+
CGDisplayFade(token, fadeTime, kCGDisplayBlendNormal,
246+
kCGDisplayBlendSolidColor, .0, .0, .0, true);
247+
didBlend = YES;
248+
}
245249
}
246250

247251
// restore old vim view size

src/MacVim/MMWindowController.m

Lines changed: 33 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)