Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate deltaLines macOS #288

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
34 changes: 33 additions & 1 deletion macos/cc/JWMMainView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <algorithm>
#include <Carbon/Carbon.h>
#include <CoreFoundation/CoreFoundation.h>
#include <CoreGraphics/CoreGraphics.h>
#include <Foundation/Foundation.h>
#include <jni.h>
#include "impl/JNILocal.hh"
#include "impl/Library.hh"
Expand Down Expand Up @@ -387,6 +390,19 @@ - (NSTouchTypeMask)allowedTouchTypes {
return NSTouchTypeMaskIndirect; // | NSTouchTypeMaskDirect;
}

- (float)getScrollScaling {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *scrollScaling = [defaults objectForKey:@"com.apple.scrollwheel.scaling"];

// If never set, the value will be null. Return scale factor of 1.0
if (scrollScaling == nil) {
return 1.0; // No scaling.
}

// Value is 0->1.0. Return a "scale factor" to multiply delta by.
return [scrollScaling floatValue] + 1.0;
}

- (BOOL)wantsRestingTouches {
// we set this to YES to prevent resting touches from triggering the cancel event
return YES;
Expand Down Expand Up @@ -484,6 +500,7 @@ - (void)scrollWheel:(NSEvent *)event {
jint modifierMask = jwm::modifierMask([event modifierFlags]);
CGFloat deltaX;
CGFloat deltaY;
// Retrieve the scrolling speed
if ([event hasPreciseScrollingDeltas]) {
deltaX = [event scrollingDeltaX];
deltaY = [event scrollingDeltaY];
Expand All @@ -495,7 +512,22 @@ - (void)scrollWheel:(NSEvent *)event {
CGFloat scale = fWindow->getScale();
deltaX *= scale;
deltaY *= scale;
jwm::JNILocal<jobject> eventObj(fWindow->fEnv, jwm::classes::EventMouseScroll::make(fWindow->fEnv, deltaX, deltaY, 0, 0, 0, fLastPos.x, fLastPos.y, modifierMask));

// Accessibility scaling.
float scrollScaling = [self getScrollScaling];
deltaX *= scrollScaling;
deltaY *= scrollScaling;

// deltaLines
CGFloat deltaLines;
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
if (source) {
double pixelsPerLine = CGEventSourceGetPixelsPerLine(source);
deltaLines = deltaY / pixelsPerLine;
CFRelease(source);
}

jwm::JNILocal<jobject> eventObj(fWindow->fEnv, jwm::classes::EventMouseScroll::make(fWindow->fEnv, deltaX, deltaY, 0, deltaLines, 0, fLastPos.x, fLastPos.y, modifierMask));
fWindow->dispatch(eventObj.get());
}

Expand Down