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

Horizontal scrolling backwards on mac #1695

Closed
michaelkirk opened this issue Sep 4, 2020 · 19 comments · Fixed by #1696
Closed

Horizontal scrolling backwards on mac #1695

michaelkirk opened this issue Sep 4, 2020 · 19 comments · Fixed by #1696

Comments

@michaelkirk
Copy link
Contributor

michaelkirk commented Sep 4, 2020

My application has vertical scrolling working well, but horizontal scrolling is backwards for macos. I'm not 100% sure that this is a bug winit, but here's what I know:

There are two kinds of MouseScrollDelta: LineDelta and PixelDelta. Which one is used depends on some combination of the platform and device.

For vertical scrolling, the sign of macos's PixelDelta matches the sign of wayland and x11's LineDelta.
For horizontal scrolling, the sign of macos's PixelDelta is opposite the sign of wayland and x11's LineDelta.

More specifically:

macos (uses PixelDelta):
negative: swipe up, swipe left (scrollbar moves down, right, respectively - aka "natural scrolling")
positive: swipe down, swipe right (scrollbar moves up, left, respectively - aka "natural scrolling")

linux-x11 (via Parallels VM on same mac) (uses LineDelta):
negative: swipe up, swipe right
positive: swipe down swipe left

linux-wayland (via Parallels VM on same mac) (uses LineDelta):
negative: swipe up, swipe right
positive: swipe down swipe left

It seems like two possibilities:

  1. This is working as intended, and it's just a discrepancy between PixelDelta vs LineDelta in general. We should clarify in the docs.

-or-

  1. This is a mac specific bug in winit and we need to * -1.0 the horizontal PixelDelta to be consistent with other platforms.
@michaelkirk
Copy link
Contributor Author

One thing which would help me debug, would be if someone running Wayland with PixelOffset scrolling (I think most modern trackpads will use PixelOffset on Linux?), could try my debug branch here: https://github.com/michaelkirk/winit/tree/mkirk/h-scroll

Steps to help debug:

git clone https://github.com/michaelkirk/winit.git
cd winit
git checkout mkirk/h-scroll
cargo build --example window_debug
cargo run --example window_debug 2> stderr_out

Then:

  1. move your mouse over the window that launched
  2. click the window
  3. swipe up on your trackpad a few times (being careful not to swipe in other directions)
  4. swipe left on your track pad a few times (being careful not to swipe in other directions)
  5. close the window and attach the output from stderr_out to this issue

scroll_debug mov

@kchibisov
Copy link
Member

There's no PixelOffset in winit, etc. You can't test Wayland with winit's examples either, but the thing I can say, that on Wayland if you swipe from right to left the PixelDelta's x is negative, and from left to right it's positive.

@michaelkirk
Copy link
Contributor Author

Sorry, I meant to say PixelDelta, not PixelOffset. I've updated the issue to avoid confusing other people.

e.g. you can see PixelDelta being used (e.g.) here: https://github.com/rust-windowing/winit/blob/master/src/platform_impl/macos/view.rs#L1009

@michaelkirk
Copy link
Contributor Author

but the thing I can say, that on Wayland if you swipe from right to left the PixelDelta's x is negative, and from left to right it's positive.

Thanks for checking!

That sounds consistent with macos - meaning that, compared to LineDelta's, the signs match for vertical scrolling, but are opposite for horizontal scrolling.

... that seems kind of wild, but maybe there's a reason for it that I don't understand.

@kchibisov
Copy link
Member

I could test X11's PixelDelta as well. I guess the no one was able to test LineDelta for x changes, since it's not something that easy to test due to lhow rare it's on a real hardware.

Also, have you verified in your vms to which direction scrolling is done in some gui applications with horizontal scrolling?

@chrisduerr
Copy link
Contributor

I'm pretty sure this is intended? macOS scrolling is the exact opposite of scrolling on other platforms with the touchpad. That should be the case for all applications.

@michaelkirk
Copy link
Contributor Author

michaelkirk commented Sep 4, 2020

I could test X11's PixelDelta as well

There is no PixelDelta in the X11 platform_impl. From what I can see everything for X11 is done with LineDelta.

Also, have you verified in your vms to which direction scrolling is done in some gui applications with horizontal scrolling?

Yeah - the VM is a potentially confounding factor, but it seems to be behaving as expected.

For example swiping from right to left in firefox in the VM moves the scroll bar to the right (same as in native macos). This behavior is the same when launching the desktop in both X11 and Wayland modes.

@michaelkirk
Copy link
Contributor Author

I'm pretty sure this is intended? macOS scrolling is the exact opposite of scrolling on other platforms with the touchpad. That should be the case for all applications.

That doesn't seem to fit what I've described nor what kchibisov reported. It seems like the difference has to do with PixelDelta vs LineDelta, not linux vs mac.

@michaelkirk
Copy link
Contributor Author

Also, to be clear @chrisduerr - I'm not simply talking about "natural scrolling" vs "reverse scrolling", which is a user configurable preference.

@kchibisov
Copy link
Member

For example swiping from right to left in firefox in the VM moves the scroll bar to the right (same as in native macos). This behavior is the same when launching the desktop in both X11 and Wayland modes.

Just fyi, swiping from right to left in firefox natively on a touch pad moves the scrollbar to the left, which is expected. on macOS you have natural scrolling by default, I'm afraid that your tests in a vm could be incorrect? Also, is vertical scrolling in a vm also the same as on macOS(means natural)?

@michaelkirk
Copy link
Contributor Author

michaelkirk commented Sep 4, 2020

Just fyi, swiping from right to left in firefox natively on a touch pad moves the scrollbar to the left, which is expected. on macOS you have natural scrolling by default, I'm afraid that your tests in a vm could be incorrect? Also, is vertical scrolling in a vm also the same as on macOS(means natural)?

Heh - I was just digging into this a bit more. It seems that the "natural" scroll behavior is inherited by the VM. So... to get "reverse" (as opposed to "natural") scrolling I have to either configure "reverse" scrolling in my host (leaving my vm at "reverse"), or set both my vm and my host to "natural" which is like a double negation. 🙃

But still, though that's confusing, I think my question remains and is best exemplified by the fact that vertical scrolling behaves as expected, while horizontal (and only horizontal) is reversed when talking about units of PixelDelta vs LineDelta.

Natural vs. Reverse scrolling should not affect that, as it affects both axes equally. Right?

@kchibisov
Copy link
Member

Could you disable natural scrolling in macOS and retest please?

@michaelkirk
Copy link
Contributor Author

michaelkirk commented Sep 4, 2020

Could you disable natural scrolling in macOS and retest please?

With default (Natural) scrolling on macos (host)

  • macos (uses PixelOffset) (natural scrolling is on by default):
    • negative: swipe up, swipe left (scrollbar moves down, right, respectively)
    • positive: swipe down, swipe right (scrollbar moves up, left, respectively)
  • linux-x11 (via Parallels on mac, inheriting natural scrolling) (uses LineOffset):
    • negative: swipe up, swipe right
    • positive: swipe down swipe left
  • linux-wayland (via Parallels on mac, inheriting natural scrolling) (uses LineOffset):
    • negative: swipe up, swipe right
    • positive: swipe down swipe left

With Natural scrolling disabled on macos (host)

Same results - but everything flipped from positive to negative.

  • macos (uses PixelOffset) (disabled natural scrolling):
    • positive: swipe up, swipe left (scrollbar moves up, left respectively)
    • negative: swipe down, swipe right (scrollbar moves down, right respectively)
  • linux-x11(via Parallels on mac, disabled natural scrolling on mac) (uses LineOffset):
    • positive: swipe up, swipe right
    • negative: swipe left, swipe down
  • linux-wayland (via Parallels on mac, disabled natural scrolling on mac) (uses LineOffset):
    • positive: swipe up, swipe right
    • negative: swipe down, swipe left

So horizontal vs. vertical is still not symmetrical with what I was expecting.

@kchibisov: but the thing I can say, that on Wayland if you swipe from right to left the PixelDelta's x is negative, and from left to right it's positive.

Is swiping from bottom to top of the track pad positive or negative on Wayland+PixelDelta?

As an aside, do you know how you're inducing PixelDelta as opposed to LineDelta on wayland? I'm only getting LineDelta on Wayland, but presumed it's because the VM is mapping the mouse input that way.

@kchibisov
Copy link
Member

As an aside, do you know how you're inducing PixelDelta as opposed to LineDelta on wayland? I'm only getting LineDelta on Wayland, but presumed it's because the VM is mapping the mouse input that way.

I'm testing on a touchpad.

So, from what I can see macOS needs x to be inverted, everything else is consistent on other platforms.

Is swiping from bottom to top of the track pad positive or negative on Wayland+PixelDelta?

yes, we explicitly invert it to be like that.

@michaelkirk
Copy link
Contributor Author

Is swiping from bottom to top of the track pad positive or negative on Wayland+PixelDelta?

yes, we explicitly invert it to be like that.

Sorry to be a pain - is it positive or is it negative?

@kchibisov
Copy link
Member

Sorry to be a pain - is it positive or is it negative?

positive

@michaelkirk
Copy link
Contributor Author

Is swiping from bottom to top of the track pad positive or negative on Wayland+PixelDelta?

positive

Excellent. That was the missing piece of information for me.

So, from what I can see macOS needs x to be inverted, everything else is consistent on other platforms.

PR forthcoming!

michaelkirk added a commit to michaelkirk/winit that referenced this issue Sep 4, 2020
…orms.

FIXES rust-windowing#1695

Note: This isn't just confusion around "natural" vs "reverse" scrolling.
These were already behaving correctly for vertical scrolling. Only
Horizontal scrolling was inverted. Unlike vertical scrolling, did not
mirror winit's output for other platforms.
@michaelkirk
Copy link
Contributor Author

Thanks for your help @kchibisov. PR at #1696

Time spent researching and documenting was about 1000x more than the actual fix. 😅

kchibisov pushed a commit that referenced this issue Sep 6, 2020
In winit the swipe from left to right on touchpad should
generate positive horizontal delta change, however on
macOS it was the other way around without
natural scrolling.

This commit inverses the horizontal scrolling delta
in 'MouseScrollDelta' events to match other platforms.

Fixes #1695.
@michaelkirk
Copy link
Contributor Author

Thanks @kchibisov!

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

Successfully merging a pull request may close this issue.

3 participants