HumbleUI / JWM

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

Calculate deltaLines macOS #288

Open jaketothepast opened 5 months ago

jaketothepast commented 5 months ago

Calculate deltaLines from the existing scroll delta. Use the accessibility scaling in calculations.

Related to #115

Screenshot 2024-01-22 at 8 14 58 AM
tonsky commented 5 months ago

Sorry, I need to get my hands on a mouse. Will check it out soon!

tonsky commented 5 months ago

Okay I did some testing. Some new information:

  1. It seems that value of com.apple.scrollwheel.scaling is already accounted by macOS. On higher setting, Chrome scrolls much faster, so I guess your app just starts receiving higher deltaY-s
  2. Minimal deltaY seems to be 0.1 (one wheel tick), but if you do several one after the other, deltaY starts to get higher. That’s scroll acceleration, and again, you don’t have to do anything, macOS just sends you correct values.
  3. By testing both Chrome and Safari, they seem to agree on value of 40 to get from deltaY to px offset. I suggest we do the same

I need you to change some calculations though. Roughly this:

  1. Trackpad.

    • Detect by [event hasPreciseScrollingDeltas] == true
    • Get EventMouseScroll::deltaX/deltaY from [event scrollingDeltaX]/[event scrollingDeltaY]
    • Do not fill EventMouseScroll::deltaLines, as there is no by-line scrolling on trackpad
  2. Mouse

    • Detect by [event hasPreciseScrollingDeltas] == true
    • Fill EventMouseScroll::deltaX/Y from [event deltaX/Y] * 40
    • Fill EventMouseScroll::deltaLines from [event deltaY] * 4 (≈ [event deltaY] * 40 / CGEventSourceGetPixelsPerLine)

As a side effect, this will let JWM clients distinguish trackpad from the mouse

Let me know if you have better ideas or questions

jaketothepast commented 5 months ago

Of course, sorry about that. I'll change the calculations!

jaketothepast commented 5 months ago

I promise I haven't forgotten about this! I have a lot of work at my full-time job this week, but when it clears up I will make the changes.