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

Handle high-precision scrolling when using notebook touchpads #3363

Closed
1 task done
yume-chan opened this issue Jul 3, 2022 · 4 comments
Closed
1 task done

Handle high-precision scrolling when using notebook touchpads #3363

yume-chan opened this issue Jul 3, 2022 · 4 comments

Comments

@yume-chan
Copy link
Contributor

yume-chan commented Jul 3, 2022

Is your feature request related to a problem? Please describe.
I'm investigating yume-chan/ya-webadb#396, a user reported that the scrolling speed of my client implementation, when using notebook touchpads, is super fast.

It turns out that Scrcpy is using the integer scrolling distances (x, y) from SDL, but mouse wheel events from browsers only contains high-resolution distances (and the event is firing very frequently). It's pretty hard to emulate integer scrolling distances from fractional ones,

In my testing using the native Scrcpy client with a notebook touchpad, the two-fingering scrolling works, but feels clunky.

1.mp4

Describe the solution you'd like
Since SDL also provides high-resolution scrolling distances (preciseX and preciseY in SDL_MouseWheelEvent), and Android accepts float values in MotionEvent.PointerCoords.setAxisValue, switch Scrcpy to use the high-precision ones. This will make scrolling on notebook touchpad super smooth.

Additional context

I tested the idea on master...yume-chan:scrcpy:float-scroll. The result on Windows laptops is good.

2.mp4

Logged SDL mouse wheel events:

scroll x=0, y=-1, preciseX=0, preciseY=-1.38333
scroll x=0, y=0, preciseX=0, preciseY=-0.566667
scroll x=0, y=-1, preciseX=0, preciseY=-0.775
scroll x=0, y=-1, preciseX=0, preciseY=-0.541667
scroll x=0, y=-1, preciseX=0, preciseY=-0.808333
scroll x=0, y=0, preciseX=0, preciseY=-0.708333
scroll x=0, y=-1, preciseX=0, preciseY=-0.641667
scroll x=0, y=-1, preciseX=0, preciseY=-0.791667
scroll x=0, y=0, preciseX=0, preciseY=-0.458333
scroll x=0, y=-1, preciseX=0, preciseY=-0.7
scroll x=0, y=0, preciseX=0, preciseY=-0.233333
scroll x=0, y=0, preciseX=0, preciseY=-0.316667
scroll x=0, y=-1, preciseX=0, preciseY=-0.25
scroll x=0, y=0, preciseX=0, preciseY=-0.0916667
scroll x=0, y=0, preciseX=0, preciseY=-0.05
scroll x=0, y=0, preciseX=0, preciseY=-0.0416667
scroll x=0, y=0, preciseX=0, preciseY=-0.025
scroll x=0, y=0, preciseX=0, preciseY=-0.00833333
scroll x=0, y=0, preciseX=0, preciseY=-0.00833333
scroll x=0, y=0, preciseX=0, preciseY=-0.00833333
scroll x=0, y=0, preciseX=0, preciseY=0.00833333
scroll x=0, y=0, preciseX=0, preciseY=0.00833333
scroll x=0, y=0, preciseX=0, preciseY=0.0166667
scroll x=0, y=0, preciseX=0, preciseY=0.0666667
scroll x=0, y=0, preciseX=0, preciseY=0.191667
scroll x=0, y=0, preciseX=0, preciseY=0.2
scroll x=0, y=0, preciseX=0, preciseY=0.391667
scroll x=0, y=1, preciseX=0, preciseY=0.325
scroll x=0, y=0, preciseX=0, preciseY=0.625
scroll x=0, y=1, preciseX=0, preciseY=0.7
scroll x=0, y=1, preciseX=0, preciseY=0.841667
scroll x=0, y=1, preciseX=0, preciseY=0.666667
scroll x=0, y=0, preciseX=0, preciseY=0.808333
scroll x=0, y=1, preciseX=0, preciseY=0.75
scroll x=0, y=1, preciseX=0, preciseY=0.516667
scroll x=0, y=0, preciseX=0, preciseY=0.783333
scroll x=0, y=1, preciseX=0, preciseY=0.433333
scroll x=0, y=0, preciseX=0, preciseY=0.6
scroll x=0, y=1, preciseX=0, preciseY=0.308333
scroll x=0, y=0, preciseX=0, preciseY=0.15
scroll x=0, y=0, preciseX=0, preciseY=0.6
scroll x=0, y=1, preciseX=0, preciseY=0.0833333
scroll x=0, y=0, preciseX=0, preciseY=0.0916667
scroll x=0, y=0, preciseX=0, preciseY=0.05
scroll x=0, y=0, preciseX=0, preciseY=0.0333333
scroll x=0, y=0, preciseX=0, preciseY=0.00833333
scroll x=0, y=0, preciseX=0, preciseY=0.00833333
scroll x=0, y=0, preciseX=0, preciseY=0.00833333

The value can exceed 1/-1 when scrolling fast, but looks like Android only accepts value between -1 and 1

@rom1v
Copy link
Collaborator

rom1v commented Jul 3, 2022

Thank you for the report 👍 A PR is welcome 😉

Some first remarks on your branch.

The preciseX/preciseY fields have been added in SDL 2.0.18, so a fallback method using x and y must be kept (using SDL_VERSION_ATLEAST(2, 0, 18)).

The vscroll and hscroll in struct sc_mouse_scroll_event should be floats, and serialized as fixed point values (cf how pressure is handled).

@yume-chan
Copy link
Contributor Author

yume-chan commented Jul 4, 2022

OK. Should I also clamp the value to -1~1 and/or shorten the fields to 16 bits (short) each like pressure? The documentation of MotionEvent.AXIS_HSCROLL(https://developer.android.com/reference/android/view/MotionEvent#AXIS_HSCROLL) says the range is -1 to 1.

@rom1v
Copy link
Collaborator

rom1v commented Jul 4, 2022

Should I also clamp the value to -1~1

I think so.

and/or shorten the fields to 16 bits (short) each like pressure?

I would say yes, I guess 16 bits is sufficient (and for consistency with pressure).

rom1v pushed a commit that referenced this issue Jul 24, 2022
Since SDL 2.0.18, the amount scrolled horizontally or vertically is
exposed as a float (between 0 and 1).

XX  DO NOT MERGE (YET)  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Remaining problem (?) before merging: the x and y value are clamped to
[0; 1], so if on some platforms a scroll event could be triggered with a
value greater than 1 or lower than -1, it is not forwarded correctly
anymore (this is the case both for the int or float versions).
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Refs <https://wiki.libsdl.org/SDL_MouseWheelEvent>
Fixes #3363 <#3363>
PR #3369 <#3369>

Signed-off-by: Romain Vimont <[email protected]>
rom1v pushed a commit that referenced this issue Jul 24, 2022
Since SDL 2.0.18, the amount scrolled horizontally or vertically is
exposed as a float (between 0 and 1). Forward a precise value to the
Android device when possible.

Refs <https://wiki.libsdl.org/SDL_MouseWheelEvent>
Fixes #3363 <#3363>
PR #3369 <#3369>

Signed-off-by: Romain Vimont <[email protected]>
rom1v pushed a commit that referenced this issue Aug 3, 2022
Since SDL 2.0.18, the amount scrolled horizontally or vertically is
exposed as a float (between 0 and 1). Forward a precise value to the
Android device when possible.

Refs <https://wiki.libsdl.org/SDL_MouseWheelEvent>
Fixes #3363 <#3363>
PR #3369 <#3369>

Signed-off-by: Romain Vimont <[email protected]>
rom1v pushed a commit that referenced this issue Aug 28, 2022
Since SDL 2.0.18, the amount scrolled horizontally or vertically is
exposed as a float (between 0 and 1). Forward a precise value to the
Android device when possible.

Refs <https://wiki.libsdl.org/SDL_MouseWheelEvent>
Fixes #3363 <#3363>
PR #3369 <#3369>

Signed-off-by: Romain Vimont <[email protected]>
@rom1v
Copy link
Collaborator

rom1v commented Aug 28, 2022

Fixed by #3369.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants