1
0
Fork 0
forked from wry/wry

wl-pointer: don't send motion events if the position did not change

This commit is contained in:
Julian Orth 2024-05-08 15:55:02 +02:00
parent 760658522c
commit 4c0e6d9b51
2 changed files with 7 additions and 1 deletions

View file

@ -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);

View file

@ -74,6 +74,7 @@ pub struct WlPointer {
id: WlPointerId,
pub seat: Rc<WlSeat>,
pub tracker: Tracker<Self>,
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,