From 4c0e6d9b51543487406ec68c49818d5ebf555316 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Wed, 8 May 2024 15:55:02 +0200 Subject: [PATCH] wl-pointer: don't send motion events if the position did not change --- src/fixed.rs | 2 +- src/ifs/wl_seat/wl_pointer.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/fixed.rs b/src/fixed.rs index 0b32769b..3bd02e9a 100644 --- a/src/fixed.rs +++ b/src/fixed.rs @@ -4,7 +4,7 @@ use std::{ ops::{Add, AddAssign, Sub, SubAssign}, }; -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)] #[repr(transparent)] pub struct Fixed(pub i32); diff --git a/src/ifs/wl_seat/wl_pointer.rs b/src/ifs/wl_seat/wl_pointer.rs index 839828cc..fa1f71f8 100644 --- a/src/ifs/wl_seat/wl_pointer.rs +++ b/src/ifs/wl_seat/wl_pointer.rs @@ -74,6 +74,7 @@ pub struct WlPointer { id: WlPointerId, pub seat: Rc, pub tracker: Tracker, + last_motion: Cell<(Fixed, Fixed)>, } impl WlPointer { @@ -82,10 +83,12 @@ impl WlPointer { id, seat: seat.clone(), tracker: Default::default(), + last_motion: Default::default(), } } pub fn send_enter(&self, serial: u32, surface: WlSurfaceId, x: Fixed, y: Fixed) { + self.last_motion.set((x, y)); self.seat.client.event(Enter { self_id: self.id, serial, @@ -104,6 +107,9 @@ impl WlPointer { } pub fn send_motion(&self, time: u32, x: Fixed, y: Fixed) { + if self.last_motion.replace((x, y)) == (x, y) { + return; + } self.seat.client.event(Motion { self_id: self.id, time,