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

X11: Mouse motion events sometimes contain garbage #3500

Closed
valaphee opened this issue Feb 18, 2024 · 2 comments · Fixed by #3523
Closed

X11: Mouse motion events sometimes contain garbage #3500

valaphee opened this issue Feb 18, 2024 · 2 comments · Fixed by #3523
Labels

Comments

@valaphee
Copy link
Contributor

valaphee commented Feb 18, 2024

While printing out events on X11, I noticed that sometimes (not always), the motion events are invalid:

DeviceEvent { device_id: DeviceId(X(DeviceId(2))), event: Motion { axis: 0, value: -1.0 } }
DeviceEvent { device_id: DeviceId(X(DeviceId(2))), event: Motion { axis: 1, value: 7.1e-322 } }
DeviceEvent { device_id: DeviceId(X(DeviceId(2))), event: MouseMotion { delta: (-1.0, 7.1e-322) } }

Only one axis gets reported and the second axis is just an unrelated value (most likely smth not belonging to the event).

for i in 0..xev.valuators.mask_len * 8 {
    if !xinput2::XIMaskIsSet(mask, i) {
        continue;
    }
    let x = unsafe { *value };

The easiest way I found to reproduce this is just moving the cursor between two monitors. It might also just be a x11 problem.

I'm running natively latest Arch Linux with Gnome using X11.

@valaphee valaphee changed the title Mouse motion events on X11 sometimes contain garbage X11: Mouse motion events sometimes contain garbage Feb 18, 2024
@notgull
Copy link
Member

notgull commented Feb 18, 2024

7.1e-322 is really close to zero, which makes me think this is an error in interpreting the data from the X11 server.

Can you reproduce this issue while running xtrace, then attach the logs?

@valaphee
Copy link
Contributor Author

valaphee commented Feb 18, 2024

XIRawEvent raw_values are used instead of XIRawEvent valuators values:

let mut value = xev.raw_values;

Replacing raw values with values yields way higher precision, (raw values only indicate if a value is zero, positive or negative at least with mouse devices) and doesn't has this problem.

I'll try to get a trace.

notgull added a commit that referenced this issue Feb 26, 2024
Usually, if mouse events are equal to (0, 0) we filter them out.
However, if the event is very close to zero it will still be given to
the user. In some cases this can be caused by bad float math on the X11
server side.

I fix this by refusing to forward events where both of their deltas fall
below a certain threshold.

Closes #3500

Signed-off-by: John Nunley <[email protected]>
notgull added a commit that referenced this issue Feb 29, 2024
Usually, if mouse events are equal to (0, 0) we filter them out.
However, if the event is very close to zero it will still be given to
the user. In some cases this can be caused by bad float math on the X11
server side.

I fix this by refusing to forward events where both of their deltas fall
below a certain threshold.

Closes #3500

Signed-off-by: John Nunley <[email protected]>
kchibisov pushed a commit that referenced this issue Mar 1, 2024
Usually, if mouse events are equal to (0, 0) we filter them out.
However, if the event is very close to zero it will still be given to
the user. In some cases this can be caused by bad float math on the X11
server side.

Fix it by filtering absolute values smaller than floating point epsilon.

Signed-off-by: John Nunley <[email protected]>
Closes: #3500
kchibisov pushed a commit that referenced this issue Mar 1, 2024
Usually, if mouse events are equal to (0, 0) we filter them out.
However, if the event is very close to zero it will still be given to
the user. In some cases this can be caused by bad float math on the X11
server side.

Fix it by filtering absolute values smaller than floating point epsilon.

Signed-off-by: John Nunley <[email protected]>
Closes: #3500
kchibisov pushed a commit that referenced this issue Mar 1, 2024
Usually, if mouse events are equal to (0, 0) we filter them out.
However, if the event is very close to zero it will still be given to
the user. In some cases this can be caused by bad float math on the X11
server side.

Fix it by filtering absolute values smaller than floating point epsilon.

Signed-off-by: John Nunley <[email protected]>
Closes: #3500
kchibisov pushed a commit that referenced this issue Mar 1, 2024
Usually, if mouse events are equal to (0, 0) we filter them out.
However, if the event is very close to zero it will still be given to
the user. In some cases this can be caused by bad float math on the X11
server side.

Fix it by filtering absolute values smaller than floating point epsilon.

Signed-off-by: John Nunley <[email protected]>
Closes: #3500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants