Skip to content

Commit

Permalink
MMTabline: Add ability to turn off animation
Browse files Browse the repository at this point in the history
This is not exposed in the user preference pane, as it should be a niche
case, but it's useful to have a way to turn off animations for either
accessibility or user preferences reasons.
  • Loading branch information
ychin committed Jan 29, 2025
1 parent 2745806 commit 18f00e5
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions runtime/doc/gui_mac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ KEY VALUE ~
*MMDialogsTrackPwd* open/save dialogs track the Vim pwd [bool]
*MMDisableLaunchAnimation* disable launch animation when opening a new
MacVim window [bool]
*MMDisableTablineAnimation* disable animation in GUI tabs [bool]
*MMFontPreserveLineSpacing* use the line-spacing as specified by font [bool]
*MMLoginShell* use login shell for launching Vim [bool]
*MMLoginShellArgument* login shell parameter [string]
Expand Down
1 change: 1 addition & 0 deletions runtime/doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -5648,6 +5648,7 @@ MMCmdLineAlignBottom gui_mac.txt /*MMCmdLineAlignBottom*
MMDefaultTablineColors gui_mac.txt /*MMDefaultTablineColors*
MMDialogsTrackPwd gui_mac.txt /*MMDialogsTrackPwd*
MMDisableLaunchAnimation gui_mac.txt /*MMDisableLaunchAnimation*
MMDisableTablineAnimation gui_mac.txt /*MMDisableTablineAnimation*
MMFontPreserveLineSpacing gui_mac.txt /*MMFontPreserveLineSpacing*
MMFullScreenFadeTime gui_mac.txt /*MMFullScreenFadeTime*
MMLoginShell gui_mac.txt /*MMLoginShell*
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MMAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ + (void)registerDefaults
MMUntitledWindowKey,
[NSNumber numberWithBool:NO], MMNoWindowShadowKey,
[NSNumber numberWithBool:NO], MMDisableLaunchAnimationKey,
[NSNumber numberWithBool:NO], MMDisableTablineAnimationKey,
[NSNumber numberWithInt:0], MMAppearanceModeSelectionKey,
[NSNumber numberWithBool:NO], MMNoTitleBarWindowKey,
[NSNumber numberWithBool:NO], MMTitlebarAppearsTransparentKey,
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MMTabline/MMTabline.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@property (nonatomic) NSInteger minimumTabWidth;
@property (nonatomic) BOOL showsAddTabButton;
@property (nonatomic) BOOL showsTabScrollButtons;
@property (nonatomic) BOOL useAnimation;
@property (nonatomic, readonly) NSInteger numberOfTabs;
@property (nonatomic, retain, readonly) MMHoverButton *addTabButton;
@property (nonatomic, retain) NSColor *tablineBgColor;
Expand Down
16 changes: 12 additions & 4 deletions src/MacVim/MMTabline/MMTabline.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ - (instancetype)initWithFrame:(NSRect)frameRect
_tabs = [NSMutableArray new];
_showsAddTabButton = YES; // get from NSUserDefaults
_showsTabScrollButtons = YES; // get from NSUserDefaults
_useAnimation = YES; // get from NSUserDefaults

_selectedTabIndex = -1;

Expand Down Expand Up @@ -624,6 +625,9 @@ - (void)fixupTabZOrder

- (void)fixupLayoutWithAnimation:(BOOL)shouldAnimate delayResize:(BOOL)delayResize
{
if (!self.useAnimation)
shouldAnimate = NO;

if (_tabs.count == 0) {
NSRect frame = _tabsContainer.frame;
frame.size.width = 0;
Expand Down Expand Up @@ -859,10 +863,14 @@ - (void)scrollTabToVisibleAtIndex:(NSInteger)index
// Left side of the selected tab is clipped.
clipBounds.origin.x = tabFrame.origin.x;
}
[NSAnimationContext beginGrouping];
[NSAnimationContext.currentContext setDuration:elapsedTime < 0.2 ? 0.05 : 0.2];
[_scrollView.contentView.animator setBoundsOrigin:clipBounds.origin];
[NSAnimationContext endGrouping];
if (_useAnimation) {
[NSAnimationContext beginGrouping];
[NSAnimationContext.currentContext setDuration:elapsedTime < 0.2 ? 0.05 : 0.2];
[_scrollView.contentView.animator setBoundsOrigin:clipBounds.origin];
[NSAnimationContext endGrouping];
} else {
[_scrollView.contentView setBoundsOrigin:clipBounds.origin];
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MMVimView.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ - (MMVimView *)initWithFrame:(NSRect)frame
tabline.hidden = YES;
tabline.showsAddTabButton = [ud boolForKey:MMShowAddTabButtonKey];
tabline.showsTabScrollButtons = [ud boolForKey:MMShowTabScrollButtonsKey];
tabline.useAnimation = ![ud boolForKey:MMDisableTablineAnimationKey];
tabline.optimumTabWidth = [ud integerForKey:MMTabOptimumWidthKey];
tabline.minimumTabWidth = [ud integerForKey:MMTabMinWidthKey];
tabline.addTabButton.target = self;
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/Miscellaneous.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extern NSString *MMTitlebarAppearsTransparentKey;
extern NSString *MMTitlebarShowsDocumentIconKey;
extern NSString *MMNoWindowShadowKey;
extern NSString *MMDisableLaunchAnimationKey;
extern NSString *MMDisableTablineAnimationKey;
extern NSString *MMLoginShellKey;
extern NSString *MMUntitledWindowKey;
extern NSString *MMZoomBothKey;
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/Miscellaneous.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
NSString *MMTitlebarShowsDocumentIconKey = @"MMTitlebarShowsDocumentIcon";
NSString *MMNoWindowShadowKey = @"MMNoWindowShadow";
NSString *MMDisableLaunchAnimationKey = @"MMDisableLaunchAnimation";
NSString *MMDisableTablineAnimationKey = @"MMDisableTablineAnimation";
NSString *MMLoginShellKey = @"MMLoginShell";
NSString *MMUntitledWindowKey = @"MMUntitledWindow";
NSString *MMZoomBothKey = @"MMZoomBoth";
Expand Down

0 comments on commit 18f00e5

Please sign in to comment.