From a2b4726ebc1b30c8f4c71d928fb74ae793af13b2 Mon Sep 17 00:00:00 2001 From: John Nunley Date: Sun, 25 Feb 2024 19:10:38 -0800 Subject: [PATCH] bugfix(x11): Filter out tiny mouse events 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 --- src/platform_impl/linux/x11/event_processor.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index c6cd61e9ae2..d84bd3ac8f4 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -44,6 +44,9 @@ pub const MAX_MOD_REPLAY_LEN: usize = 32; /// The X11 documentation states: "Keycodes lie in the inclusive range `[8, 255]`". const KEYCODE_OFFSET: u8 = 8; +/// Minimum delta for a device event to be considered. +const NOTGULL_THRESHOLD: f32 = 4.0e-8; + pub struct EventProcessor { pub dnd: Dnd, pub ime_receiver: ImeReceiver, @@ -1548,7 +1551,9 @@ impl EventProcessor { value = unsafe { value.offset(1) }; } - if mouse_delta != (0.0, 0.0) { + if mouse_delta.0.abs() as f32 >= NOTGULL_THRESHOLD + || mouse_delta.1.abs() as f32 >= NOTGULL_THRESHOLD + { let event = Event::DeviceEvent { device_id: did, event: DeviceEvent::MouseMotion { delta: mouse_delta }, @@ -1556,7 +1561,7 @@ impl EventProcessor { callback(&self.target, event); } - if scroll_delta != (0.0, 0.0) { + if scroll_delta.0.abs() >= NOTGULL_THRESHOLD || scroll_delta.1.abs() >= NOTGULL_THRESHOLD { let event = Event::DeviceEvent { device_id: did, event: DeviceEvent::MouseWheel {