equalsraf / neovim-qt

Neovim client library and GUI, in Qt5.
https://github.com/equalsraf/neovim-qt/wiki
ISC License
1.85k stars 171 forks source link

Scroll direction is reversed on MacOS. #696

Closed AllenDang closed 8 months ago

AllenDang commented 4 years ago

In recent commit, I noticed that scroll direction with wire mouse wheel is reversed on MacOS 10.15.4 with Qt 5.14.2.

gpncarl commented 4 years ago

I have the same problem

equalsraf commented 4 years ago

Hi @GPN211314 cal you tell us which version you are using?

From a terminal you can get the nvim-qt version using the command line argument nvim-qt --version. Can you share the output?

Also does this happen with both the touch pad and mouse?

gpncarl commented 4 years ago

Hi @GPN211314 cal you tell us which version you are using?

From a terminal you can get the nvim-qt version using the command line argument nvim-qt --version. Can you share the output?

Also does this happen with both the touch pad and mouse?

NVIM-QT v0.2.17.9999 Build type: Release Compilation: -Wall -Wextra -Wno-unused-parameter -std=c++11 -Wfatal-errors Qt Version: 5.15.0

MacOS 10.15.7

I only use the touch pad No matter I install it with brew , nix or compiling it myself, I encountered the same problem (sorry for my poor english)

psagers commented 4 years ago

I noticed this as well. I have both a conventional USB mouse and an external Apple trackpad and I observe the following:

Scroll wheel down: content moves up. Scroll wheel up: content moves down.

Unlike other applications, this is regardless of the "Scroll direction" setting under System Preferences > Mouse.

Trackpad up (2-finger): content moves left. Trackpad right: content moves left. Trackpad down: content moves diagonally up and left. Trackpad left: content moves up.

Don't know what to say about that one. It's almost as if someone's using the wrong set of constants that just happen to overlap with the correct values.

NVIM-QT v0.2.16.1
Build type: Release
Compilation: -Wall -Wextra -Wno-unused-parameter -std=c++11 -Wfatal-errors
Qt Version: 5.15.1
Environment: 
  nvim: nvim
  args: --cmd let &rtp.=',/Users/psagers/ext/neovim-qt/build/bin/nvim-qt.app/Contents/MacOS/../Resources/runtime' --cmd set termguicolors
  runtime: /Users/psagers/ext/neovim-qt/build/bin/nvim-qt.app/Contents/MacOS/../Resources/runtime

NVIM v0.4.4
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/tmp/neovim-20200808-89283-1us0ytm/neovim-0.4.4/build/config -I/tmp/neovim-20200808-89283-1us0ytm/neovim-0.4.4/src -I/usr/local/include -I/tmp/neovim-20200808-89283-1us0ytm/neovim-0.4.4/deps-build/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -I/usr/local/opt/gettext/include -I/tmp/neovim-20200808-89283-1us0ytm/neovim-0.4.4/build/src/nvim/auto -I/tmp/neovim-20200808-89283-1us0ytm/neovim-0.4.4/build/include
Compiled by brew@Catalina

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.4.4/share/nvim"

Run :checkhealth for more info
jgehrig commented 4 years ago

Do you have the ability to build from source?

Could you apply the following patch, and report back with the output?

--- a/src/gui/shell.cpp Thu Oct 15 18:01:11 2020 +0200
+++ b/src/gui/shell.cpp Sun Oct 25 13:27:20 2020 -0400
@@ -1373,6 +1373,9 @@
                        .arg(Input::GetModifierPrefix(ev->modifiers()), (scroll_delta.x() > 0) ? "Left" : "Right")
                        .arg(pos.x()).arg(pos.y());
        }
+       qDebug() << "QWheelEvent";
+       qDebug() << "  " << ev;
+       qDebug() << "  " << inp;
        m_nvim->api0()->vim_input(inp.toLatin1());
 }

You will need to build Debug for these messages to appear: -DCMAKE_BUILD_TYPE=Debug.

When you scroll, you should see lots of output like the following :

QWheelEvent
   QWheelEvent(Qt::NoScrollPhase, pixelDelta=QPoint(0,0), angleDelta=QPoint(0,-8))
   "<ScrollWheelDown><29,35>"
jgehrig commented 4 years ago

I also see some issues in master around scroll event position:

QWheelEvent
   QWheelEvent(Qt::NoScrollPhase, pixelDelta=QPoint(0,0), angleDelta=QPoint(0,80))
   "<ScrollWheelUp><                          35.2222,%4>"

It looks like Qt has changed to floating point QWheelEvents and I overlooked this in some recent changes. We should also fix the .arg and floating point issues.

My best guess for the direction issues is bad logic for direction_x and direction_y logic on MacOS.

Then we can add test coverage so scrolling doesn't break again in the future :)

psagers commented 4 years ago

I was able to get debug output, but I also updated to master and the direction is no longer chaotic. It still doesn't respect the system setting, but it's intelligible.

It also doesn't seem to scroll during the gesture. If I flick with two fingers, it will sluggishly catch up. If I drag slowly (which is more typical), it never moves.

Here's some representative output, in case it's useful. Batches of events appear after the end of a quick flick gesture. Longer, continuous gestures produce no output.

Thanks

QWheelEvent
   QWheelEvent(Qt::ScrollUpdate, pixelDelta=QPoint(0,-39), angleDelta=QPoint(0,-78))
   "<ScrollWheelUp><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollUpdate, pixelDelta=QPoint(-1,-59), angleDelta=QPoint(-2,-118))
   "<ScrollWheelUp><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollUpdate, pixelDelta=QPoint(0,-80), angleDelta=QPoint(0,-160))
   "<ScrollWheelUp><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,-312), angleDelta=QPoint(0,-624))
   "<ScrollWheelUp><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,-459), angleDelta=QPoint(0,-918))
   "<ScrollWheelUp><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,-347), angleDelta=QPoint(0,-694))
   "<ScrollWheelUp><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,-245), angleDelta=QPoint(0,-490))
   "<ScrollWheelUp><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,-137), angleDelta=QPoint(0,-274))
   "<ScrollWheelUp><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,-88), angleDelta=QPoint(0,-176))
   "<ScrollWheelUp><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,-72), angleDelta=QPoint(0,-144))
   "<ScrollWheelUp><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,-46), angleDelta=QPoint(0,-92))
   "<ScrollWheelUp><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,-31), angleDelta=QPoint(0,-62))
   "<ScrollWheelUp><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,33), angleDelta=QPoint(0,66))
   "<ScrollWheelDown><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,174), angleDelta=QPoint(0,348))
   "<ScrollWheelDown><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,126), angleDelta=QPoint(0,252))
   "<ScrollWheelDown><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,79), angleDelta=QPoint(0,158))
   "<ScrollWheelDown><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,66), angleDelta=QPoint(0,132))
   "<ScrollWheelDown><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(0,43), angleDelta=QPoint(0,86))
   "<ScrollWheelDown><                       86.25,%4>"
QWheelEvent
   QWheelEvent(Qt::ScrollUpdate, pixelDelta=QPoint(31,1), angleDelta=QPoint(62,2))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollUpdate, pixelDelta=QPoint(32,1), angleDelta=QPoint(64,2))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollUpdate, pixelDelta=QPoint(32,1), angleDelta=QPoint(64,2))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollUpdate, pixelDelta=QPoint(45,0), angleDelta=QPoint(90,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(60,0), angleDelta=QPoint(120,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(65,0), angleDelta=QPoint(130,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(130,0), angleDelta=QPoint(260,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(60,0), angleDelta=QPoint(120,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(58,0), angleDelta=QPoint(116,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(60,0), angleDelta=QPoint(120,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(56,0), angleDelta=QPoint(112,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(53,0), angleDelta=QPoint(106,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(49,0), angleDelta=QPoint(98,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(45,0), angleDelta=QPoint(90,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(41,0), angleDelta=QPoint(82,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(38,0), angleDelta=QPoint(76,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(35,0), angleDelta=QPoint(70,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(32,0), angleDelta=QPoint(64,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(30,0), angleDelta=QPoint(60,0))
   "<ScrollWheelRight><86.25,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollUpdate, pixelDelta=QPoint(-38,2), angleDelta=QPoint(-76,4))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollUpdate, pixelDelta=QPoint(-40,1), angleDelta=QPoint(-80,2))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollUpdate, pixelDelta=QPoint(-48,-1), angleDelta=QPoint(-96,-2))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollUpdate, pixelDelta=QPoint(-71,-2), angleDelta=QPoint(-142,-4))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollUpdate, pixelDelta=QPoint(-101,0), angleDelta=QPoint(-202,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-124,0), angleDelta=QPoint(-248,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-125,0), angleDelta=QPoint(-250,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-122,0), angleDelta=QPoint(-244,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-117,0), angleDelta=QPoint(-234,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-111,0), angleDelta=QPoint(-222,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-105,0), angleDelta=QPoint(-210,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-194,0), angleDelta=QPoint(-388,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-175,0), angleDelta=QPoint(-350,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-229,0), angleDelta=QPoint(-458,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-66,0), angleDelta=QPoint(-132,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-174,0), angleDelta=QPoint(-348,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-51,0), angleDelta=QPoint(-102,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-130,0), angleDelta=QPoint(-260,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-37,0), angleDelta=QPoint(-74,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-34,0), angleDelta=QPoint(-68,0))
   "<ScrollWheelLeft><86,28.8667>"
QWheelEvent
   QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(-31,0), angleDelta=QPoint(-62,0))
   "<ScrollWheelLeft><86,28.8667>"
jgehrig commented 3 years ago

Let's try to fix this issue.

Can anyone provide me with some more debug output from build #797? (I don't have access to MacOS hardware)

  1. Build the PR above.
  2. Open neovim-qt.
  3. Perform one short scroll in a single direction.
  4. Copy the terminal output from step 3. Add a note which direction you scrolled (up, down, left, right)

A vertical event is most useful. A horizontal event would also be helpful. The buffer doesn't need to actually move/scroll, we are only trying to capture the raw mouse events. Events are sent regardless of the buffer state.

The output should look something like this:

QWheelEvent(Qt::NoScrollPhase, pixelDelta=QPoint(0,0), angleDelta=QPoint(0,-8))
  angleDelta: QPoint(0,-8)
  button: QFlags<Qt::MouseButton>(NoButton)
  globalPosition: QPointF(272,1110)
  inverted: false
  phase: Qt::NoScrollPhase
  pixelDelta: QPoint(0,0)
  position: QPointF(272,1045)
  source: Qt::MouseEventNotSynthesized
  deltasPerStep: 120
  m_scrollDeltaRemainder: QPoint(56,0)
    evString: "<ScrollWheelDown><30,47>"

My goal here is to write test coverage for this scenario. If we can add a test, we can fix the problem and guarantee it continues to work in the future.

Thanks!

Mathijs-Bakker commented 3 years ago

Hi! I don't get any test output when running the nvim-qt.app

This is what I did:

> gh pr checkout 797
> mkdir build
> cd build
> cmake -DCMAKE_BUILD_TYPE=Release ..
> make
> cd bin
> open Nvim-qt.app
jgehrig commented 3 years ago

@Mathijs-Bakker

Release builds don't have qDebug() output.

You should see the output if you change Line 4: cmake -DCMAKE_BUILD_TYPE=Debug

I assume you see the reversed scrolling behavior? If so, thanks for helping with this!

Mathijs-Bakker commented 3 years ago

@jgehrig Confirmed. The debug build has the correct scrolling behavior!

korya commented 3 years ago

I have the same problem -- the scroll direction is inverted on MacOs.

$ nvim-qt --version
NVIM-QT v0.2.16.1
Build type: Release
Compilation: -Wall -Wextra -Wno-unused-parameter -std=c++11 -Wfatal-errors
Qt Version: 5.15.2
Environment:
  nvim: nvim
  args: --cmd let &rtp.=',/usr/local/Cellar/neovim-qt/0.2.16.1/nvim-qt.app/Contents/MacOS/../Resources/runtime' --cmd set termguicolors
  runtime: /usr/local/Cellar/neovim-qt/0.2.16.1/nvim-qt.app/Contents/MacOS/../Resources/runtime

NVIM v0.5.1
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20210927-21425-quzo0s/neovim-0.5.1/build/config -I/tmp/neovim-20210927-21425-quzo0s/neovim-0.5.1/src -I/usr/local/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -I/usr/local/opt/gettext/include -I/tmp/neovim-20210927-21425-quzo0s/neovim-0.5.1/build/src/nvim/auto -I/tmp/neovim-20210927-21425-quzo0s/neovim-0.5.1/build/include
Compiled by brew@iMac-Pro

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.5.1/share/nvim"

Run :checkhealth for more info

Is there an option to invert it?

jgehrig commented 3 years ago

@korya

Is there an option to invert it?

No, there is no option to invert the scrolling.

I cannot reproduce the issue... First we need to understand what is going wrong here.

Are you willing to provide debug info with the steps above? (let me know, and I will update #797)

smathy commented 8 months ago

Reviving this hopefully.

I applied the patch from #797 to latest master. It's still scrolling the viewport, not the content (ie. a scrollup on the mouse moves the content down), which is not what I have set in my OS.

I get this debug output when I scroll up on the mouse:

QWheelEvent(Qt::NoScrollPhase, pixelDelta=QPoint(0,-40), angleDelta=QPoint(0,-120))
  angleDelta: QPoint(0,-120)
  button: QFlags<Qt::MouseButton>(NoButton)
  globalPosition: QPointF(1444.24,586.703)
  inverted: true
  phase: Qt::NoScrollPhase
  pixelDelta: QPoint(0,-40)
  position: QPointF(1444,534)
  source: Qt::MouseEventNotSynthesized
  deltasPerStep: 120
  m_scrollDeltaRemainder: 120
  evString: "<ScrollWheelUp><206,41>"

...and this for a scroll down:

QWheelEvent(Qt::NoScrollPhase, pixelDelta=QPoint(0,40), angleDelta=QPoint(0,120))                                                                                                       master f5c95b1 12:23:23
  angleDelta: QPoint(0,120)
  button: QFlags<Qt::MouseButton>(NoButton)
  globalPosition: QPointF(1935.75,419.566)
  inverted: true
  phase: Qt::NoScrollPhase
  pixelDelta: QPoint(0,40)
  position: QPointF(1936,367)
  source: Qt::MouseEventNotSynthesized
  deltasPerStep: 120
  m_scrollDeltaRemainder: 120
  evString: "<ScrollWheelDown><276,28>"

FWIW, I get the same debug and behavior when I set the OS option to reverse the scroll direction. Ie. that setting doesn't change the neovim-qt behavior.

smathy commented 8 months ago

FWIW, I get the same debug and behavior when I set the OS option to reverse the scroll direction. Ie. that setting doesn't change the neovim-qt behavior.

Correction, the inverted value is false.

smathy commented 8 months ago

Ok, so @jgehrig, what I think is happening here is that Qt (at least on MacOS) is now already making the invert adjustment in angleDelta.

Both of these are "wheel-up" movements, but first with invert set, and then without:

MacOS Default "Natural" scroll (scrolling content, not viewport)

QWheelEvent(Qt::ScrollMomentum, pixelDelta=QPoint(1,-3), angleDelta=QPoint(2,-6))
  angleDelta: QPoint(2,-6)
  inverted: true
  position: QPointF(550,339)
  deltasPerStep: 120
  m_scrollDeltaRemainder: QPoint(-48,2)
  evString: "<ScrollWheelUp><78,26><ScrollWheelRight><78,26>"

Viewport scolling

QWheelEvent(Qt::ScrollUpdate, pixelDelta=QPoint(0,2), angleDelta=QPoint(0,4))
  angleDelta: QPoint(0,4)
  inverted: false
  position: QPointF(646,497)
  deltasPerStep: 120
  m_scrollDeltaRemainder: QPoint(-98,2)
  evString: "<ScrollWheelUp><92,38><ScrollWheelRight><92,38>"

Note the angleDelta.y(), it comes out of Qt already inverted, so then your code re-inverts it with the ev.angleDelta() * invertConstant logic. I confirmed that by removing that logic, all works as expected.

smathy commented 8 months ago

For any Mac users out there:

diff --git a/src/gui/shell.cpp b/src/gui/shell.cpp
index 1486b82..08ecea4 100644
--- a/src/gui/shell.cpp
+++ b/src/gui/shell.cpp
@@ -1498,9 +1498,7 @@ void Shell::wheelEvent(QWheelEvent *ev)
    QSize cellSize,
    int deltasPerStep) noexcept
 {
-   int invertConstant{ (ev.inverted()) ? -1 : 1 };
-
-   QPoint scrollRemainderAndEvent { (ev.angleDelta() * invertConstant) + scrollRemainderOut };
+   QPoint scrollRemainderAndEvent { ev.angleDelta() + scrollRemainderOut };

    scrollRemainderOut.rx() = scrollRemainderAndEvent.x() % deltasPerStep;
    scrollRemainderOut.ry() = scrollRemainderAndEvent.y() % deltasPerStep;
smathy commented 8 months ago

/cc @equalsraf ☝️

jgehrig commented 8 months ago

@smathy

Here is the Qt documentation: https://doc.qt.io/qt-6/qwheelevent.html#inverted

Based on my read of the docs, what you're saying above sounds correct. We should ignore QWheelEvent::inverted.

The inverted API can be used to ignore the OS setting for scroll direction: "With the inverted property a wheel event consumer can choose to always follow the direction of the wheel, regardless of the system settings".

It sounds like we want to delete the constant for everyone. Feel free to open a PR, and I will merge it. Or if you'd prefer, I can take your diff above and commit it.

Thanks for your thorough investigation! :)

smathy commented 8 months ago

Wow, yeah, that's the smoking gun. I'd looked all over the angleDelta docs for something saying that.

I need no glory, feel free to just commit my diff above, happy to help.

smathy commented 8 months ago

FWIW, I think it makes sense that you only heard about this from MacOS people, that's the only OS crazy (ahem, cool) enough to standardize on inverted scrolling :)

smathy commented 8 months ago

I've added the PR.