scrcpy icon indicating copy to clipboard operation
scrcpy copied to clipboard

Support smooth scrolling on notebook touchpads.

Open yume-chan opened this issue 1 year ago • 2 comments

Fixes #3363

HID mode doesn't support this smooth scrolling, because sending fractional scrolling distance over standard HID mouse protocol seems complicated. I may investigate more in the future (plus horizontal scrolling support).

Only tested on Windows with both mouse and touchpad.

yume-chan avatar Jul 06 '22 05:07 yume-chan

Thank you :+1: (and sorry for the delay).

I rebased on dev (and squashed your 2 commits), and made the following changes:

  • extracted a function fixedPointToFloat() used for pressure as a preliminary commit before your changes;
  • use this function in your commits;
  • remove the inversion of horizontal scrolling (it looks suspicious to me, cf https://github.com/Genymobile/scrcpy/issues/966#issuecomment-560394359, please take a look and confirm that it works as expected for you);
  • used conditional compilation for SDL_VERSION_ATLEAST() (otherwise it would not compile with an older SDL version).

I was first annoyed by the CLAMP() between -1 and 1, but the Android side expects a value in this range: AXIS_VSCROLL, so it's better to clamp anyway (even if SDL could trigger values outside this range).

I could not test since on my computer, only -1 or +1 values are generated.

Please review and test this branch: pr3369.1.

rom1v avatar Jul 24 '22 14:07 rom1v

I changed to encode as a signed integer (with a more natural two's complement):

  • -1.0f0x8000
  • -0.5f0xC000
  • 0.0f0x0000
  • 0.5f0x4000
  • 1.0f0x7FFF

I added the necessary util functions and unit tests beforehand, then adapted your commit to use them.

Please review and test pr3369.3.

Thank you :wink:

rom1v avatar Aug 03 '22 21:08 rom1v

@yume-chan Did you have a change to test/review? (It's not urgent)

rom1v avatar Aug 16 '22 22:08 rom1v

Sorry, I'm still busy working on another project. I always have this on my todo list and will report back once that's finished.

yume-chan avatar Aug 18 '22 12:08 yume-chan

I merged into dev. Everything looks good to me.

rom1v avatar Aug 28 '22 13:08 rom1v

This works great on my Mac, both with touchpad and mouse. The scrolling is much nicer now.

The version should probably be bumped, because of the incompatible server/client. When I tried to scroll with mismatched server, I got a lot of

[server] WARN: Unknown event type: -116

(with the number varying for different runs) and then scrcpy would become completely unresponsive. (That the scrolling didn't work was expected, but a little surprising that it didn't recover.)

Also, had to change PLATFORM and BUILD_TOOLS from 31 to 33 in server/build_without_gradle.sh, because otherwise I kept getting

[server] INFO: Device: Sony G8441 (Android 9)
[server] ERROR: Exception on thread Thread[main,5,main]
java.lang.AssertionError: java.lang.NullPointerException: 
 Attempt to invoke virtual method
 'java.lang.reflect.Method java.lang.Class.getMethod(java.lang.String, java.lang.Class[])'
 on a null object reference
        at com.genymobile.scrcpy.wrappers.WindowManager.registerRotationWatcher(WindowManager.java:108)
        at com.genymobile.scrcpy.Device.<init>(Device.java:85)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:65)
        at com.genymobile.scrcpy.Server.main(Server.java:335)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:340)
Caused by: java.lang.NullPointerException:
 Attempt to invoke virtual method
 'java.lang.reflect.Method java.lang.Class.getMethod(java.lang.String, java.lang.Class[])'
 on a null object reference
        at com.genymobile.scrcpy.wrappers.WindowManager.registerRotationWatcher(WindowManager.java:102)
        ... 5 more
2022-09-02 13:12:05.549 scrcpy[48321:5695314] DEBUG: Interrupting socket
2022-09-02 13:12:05.549 scrcpy[48321:5695314] DEBUG: Server disconnected
2022-09-02 13:12:05.549 scrcpy[48321:5695314] DEBUG: Server terminated

metayan avatar Sep 02 '22 11:09 metayan

@metayan Thanks for the verification!

In addition, can you verify does horizontal scrolling works (not flipped) on both touchpad and mouse (if you have a mouse with horizonal scroll wheel)? You can open the browser app on your phone and pinch out to zoom in, then scroll horizontally.

The version should probably be bumped

It will, when the new version is released.

then scrcpy would become completely unresponsive

That's expected. The packet size changed, so after one mismatched packet, the whole stream becomes out of sync.

Also, had to change PLATFORM and BUILD_TOOLS from 31 to 33

This looks unrelated to this PR, maybe you want to open a new issue for further investigation.

yume-chan avatar Sep 02 '22 11:09 yume-chan

@metayan Thanks for the verification!

In addition, can you verify does horizontal scrolling works (not flipped) on both touchpad and mouse (if you have a mouse with horizonal scroll wheel)? You can open the browser app on your phone and pinch out to zoom in, then scroll horizontally.

It is "flipped" on the touchpad. With "Scroll direction: Natural" set in preferences, the vertical scroll follows the fingers, but the horizontal moves in the opposite direction.

I don't have a mouse with horizontal scroll wheel.

The version should probably be bumped

It will, when the new version is released.

Might be an idea to bump it immediately when changing the protocol, so anyone building from source will notice the mismatch right away. Your choice, of course. ;)

Also, had to change PLATFORM and BUILD_TOOLS from 31 to 33

This looks unrelated to this PR, maybe you want to open a new issue for further investigation.

Seems so. Will do.

metayan avatar Sep 02 '22 12:09 metayan