Skip to content

Commit b7717d5

Browse files
authored
Merge pull request #1566 from ychin/mouse-wheel-disable-acceleration
Add better scroll wheel support and option to disable acceleration
2 parents 4af6e9a + 95a3120 commit b7717d5

File tree

7 files changed

+102
-18
lines changed

7 files changed

+102
-18
lines changed

runtime/doc/gui_mac.txt

+11-4
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ as general information regarding macOS user defaults.
283283
Here is a list of relevant dictionary entries:
284284

285285
KEY VALUE ~
286-
*MMAllowForceClickLookUp* use Force click for data lookup instead of
287-
<ForceClick> [bool]
288286
*MMCellWidthMultiplier* width of a normal glyph in em units [float]
289287
*MMCmdLineAlignBottom* Pin command-line to bottom of MacVim [bool]
290288
*MMDialogsTrackPwd* open/save dialogs track the Vim pwd [bool]
@@ -307,7 +305,6 @@ KEY VALUE ~
307305
*MMTitlebarAppearsTransparent* enable a transparent titlebar [bool]
308306
*MMAppearanceModeSelection* dark mode selection (|macvim-dark-mode|)[bool]
309307
*MMRendererClipToRow* clip tall characters to the row they are on [bool]
310-
*MMScrollOneDirectionOnly* scroll along one axis only when using trackpad [bool]
311308
*MMSmoothResize* allow smooth resizing of MacVim window [bool]
312309
*MMShareFindPboard* share search text to Find Pasteboard [bool]
313310
*MMTextInsetBottom* text area offset in pixels [int]
@@ -316,12 +313,22 @@ KEY VALUE ~
316313
*MMTextInsetTop* text area offset in pixels [int]
317314
*MMTexturedWindow* use brushed metal window (Tiger only) [bool]
318315
*MMTranslateCtrlClick* interpret ctrl-click as right-click [bool]
319-
*MMUseMouseTime* use mousetime to detect multiple clicks [bool]
320316
*MMVerticalSplit* files open in vertical splits [bool]
321317
*MMZoomBoth* zoom button maximizes both directions [bool]
322318
*MMUpdaterPrereleaseChannel* opt-in to pre-release software update [bool]
323319
*MMShowWhatsNewOnStartup* show "What's New" after updating to new version [bool]
324320

321+
Mouse / Trackpad ~
322+
*MMScrollOneDirectionOnly* scroll along one axis only when using trackpad [bool]
323+
*MMAllowForceClickLookUp* use Force click for data lookup instead of
324+
<ForceClick> [bool]
325+
*MMMouseWheelDisableAcceleration* disable OS scroll wheel acceleration [bool]
326+
*MMMouseWheelNumLines* how many lines to scroll when scroll wheel
327+
acceleration is turned off [int]
328+
*MMMouseWheelMinLines* min number of lines to scroll per scroll wheel
329+
click when acceleration is on [int]
330+
*MMUseMouseTime* use mousetime to detect multiple clicks [bool]
331+
325332
Tabs ~
326333
*MMTabColorsMode* use default/auto/colorscheme for tab colors [int]
327334
*MMWindowUseTabBackgroundColor* use tabs background fill color as window color [bool]

runtime/doc/tags

+3
Original file line numberDiff line numberDiff line change
@@ -5654,6 +5654,9 @@ MMFullScreenFadeTime gui_mac.txt /*MMFullScreenFadeTime*
56545654
MMLoginShell gui_mac.txt /*MMLoginShell*
56555655
MMLoginShellArgument gui_mac.txt /*MMLoginShellArgument*
56565656
MMLoginShellCommand gui_mac.txt /*MMLoginShellCommand*
5657+
MMMouseWheelDisableAcceleration gui_mac.txt /*MMMouseWheelDisableAcceleration*
5658+
MMMouseWheelMinLines gui_mac.txt /*MMMouseWheelMinLines*
5659+
MMMouseWheelNumLines gui_mac.txt /*MMMouseWheelNumLines*
56575660
MMNativeFullScreen gui_mac.txt /*MMNativeFullScreen*
56585661
MMNoFontSubstitution gui_mac.txt /*MMNoFontSubstitution*
56595662
MMNoTitleBarWindow gui_mac.txt /*MMNoTitleBarWindow*

src/MacVim/Base.lproj/Preferences.xib

+42-5
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,11 @@
573573
<point key="canvasLocation" x="137.5" y="478.5"/>
574574
</customView>
575575
<customView id="Bnq-Nx-GJH" userLabel="Input">
576-
<rect key="frame" x="0.0" y="0.0" width="483" height="110"/>
576+
<rect key="frame" x="0.0" y="0.0" width="483" height="155"/>
577577
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
578578
<subviews>
579579
<customView id="DAP-Yi-QU0" userLabel="Trackpad">
580-
<rect key="frame" x="20" y="72" width="433" height="18"/>
580+
<rect key="frame" x="20" y="117" width="433" height="18"/>
581581
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
582582
<subviews>
583583
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="f18-Wr-EgZ">
@@ -604,11 +604,11 @@
604604
</subviews>
605605
</customView>
606606
<customView id="GZa-RH-fza" userLabel="Mouse">
607-
<rect key="frame" x="20" y="46" width="433" height="18"/>
607+
<rect key="frame" x="20" y="46" width="433" height="63"/>
608608
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
609609
<subviews>
610610
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="3Tx-8j-zQR">
611-
<rect key="frame" x="-2" y="0.0" width="187" height="17"/>
611+
<rect key="frame" x="-2" y="45" width="187" height="17"/>
612612
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
613613
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Mouse:" id="imK-Tr-YuD">
614614
<font key="font" metaFont="system"/>
@@ -617,7 +617,7 @@
617617
</textFieldCell>
618618
</textField>
619619
<button id="RLs-2Z-8PJ" userLabel="Ctrl-click as right-click">
620-
<rect key="frame" x="189" y="-1" width="199" height="18"/>
620+
<rect key="frame" x="189" y="44" width="199" height="18"/>
621621
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
622622
<buttonCell key="cell" type="check" title="Treat Ctrl-click as right-click" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="PYG-cd-wzL" userLabel="Ctrl-click as right-click">
623623
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
@@ -627,6 +627,43 @@
627627
<binding destination="58" name="value" keyPath="values.MMTranslateCtrlClick" id="ZMh-R3-AYN"/>
628628
</connections>
629629
</button>
630+
<button id="8rY-bA-ZQt">
631+
<rect key="frame" x="189" y="26" width="224" height="18"/>
632+
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
633+
<buttonCell key="cell" type="check" title="Disable scroll wheel acceleration" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="fRx-Gy-P0M">
634+
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
635+
<font key="font" metaFont="system"/>
636+
</buttonCell>
637+
<connections>
638+
<binding destination="58" name="value" keyPath="values.MMMouseWheelDisbleAcceleration" id="899-jt-taC"/>
639+
</connections>
640+
</button>
641+
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="SqW-DB-w7i">
642+
<rect key="frame" x="210" y="3" width="109" height="17"/>
643+
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
644+
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="left" title="Lines to scroll:" id="w03-Ox-2xg">
645+
<font key="font" metaFont="system"/>
646+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
647+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
648+
</textFieldCell>
649+
<connections>
650+
<binding destination="58" name="enabled" keyPath="values.MMMouseWheelDisbleAcceleration" id="Mzw-pC-FbR"/>
651+
</connections>
652+
</textField>
653+
<textField focusRingType="none" verticalHuggingPriority="750" id="Zpw-eU-7d1">
654+
<rect key="frame" x="305" y="1" width="32" height="21"/>
655+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
656+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="Vwr-3s-VFd">
657+
<numberFormatter key="formatter" formatterBehavior="default10_4" numberStyle="decimal" formatWidth="-1" minimumIntegerDigits="1" maximumIntegerDigits="2000000000" maximumFractionDigits="3" id="NEj-vx-0Qo"/>
658+
<font key="font" metaFont="system"/>
659+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
660+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
661+
</textFieldCell>
662+
<connections>
663+
<binding destination="58" name="enabled" keyPath="values.MMMouseWheelDisbleAcceleration" id="i3X-ti-Cv8"/>
664+
<binding destination="58" name="value" keyPath="values.MMMouseWheelNumLines" id="ecJ-lb-ghs"/>
665+
</connections>
666+
</textField>
630667
</subviews>
631668
</customView>
632669
<customView id="aUx-jX-mJJ" userLabel="Scrolling">

src/MacVim/MMAppController.m

+3
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ + (void)registerDefaults
217217
[NSNumber numberWithBool:YES], MMUseInlineImKey,
218218
#endif // INCLUDE_OLD_IM_CODE
219219
[NSNumber numberWithBool:NO], MMSuppressTerminationAlertKey,
220+
[NSNumber numberWithBool:NO], MMMouseWheelDisableAccelerationKey,
221+
[NSNumber numberWithInt:1], MMMouseWheelMinLinesKey,
222+
[NSNumber numberWithInt:3], MMMouseWheelNumLinesKey,
220223
[NSNumber numberWithBool:YES], MMNativeFullScreenKey,
221224
[NSNumber numberWithDouble:0.0], MMFullScreenFadeTimeKey,
222225
[NSNumber numberWithBool:NO], MMNonNativeFullScreenShowMenuKey,

src/MacVim/MMTextViewHelper.m

+36-8
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,15 @@ - (void)doCommandBySelector:(SEL)sel
312312
else interpretKeyEventsSwallowedKey = NO;
313313
}
314314

315-
- (void)scrollWheel:(NSEvent *)event
315+
- (void)calcScrollWheelDeltas:(NSEvent *)event x:(float *)x y:(float *)y eventFlags:(NSEventModifierFlags*)eventFlags
316316
{
317317
float dx = 0;
318318
float dy = 0;
319319

320-
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
320+
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
321+
321322
if ([event hasPreciseScrollingDeltas]) {
322323
const NSEventPhase phase = event.phase;
323-
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
324324

325325
CGFloat eventScrollingDeltaX = event.scrollingDeltaX;
326326
CGFloat eventScrollingDeltaY = event.scrollingDeltaY;
@@ -366,12 +366,40 @@ - (void)scrollWheel:(NSEvent *)event
366366
scrollingDeltaY = 0;
367367
dx = [event scrollingDeltaX];
368368
dy = [event scrollingDeltaY];
369+
370+
if ([ud boolForKey:MMMouseWheelDisableAccelerationKey]) {
371+
// Use scroll wheel as discrete steps as macOS acceleration often
372+
// leads to unintuitive results.
373+
NSInteger numLines = [ud integerForKey:MMMouseWheelNumLinesKey];
374+
dx = dx == 0 ? 0 : (dx > 0 ? numLines : -numLines);
375+
dy = dy == 0 ? 0 : (dy > 0 ? numLines : -numLines);
376+
} else {
377+
// Use the default OS acceleration, but we still want to round up
378+
// the delta to at least 1 (configurable) as otherwise it's
379+
// frustrating to use as MacVim fails to scroll even one line.
380+
NSInteger minScrollLines = [ud integerForKey:MMMouseWheelMinLinesKey];
381+
dx = dx == 0 ? 0 : (fabs(dx) > minScrollLines ? dx : (dx > 0 ? minScrollLines : -minScrollLines));
382+
dy = dy == 0 ? 0 : (fabs(dy) > minScrollLines ? dy : (dy > 0 ? minScrollLines : -minScrollLines));
383+
}
384+
385+
if ((*eventFlags & NSEventModifierFlagShift) && dx != 0 && dy == 0) {
386+
// A shift-scroll in macOS converts a normal Y to X-axis scroll.
387+
// There is no proper API to query this so this is just done by
388+
// heuristics. We need to remove the shift flag, or Vim would see
389+
// this as a <S-ScrollWheelRight> which is not what we want.
390+
*eventFlags = *eventFlags & (~NSEventModifierFlagShift);
391+
}
369392
}
370-
#else
371-
dx = [event deltaX];
372-
dy = [event deltaY];
373-
#endif
374393

394+
*x = dx;
395+
*y = dy;
396+
}
397+
398+
- (void)scrollWheel:(NSEvent *)event
399+
{
400+
NSEventModifierFlags eventFlags = event.modifierFlags;
401+
float dx = 0, dy = 0;
402+
[self calcScrollWheelDeltas:event x:&dx y:&dy eventFlags:&eventFlags];
375403
if (dx == 0 && dy == 0)
376404
return;
377405

@@ -386,7 +414,7 @@ - (void)scrollWheel:(NSEvent *)event
386414
int row, col;
387415
NSPoint pt = [textView convertPoint:[event locationInWindow] fromView:nil];
388416
if ([textView convertPoint:pt toRow:&row column:&col]) {
389-
unsigned flags = (unsigned)[event modifierFlags];
417+
unsigned flags = (unsigned)eventFlags;
390418
NSMutableData *data = [NSMutableData data];
391419

392420
[data appendBytes:&row length:sizeof(int)];

src/MacVim/Miscellaneous.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ extern NSString *MMUseInlineImKey;
6161
extern NSString *MMSuppressTerminationAlertKey;
6262
extern NSString *MMNativeFullScreenKey;
6363
extern NSString *MMUseMouseTimeKey;
64+
extern NSString *MMMouseWheelDisableAccelerationKey; ///< Disable native macOS mouse scroll wheel acceleration
65+
extern NSString *MMMouseWheelMinLinesKey; ///< Minimum scroll delta for mouse scroll wheel, only when acceleration is on
66+
extern NSString *MMMouseWheelNumLinesKey; ///< Number of lines to scroll using mouse scroll wheel, only when acceleration is off
6467
extern NSString *MMFullScreenFadeTimeKey;
6568
extern NSString *MMNonNativeFullScreenShowMenuKey;
6669
extern NSString *MMNonNativeFullScreenSafeAreaBehaviorKey;
@@ -69,7 +72,7 @@ extern NSString *MMCmdLineAlignBottomKey;
6972
extern NSString *MMRendererClipToRowKey;
7073
extern NSString *MMAllowForceClickLookUpKey;
7174
extern NSString *MMUpdaterPrereleaseChannelKey;
72-
extern NSString *MMLastUsedBundleVersionKey; // The last used version of MacVim before this launch
75+
extern NSString *MMLastUsedBundleVersionKey; ///< The last used version of MacVim before this launch
7376
extern NSString *MMShowWhatsNewOnStartupKey;
7477
extern NSString *MMScrollOneDirectionOnlyKey;
7578

src/MacVim/Miscellaneous.m

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
NSString *MMSuppressTerminationAlertKey = @"MMSuppressTerminationAlert";
5858
NSString *MMNativeFullScreenKey = @"MMNativeFullScreen";
5959
NSString *MMUseMouseTimeKey = @"MMUseMouseTime";
60+
NSString *MMMouseWheelDisableAccelerationKey = @"MMMouseWheelDisbleAcceleration";
61+
NSString *MMMouseWheelMinLinesKey = @"MMMouseWheelMinLines";
62+
NSString *MMMouseWheelNumLinesKey = @"MMMouseWheelNumLines";
6063
NSString *MMFullScreenFadeTimeKey = @"MMFullScreenFadeTime";
6164
NSString *MMNonNativeFullScreenShowMenuKey = @"MMNonNativeFullScreenShowMenu";
6265
NSString *MMNonNativeFullScreenSafeAreaBehaviorKey = @"MMNonNativeFullScreenSafeAreaBehavior";

0 commit comments

Comments
 (0)