Scrcpy: In Mac OS, I think the natural scrolling doesn't work

Created on 30 Nov 2019  路  14Comments  路  Source: Genymobile/scrcpy

Is it just me? I use Mac OS Mojave in 2018 Mac Book Pro 15. Does anybody have the same issue? it seems to be working fine in my Ubuntu though

input events macos scrolling

Most helpful comment

@r4dixx Thank you for the feedbacks.

Here is a summary of the results (I post them here to keep a trace).

Both with scroll or trackpad, when natural scroll is enabled:

# scroll up
x=0, y=-1 (mul=-1), direction=1

# scroll down
x=0, y=1 (mul=-1), direction=1

When natural scroll is disabled:

# scroll up
x=0, y=1 (mul=1), direction=0

# scroll down
x=0, y=-1 (mul=1), direction=0

So I guess the correct behavior is to just ignore the direction field (which forces the scroll to be "unnatural":

Movements down (scroll backward) generate negative y values and up (scroll forward) generate positive y values.
[鈥
If direction is SDL_MOUSEWHEEL_FLIPPED the values in x and y will be opposite. Multiply by -1 to change them back.

https://wiki.libsdl.org/SDL_MouseWheelEvent#Remarks

diff --git a/app/src/input_manager.c b/app/src/input_manager.c
index 7d333c1..49faa11 100644
--- a/app/src/input_manager.c
+++ b/app/src/input_manager.c
@@ -550,13 +550,8 @@ convert_mouse_wheel(const SDL_MouseWheelEvent *from, struct screen *screen,
     to->type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT;

     to->inject_scroll_event.position = position;
-
-    int mul = from->direction == SDL_MOUSEWHEEL_NORMAL ? 1 : -1;
-    // SDL behavior seems inconsistent between horizontal and vertical scrolling
-    // so reverse the horizontal
-    // <https://wiki.libsdl.org/SDL_MouseWheelEvent#Remarks>
-    to->inject_scroll_event.hscroll = -mul * from->x;
-    to->inject_scroll_event.vscroll = mul * from->y;
+    to->inject_scroll_event.hscroll = from->x;
+    to->inject_scroll_event.vscroll = from->y;

     return true;
 }

All 14 comments

What is "natural" scrolling?

@rom1v so when you scroll up (two finger swiping "up") it scrolls down and vice versa. there's a option in mouse and touchpad settings in the Mac where you can tick the box

Lovely application, but I'm checking if I'm the only one who has the issue. I've installed Scrcpy with brew

So you are saying that the scroll is reversed in scrcpy?

yes so it's acting as if the "natural scroll" has been turned off. do you have a mac? you can probably quickly try it by enabling it in the settings

do you have a mac?

No, I don't.

If you are comfortable with building it and play with the source code, here is the relevant part:

https://github.com/Genymobile/scrcpy/blob/8bc056b9c68eea7bccfa5d9123a70443fb1d75b2/app/src/input_manager.c#L554-L559

Ref: #49 and f9a63ec272a6051bd2f1a92a580640018124a34c

EDIT: More precisely, do you receive a different direction and y value when you use "natural scroll" compared to when you scroll using a mouse?

is this part the server?

No, it's the client (it's in app/ and is written in C; the server is in server/ and is written in Java).

https://wiki.libsdl.org/SDL_MouseWheelEvent seems there is a FLIPPED option on event, but this only has to be activated when the user activates in the settings. Any idea on this?

SDL_MOUSEWHEEL_FLIPPED is just a possible value of direction (and is already handled in the code):

int mul = from->direction == SDL_MOUSEWHEEL_NORMAL ? 1 : -1; 

FYI

Just tested on my machine with LOGD("x=%"PRIu32", y=%"PRIi32" (x%d), direction=%"PRIu32, from->x, from->y, mul, from->direction); right before convert_mouse_wheel's return statement.

Here's what I get:

Natural scroll enabled:

  • trackpad: direction=1
  • mouse (click): no output
  • mouse (wheel): direction=1

Natural scroll disabled:

  • trackpad: direction=0
  • mouse (click): no output
  • mouse (wheel): direction=0

In both cases, when using the trackpad, I get Unknown touch device id -1, cannot reset, so there's that...

Let me know if you need additional testing and/or info!

System info:

Scrcpy built locally from master

  • ./run x --version
scrcpy 1.11

dependencies:
 - SDL 2.0.10
 - libavcodec 58.54.100
 - libavformat 58.29.100
 - libavutil 56.31.100
  • sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.1
BuildVersion:   19B88
  • uname -a
Darwin parprpmc008675a 19.0.0 Darwin Kernel Version 19.0.0: Thu Oct 17 16:17:15 PDT 2019; root:xnu-6153.41.3~29/RELEASE_X86_64 x86_64

@r4dixx Thank you for the feedbacks.

Here is a summary of the results (I post them here to keep a trace).

Both with scroll or trackpad, when natural scroll is enabled:

# scroll up
x=0, y=-1 (mul=-1), direction=1

# scroll down
x=0, y=1 (mul=-1), direction=1

When natural scroll is disabled:

# scroll up
x=0, y=1 (mul=1), direction=0

# scroll down
x=0, y=-1 (mul=1), direction=0

So I guess the correct behavior is to just ignore the direction field (which forces the scroll to be "unnatural":

Movements down (scroll backward) generate negative y values and up (scroll forward) generate positive y values.
[鈥
If direction is SDL_MOUSEWHEEL_FLIPPED the values in x and y will be opposite. Multiply by -1 to change them back.

https://wiki.libsdl.org/SDL_MouseWheelEvent#Remarks

diff --git a/app/src/input_manager.c b/app/src/input_manager.c
index 7d333c1..49faa11 100644
--- a/app/src/input_manager.c
+++ b/app/src/input_manager.c
@@ -550,13 +550,8 @@ convert_mouse_wheel(const SDL_MouseWheelEvent *from, struct screen *screen,
     to->type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT;

     to->inject_scroll_event.position = position;
-
-    int mul = from->direction == SDL_MOUSEWHEEL_NORMAL ? 1 : -1;
-    // SDL behavior seems inconsistent between horizontal and vertical scrolling
-    // so reverse the horizontal
-    // <https://wiki.libsdl.org/SDL_MouseWheelEvent#Remarks>
-    to->inject_scroll_event.hscroll = -mul * from->x;
-    to->inject_scroll_event.vscroll = mul * from->y;
+    to->inject_scroll_event.hscroll = from->x;
+    to->inject_scroll_event.vscroll = from->y;

     return true;
 }

Works perfectly. Vertically and horizontally. Thanks a whole bunch!

Fixed by 3100533e56b2efdfc6f07b96681a7eef25ff63e0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

singleNeuron picture singleNeuron  路  3Comments

targor picture targor  路  3Comments

jonnybrooks picture jonnybrooks  路  3Comments

swamikamal picture swamikamal  路  3Comments

cutoseo picture cutoseo  路  4Comments