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

Unexpected mouse events when using the touchpad on MacOS #1222

Closed
mikolajsnioch opened this issue Jan 24, 2022 · 6 comments
Closed

Unexpected mouse events when using the touchpad on MacOS #1222

mikolajsnioch opened this issue Jan 24, 2022 · 6 comments
Labels
bug Something isn't working compatibility shell

Comments

@mikolajsnioch
Copy link

System: macOS Monterey 12.1, Apple Silicon

It seems that when using the touchpad, events that are passed on to widgets are not correct. Some are missing, some are included when they should not be.

  1. When I move the cursor from outside the window into it, I receive correct event types:
CursorEntered
CursorMoved { position: Point { x: 485.67578, y: 0.1796875 } }
CursorMoved { position: Point { x: 483.41016, y: 3.3515625 } }
(more...)
  1. When I move the cursor inside the Window, over it and then outside, CursorLeft is not produced:
CursorEntered
CursorMoved { position: Point { x: 498.79297, y: 29.074219 } }
CursorMoved { position: Point { x: 495.82813, y: 29.074219 } }
CursorMoved { position: Point { x: 493.98047, y: 29.074219 } }
CursorMoved { position: Point { x: 490.35547, y: 29.074219 } }
CursorMoved { position: Point { x: 486.02734, y: 29.074219 } }
CursorMoved { position: Point { x: 483.05078, y: 29.074219 } }
CursorMoved { position: Point { x: 480.07422, y: 29.074219 } }
CursorMoved { position: Point { x: 477.09766, y: 29.074219 } }
CursorMoved { position: Point { x: 474.1211, y: 28.652344 } }
CursorMoved { position: Point { x: 469.29688, y: 27.066406 } }
CursorMoved { position: Point { x: 464.53125, y: 24.691406 } }
CursorMoved { position: Point { x: 460.30078, y: 22.398438 } }
CursorMoved { position: Point { x: 456.46484, y: 19.707031 } }
CursorMoved { position: Point { x: 453.5039, y: 16.753906 } }
CursorMoved { position: Point { x: 449.90625, y: 13.1640625 } }
CursorMoved { position: Point { x: 447.39844, y: 10.6640625 } }
CursorMoved { position: Point { x: 444.2461, y: 7.09375 } }
CursorMoved { position: Point { x: 441.73828, y: 4.59375 } }
CursorMoved { position: Point { x: 439.23828, y: 2.1015625 } }
CursorMoved { position: Point { x: 437.58203, y: 0.140625 } }
  1. If i click the touchpad to produce a ButtonPressed(Button::Left), I receive a number ofCursorMoved events before ButtonReleased(Button::Left) is produced. If I keep the button pressed, CursorMoved will continue to be received until I release the button. The same behavior can be observed with Button::Right:
ButtonPressed(Left)
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
CursorMoved { position: Point { x: 464.9961, y: 341.35156 } }
ButtonReleased(Left)
  1. CursorMoved events are also produced when using a two-finger gesture equivalent to scrolling the wheel:
WheelScrolled { delta: Pixels { x: -0.0, y: 0.0 } }
CursorMoved { position: Point { x: 332.1172, y: 167.69922 } }
WheelScrolled { delta: Pixels { x: -0.0, y: -1.0 } }
CursorMoved { position: Point { x: 332.1172, y: 167.69922 } }
WheelScrolled { delta: Pixels { x: -0.0, y: -4.0 } }
CursorMoved { position: Point { x: 332.1172, y: 167.69922 } }
WheelScrolled { delta: Pixels { x: 1.0, y: -7.0 } }
CursorMoved { position: Point { x: 332.1172, y: 167.69922 } }
WheelScrolled { delta: Pixels { x: 1.0, y: -8.0 } }
CursorMoved { position: Point { x: 332.1172, y: 167.69922 } }
WheelScrolled { delta: Pixels { x: 1.0, y: -8.0 } }
CursorMoved { position: Point { x: 332.1172, y: 167.69922 } }
WheelScrolled { delta: Pixels { x: 1.0, y: -8.0 } }
CursorMoved { position: Point { x: 332.1172, y: 167.69922 } }
WheelScrolled { delta: Pixels { x: 1.0, y: -7.0 } }
CursorMoved { position: Point { x: 332.1172, y: 167.69922 } }
WheelScrolled { delta: Pixels { x: 1.0, y: -6.0 } }
CursorMoved { position: Point { x: 332.1172, y: 167.69922 } }
WheelScrolled { delta: Pixels { x: 1.0, y: -5.0 } }
CursorMoved { position: Point { x: 332.1172, y: 167.69922 } }
WheelScrolled { delta: Pixels { x: 1.0, y: -5.0 } }
CursorMoved { position: Point { x: 332.1172, y: 167.69922 } }
WheelScrolled { delta: Pixels { x: 1.0, y: -4.0 } }
CursorMoved { position: Point { x: 332.1172, y: 167.69922 } }
WheelScrolled { delta: Pixels { x: -0.0, y: -2.0 } }
CursorMoved { position: Point { x: 332.1172, y: 167.69922 } }

My suspicion is that there are two separate issues at play here:

  1. Incorrect handling of the Apple Touchpad - it seems that CursorMoved is always produced when the touchpad is touched, regardless of what the user does with it. What is interesting is that in the mouse wheel scenario, I am moving my fingers down, which is reflected in the negative delta on the WheelScrolled message, but the coordinates of CursorMoved.point are static
  2. Window focus - I noticed that, unlike on Linux, the application does not respond to mouse events until I click on it to focus it. It stops reacting to them when the cursor leaves window bounds. I think this is behind the missing CursorLeft message
@mikolajsnioch
Copy link
Author

What is interesting is that in the mouse wheel scenario, I am moving my fingers down, which is reflected in the negative delta on the WheelScrolled message, but the coordinates of CursorMoved.point are static

This is actually the case with all CursorMoved events that are invalid

@mikolajsnioch
Copy link
Author

Perhaps related to this rust-windowing/winit#1418 (comment)

@mikolajsnioch
Copy link
Author

mikolajsnioch commented Jan 24, 2022

Going a bit deeper into this. In winit/src/platform_impl/macos/app.rs there's a function called send_event. I set a debug point there and was observing event types. For the left mouse button click and hold scenario I see the following series of events:

NSLeftMouseDown
NSAppKitDefined
NSEventTypePressure
NSEventTypePressure
(... repeated ...)
NSSystemDefined (optionally?)
NSLeftMouseUp

The ones that are suspicious in the context of the error defined above are, in my opinion, NSEventTypePressure.

@hecrj
Copy link
Member

hecrj commented Jan 25, 2022

Is this on master? I get CursorLeft to trigger just fine!

The other issues are most likely related to winit, as you pointed out. Could you try the winit examples and see if the problem is present there? If it is, then we should report the issue there!

@mikolajsnioch
Copy link
Author

Is this on master? I get CursorLeft to trigger just fine!

The other issues are most likely related to winit, as you pointed out. Could you try the winit examples and see if the problem is present there? If it is, then we should report the issue there!

Hey Hector,

Yes, this is on master and you are right about CursorLeft. I created a minimal example and it works normally, so I must have some issue in my code. Perhaps the event is captured by one of child widgets.

Regarding other events, I am still looking into it. Let's keep this issue open for now. Once I get to the bottom of the matter I will either close or post an update.

Thanks!

@hecrj hecrj added bug Something isn't working compatibility shell labels Jan 26, 2022
@mikolajsnioch
Copy link
Author

I think this is platform specific and not a bug. I am a relatively new mac user and it got me confused. I observed the same behavior in other applications including Windows programs running in a VM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compatibility shell
Projects
None yet
Development

No branches or pull requests

2 participants