@@ -38,6 +38,7 @@ @implementation MMTabline
38
38
NSInteger _finalDraggedTabIndex;
39
39
MMHoverButton *_leftScrollButton;
40
40
MMHoverButton *_rightScrollButton;
41
+ id _scrollWheelEventMonitor;
41
42
}
42
43
43
44
- (instancetype )initWithFrame : (NSRect )frameRect
@@ -78,6 +79,30 @@ - (instancetype)initWithFrame:(NSRect)frameRect
78
79
[self addConstraint: _addTabButtonTrailingConstraint];
79
80
80
81
[[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (didScroll: ) name: NSViewBoundsDidChangeNotification object: _scrollView.contentView];
82
+
83
+ // Monitor for scroll wheel events so we can scroll the tabline
84
+ // horizontally without the user having to hold down SHIFT.
85
+ _scrollWheelEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask: NSEventMaskScrollWheel handler: ^NSEvent * _Nullable (NSEvent * _Nonnull event) {
86
+ NSPoint location = [_scrollView convertPoint: event.locationInWindow fromView: nil ];
87
+ // We want events:
88
+ // where the mouse is over the _scrollView
89
+ // and where the user is not modifying it with the SHIFT key
90
+ // and initiated by the scroll wheel and not the trackpad
91
+ if ([_scrollView mouse: location inRect: _scrollView.bounds]
92
+ && !event.modifierFlags
93
+ && !event.hasPreciseScrollingDeltas )
94
+ {
95
+ // Create a new scroll wheel event based on the original,
96
+ // but set the new deltaX to the original's deltaY.
97
+ // stackoverflow.com/a/38991946/111418
98
+ CGEventRef cgEvent = CGEventCreateCopy (event.CGEvent );
99
+ CGEventSetIntegerValueField (cgEvent, kCGScrollWheelEventDeltaAxis2 , event.scrollingDeltaY );
100
+ NSEvent *newEvent = [NSEvent eventWithCGEvent: cgEvent];
101
+ CFRelease (cgEvent);
102
+ return newEvent;
103
+ }
104
+ return event;
105
+ }];
81
106
}
82
107
return self;
83
108
}
0 commit comments