From 82b416fcbf846f883b145c5b14d84e6b3d5a0572 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Wed, 27 Nov 2024 13:15:56 +0100 Subject: [PATCH] ei: implement ei_touchscreen v2 --- src/ei/ei_ifs/ei_device.rs | 1 + src/ei/ei_ifs/ei_seat.rs | 13 +++++++++++++ src/ei/ei_ifs/ei_touchscreen.rs | 21 ++++++++++++++++++--- src/ifs/wl_seat/event_handling.rs | 4 ++-- wire-ei/ei_touchscreen.txt | 8 ++++++++ 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/ei/ei_ifs/ei_device.rs b/src/ei/ei_ifs/ei_device.rs index 46342a3e..81e6c3d6 100644 --- a/src/ei/ei_ifs/ei_device.rs +++ b/src/ei/ei_ifs/ei_device.rs @@ -233,6 +233,7 @@ impl EiDeviceRequestHandler for EiDevice { seat.touch_motion_at(time, id, x, y); } TouchChange::Up => seat.touch_up(time, id), + TouchChange::Cancel => seat.touch_cancel(time, id), } } seat.touch_frame(time); diff --git a/src/ei/ei_ifs/ei_seat.rs b/src/ei/ei_ifs/ei_seat.rs index d8469b40..430f55d5 100644 --- a/src/ei/ei_ifs/ei_seat.rs +++ b/src/ei/ei_ifs/ei_seat.rs @@ -197,6 +197,19 @@ impl EiSeat { } } + pub fn handle_touch_cancel(&self, id: u32) { + if self.is_sender() { + return; + } + if let Some(b) = self.touchscreen.get() { + if self.client.versions.ei_touchscreen() >= EiVersion(2) { + b.send_cancel(id); + } else { + b.send_up(id); + } + } + } + pub fn handle_touch_frame(&self, time_usec: u64) { if self.is_sender() { return; diff --git a/src/ei/ei_ifs/ei_touchscreen.rs b/src/ei/ei_ifs/ei_touchscreen.rs index a62dc06a..b9bb8dfb 100644 --- a/src/ei/ei_ifs/ei_touchscreen.rs +++ b/src/ei/ei_ifs/ei_touchscreen.rs @@ -10,8 +10,8 @@ use { utils::clonecell::UnsafeCellCloneSafe, wire_ei::{ ei_touchscreen::{ - ClientDown, ClientMotion, ClientUp, EiTouchscreenRequestHandler, Release, - ServerDown, ServerMotion, ServerUp, + ClientCancel, ClientDown, ClientMotion, ClientUp, EiTouchscreenRequestHandler, + Release, ServerCancel, ServerDown, ServerMotion, ServerUp, }, EiTouchscreenId, }, @@ -33,6 +33,7 @@ pub enum TouchChange { Down(f32, f32), Motion(f32, f32), Up, + Cancel, } unsafe impl UnsafeCellCloneSafe for TouchChange {} @@ -65,12 +66,22 @@ impl EiTouchscreen { }); } + pub fn send_cancel(&self, touchid: u32) { + self.client.event(ServerCancel { + self_id: self.id, + touchid, + }); + } + fn set_client_event(&self, touchid: u32, event: TouchChange) -> Result<(), EiTouchscreenError> { match self.device.touch_changes.lock().entry(touchid) { Entry::Occupied(mut o) => { use TouchChange::*; match (o.get(), event) { - (Motion(_, _), Motion(_, _)) | (Down(_, _), Down(_, _)) | (Up, Up) => { + (Motion(_, _), Motion(_, _)) + | (Down(_, _), Down(_, _)) + | (Up, Up) + | (Cancel, Cancel) => { o.insert(event); Ok(()) } @@ -104,6 +115,10 @@ impl EiTouchscreenRequestHandler for EiTouchscreen { fn client_up(&self, req: ClientUp, _slf: &Rc) -> Result<(), Self::Error> { self.set_client_event(req.touchid, TouchChange::Up) } + + fn client_cancel(&self, req: ClientCancel, _slf: &Rc) -> Result<(), Self::Error> { + self.set_client_event(req.touchid, TouchChange::Cancel) + } } ei_object_base! { diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index 159dd676..e3778b95 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -761,9 +761,9 @@ impl WlSeatGlobal { self.touch_owner.motion(self, time_usec, id, x, y); } - fn touch_cancel(self: &Rc, time_usec: u64, id: i32) { + pub fn touch_cancel(self: &Rc, time_usec: u64, id: i32) { self.for_each_ei_seat(|ei_seat| { - ei_seat.handle_touch_up(id as _); + ei_seat.handle_touch_cancel(id as _); }); self.state.for_each_seat_tester(|t| { t.send_touch_cancel(self.id, time_usec, id); diff --git a/wire-ei/ei_touchscreen.txt b/wire-ei/ei_touchscreen.txt index 2bca8286..3c732898 100644 --- a/wire-ei/ei_touchscreen.txt +++ b/wire-ei/ei_touchscreen.txt @@ -17,6 +17,10 @@ request client_up (sender) { touchid: u32, } +request client_cancel (sender, since = 2) { + touchid: u32, +} + event destroyed { serial: u32, } @@ -36,3 +40,7 @@ event server_motion (receiver) { event server_up (receiver) { touchid: u32, } + +event server_cancel (receiver, since = 2) { + touchid: u32, +}