Skip to content

Commit

Permalink
bugfix(x11): Filter out tiny mouse events
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
notgull committed Feb 29, 2024
1 parent f0b4889 commit a2b4726
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1548,15 +1551,17 @@ 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 },
};
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 {
Expand Down

0 comments on commit a2b4726

Please sign in to comment.