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

Sequence of mouse movements seems out of order when using trackpad on macOS #3516

Closed
dmbfm opened this issue Feb 23, 2024 · 5 comments · Fixed by #3601
Closed

Sequence of mouse movements seems out of order when using trackpad on macOS #3516

dmbfm opened this issue Feb 23, 2024 · 5 comments · Fixed by #3601

Comments

@dmbfm
Copy link

dmbfm commented Feb 23, 2024

I'm developing a drawing application and I noticed a weird artifact with mouse positions when drawing with a trackpad on macOS (I'm using a macbook M1 pro on macOS 14.3.1, and using winit 0.29.10).

What I do is each frame I collect all of the incoming positions CursorMoved window event and store them in a vec. Then when it comes to draw the frame I connect these points with lines.

When using a mouse everything works fine, but when using a trackpad I noticed that I got a lot of weird loops and spikes coming out of the drawn lines. For instance:

Screenshot 2024-02-23 at 09 30 12

In the image above different colors refer to different frames. Notice that the blue line does a sort of 'V' shape, so it appears the mouse locations are coming in out of order.

By commenting out this line,

self.mouse_motion(event);

which then blocks the pressureChange event from emitting CursorMoved events, this artifacts go away and everything works correctly.

It seems like the position from pressureChange is not equivalent from regular mouse positions, or maybe macOS does not process them in the same order, causing these loops to appear.

@dmbfm dmbfm changed the title Sequence of mouse movements seems wrong when using trackpad on macOS Sequence of mouse movements seems out of order when using trackpad on macOS Feb 23, 2024
@madsmtm
Copy link
Member

madsmtm commented Mar 14, 2024

Huh, in general, I find it odd the amount of places we're calling mouse_motion; I'd imagine they only really need calling inside mouseMoved:, mouseDragged:, rightMouseDragged: and otherMouseDragged:, it should be redundant everywhere else.

Will need to do some digging in the project history to see why it is like it is.

@madsmtm
Copy link
Member

madsmtm commented Mar 15, 2024

This was added in #1490, but I can't seem to reproduce the original issue, it's possible that issue has been fixed in macOS itself in the meantime, and the workaround is unnecessary in newer versions?

@madsmtm
Copy link
Member

madsmtm commented Mar 15, 2024

I tried debug-logging the data in the event sent to pressureChangeWithEvent:, but from my findings, it appears to be executed after mouseMoved:, and always with the same data as mouseMoved:. So while perhaps a bit inefficient, because we emit the same event twice, it doesn't seem like it should cause the issues you're seeing?

Can you provide a minimal example where you can reproduce the jittery behaviour? Maybe by trying one of the examples in this repo (likely window), click-drag your mouse across the window, and see if the output is jittery?

@dmbfm
Copy link
Author

dmbfm commented Mar 15, 2024

I had a hard time identifying the jitter via the window example, but this not-so-minimal project reproduces the issue on my machine: https://github.com/dmbfm/winit-macos-mouse-movement

Here is an example:

image

I just updated to macOS 14.4 and the issue still happens. Maybe it is specific to the macbook M1 pro because of the 120hz refresh rate or something like that?

madsmtm added a commit that referenced this issue Mar 21, 2024
In particular, we don't want to emit those events inside of
`pressureChangeWithEvent:`, since the mouse motion value is sometimes
outdated.

Fixes #3516
madsmtm added a commit that referenced this issue Mar 21, 2024
In particular, we don't want to emit those events inside of
`pressureChangeWithEvent:`, since the mouse motion value is sometimes
outdated.

Fixes #3516
madsmtm added a commit that referenced this issue Mar 21, 2024
In particular, we don't want to emit those events inside of
`pressureChangeWithEvent:`, since the mouse motion value is sometimes
outdated.

Additionally, we want to ensure the events have been emitted during
other gestures.

Fixes #3516
@madsmtm
Copy link
Member

madsmtm commented Mar 21, 2024

Thanks for the example, I could reproduce the problem (even with a refresh rate of 60Hz, so I don't think that's it).

I've opened #3601 to fix this in the manner you suggested to begin with.

madsmtm added a commit that referenced this issue Mar 22, 2024
In particular, we don't want to emit those events inside of
`pressureChangeWithEvent:`, since the mouse motion value is sometimes
outdated.

Additionally, we want to ensure the events have been emitted during
other gestures.

Fixes #3516
madsmtm added a commit that referenced this issue Mar 28, 2024
In particular, we don't want to emit those events inside of
`pressureChangeWithEvent:`, since the mouse motion value is sometimes
outdated.

Additionally, we want to ensure the events have been emitted during
other gestures.

Fixes #3516
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants