HumbleUI / JWM

Cross-platform window management and OS integration library for Java
Apache License 2.0
573 stars 46 forks source link

EventMouseScroll: Report lines scroll separate from px scroll #115

Open tonsky opened 3 years ago

tonsky commented 3 years ago

macOS: mouse wheel scroll events need to be multiplied. Chrome uses 40, druid 32, Flutter uses system-provided value which is usually set to 10 which seems too low after comparing e.g. with Safari

On Windows, scroll is reported in wheel ticks * 120, which are converted to lines (coeff in settings), which then should be converted to pixels by multiplying by 33 (Chromium, JavaFX):

ticks = GET_WHEEL_DELTA_WPARAM / WHEEL_DELTA (=120)
px = ticks * SPI_GETWHEELSCROLLLINES/SPI_GETWHEELSCROLLCHARS * 100.0f / 3.0f

On Windows, scroll might be set to pages, too, then just report pages. Possible to report px value in that case as the height of the window?

tonsky commented 3 years ago

Page scroll detection from Gecko https://github.com/mozilla/gecko-dev/blob/da97cbad6c9f00fc596253feb5964a8adbb45d9e/widget/windows/WinMouseScrollHandler.cpp#L891-L903

jaketothepast commented 10 months ago

Hello from jwind in #Clojurians slack channel! I'll take this one on as a first issue

jaketothepast commented 10 months ago

@tonsky when you say lines scroll, does this mean one "tick" of the mouse wheel? I looked into the code for Mac/Windows and it seems to be that way

tonsky commented 10 months ago

No, I think in windows there’s a system setting that sets how many “lines” one wheel tick is. We should respect that when reporting it in EventMouseScroll::deltaLines. Same for ::deltaPages (I think it’s also a setting? You’ll have to check)

jaketothepast commented 10 months ago

So the "lines" measure is arbitrary on Windows, are we trying to emulate this on X11? I looked into your other commits referencing this issue, seems that Windows is reporting line delta but not pages yet, and the only label on this issue currently is X11

tonsky commented 10 months ago

Sorry I might have lost some context since.

So the idea is to report what’s actually happening (e.g. mouse wheel scrolls * lines per wheel tick) as well as some universal unit like pixels. So the people who just want simple solution can use pixels and those will works reasonable on all platforms. But people who want to go extra mile can be faithful to the reality. For example, if user uses mouse, users can add scroll smoothing on top of that, but not if user is on trackpad.

It seems like on Windows it’s already implemented that way.

On macOS it only reports pixels right now, which is how it should be for trackpad, but for mouse it should also report lines. I assume lines are number of ticks of mouse wheel times this setting:

Screenshot 2024-01-19 at 20 23 28

As far as I can see, X11 is in the same state as Mac, but I am not sure how realistic it is to get amount of lines from X11.

It also looks like Windows lacks horizontal scroll, which can also be useful. I created a task #285

jaketothepast commented 10 months ago

Great, thank you for the additional context, if I have any more questions I'll let you know!

jaketothepast commented 10 months ago

I've found how to read that scroll scaling config value:

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

I'm thinking of using a combination of this, and the system pixels per line in CGEventSourceGetPixelsPerLine, to report on the line delta using the pixel delta on macos

The config value on macos appears to be a float, from 0 -> 1.0

tonsky commented 10 months ago

Sounds good!