Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/platform/guimac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ @implementation SSView
double rotationGestureCurrent;
Point2d trackpadPositionShift;
bool inTrackpadScrollGesture;
int activeTrackpadTouches;
bool scrollFromTrackpadTouch;
Platform::Window::Kind kind;
}

Expand All @@ -397,6 +399,9 @@ - (id)initWithKind:(Platform::Window::Kind)aKind {
editor.action = @selector(didEdit:);

inTrackpadScrollGesture = false;
activeTrackpadTouches = 0;
scrollFromTrackpadTouch = false;
self.acceptsTouchEvents = YES;
kind = aKind;
if(kind == Platform::Window::Kind::TOPLEVEL) {
NSGestureRecognizer *mag = [[NSMagnificationGestureRecognizer alloc] initWithTarget:self
Expand Down Expand Up @@ -573,7 +578,16 @@ - (void)scrollWheel:(NSEvent *)nsEvent {
using Platform::MouseEvent;

MouseEvent event = [self convertMouseEvent:nsEvent];
if(nsEvent.subtype == NSEventSubtypeTabletPoint && kind == Platform::Window::Kind::TOPLEVEL) {
if(nsEvent.phase == NSEventPhaseBegan) {
// If this scroll began on trackpad then touchesBeganWithEvent was called prior to this
// event and we have at least one active trackpad touch. We store this information so we
// can handle scroll originating from trackpad differently below.
scrollFromTrackpadTouch = activeTrackpadTouches > 0 &&
nsEvent.subtype == NSEventSubtypeTabletPoint &&
kind == Platform::Window::Kind::TOPLEVEL;
}
// Check if we are scrolling on trackpad and handle things differently.
if(scrollFromTrackpadTouch) {
// This is how Cocoa represents 2 finger trackpad drag gestures, rather than going via
// NSPanGestureRecognizer which is how you might expect this to work... We complicate this
// further by also handling shift-two-finger-drag to mean rotate. Fortunately we're using
Expand Down Expand Up @@ -626,6 +640,18 @@ - (void)scrollWheel:(NSEvent *)nsEvent {
receiver->onMouseEvent(event);
}

- (void)touchesBeganWithEvent:(NSEvent *)event {
activeTrackpadTouches++;
}

- (void)touchesEndedWithEvent:(NSEvent *)event {
activeTrackpadTouches--;
}

- (void)touchesCancelledWithEvent:(NSEvent *)event {
activeTrackpadTouches--;
}

- (void)mouseExited:(NSEvent *)nsEvent {
using Platform::MouseEvent;

Expand Down