|
| 1 | +use crate::wayland::{WaylandError, WaylandResult, core::pointer::Pointer}; |
| 2 | +use mint::Vector2; |
| 3 | +use std::sync::Arc; |
| 4 | +use waynest::ObjectId; |
| 5 | +use waynest_protocols::server::unstable::relative_pointer_unstable_v1::{ |
| 6 | + zwp_relative_pointer_manager_v1::*, zwp_relative_pointer_v1::*, |
| 7 | +}; |
| 8 | +use waynest_server::Client as _; |
| 9 | + |
| 10 | +#[derive(Debug, waynest_server::RequestDispatcher)] |
| 11 | +#[waynest(error = crate::wayland::WaylandError, connection = crate::wayland::Client)] |
| 12 | +pub struct RelativePointerManager(pub ObjectId); |
| 13 | +impl ZwpRelativePointerManagerV1 for RelativePointerManager { |
| 14 | + type Connection = crate::wayland::Client; |
| 15 | + |
| 16 | + async fn destroy( |
| 17 | + &self, |
| 18 | + client: &mut Self::Connection, |
| 19 | + _sender_id: ObjectId, |
| 20 | + ) -> WaylandResult<()> { |
| 21 | + client.remove(self.0); |
| 22 | + Ok(()) |
| 23 | + } |
| 24 | + |
| 25 | + async fn get_relative_pointer( |
| 26 | + &self, |
| 27 | + client: &mut Self::Connection, |
| 28 | + _sender_id: ObjectId, |
| 29 | + id: ObjectId, |
| 30 | + pointer: ObjectId, |
| 31 | + ) -> WaylandResult<()> { |
| 32 | + let Some(pointer) = client.get::<Pointer>(pointer) else { |
| 33 | + return Err(WaylandError::MissingObject(pointer)); |
| 34 | + }; |
| 35 | + |
| 36 | + let relative_pointer = client.insert(id, RelativePointer(id))?; |
| 37 | + |
| 38 | + *pointer.relative_pointer.write().await = Arc::downgrade(&relative_pointer); |
| 39 | + |
| 40 | + Ok(()) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +#[derive(Debug, waynest_server::RequestDispatcher)] |
| 45 | +#[waynest(error = crate::wayland::WaylandError, connection = crate::wayland::Client)] |
| 46 | +pub struct RelativePointer(pub ObjectId); |
| 47 | +impl RelativePointer { |
| 48 | + pub async fn send_relative_motion( |
| 49 | + &self, |
| 50 | + client: &mut crate::wayland::Client, |
| 51 | + delta: Vector2<f32>, |
| 52 | + ) -> WaylandResult<()> { |
| 53 | + self.relative_motion( |
| 54 | + client, |
| 55 | + self.0, |
| 56 | + 0, |
| 57 | + 0, |
| 58 | + (delta.x as f64).into(), |
| 59 | + (delta.y as f64).into(), |
| 60 | + (delta.x as f64).into(), |
| 61 | + (delta.y as f64).into(), |
| 62 | + ) |
| 63 | + .await |
| 64 | + } |
| 65 | +} |
| 66 | +impl ZwpRelativePointerV1 for RelativePointer { |
| 67 | + type Connection = crate::wayland::Client; |
| 68 | + |
| 69 | + async fn destroy( |
| 70 | + &self, |
| 71 | + client: &mut Self::Connection, |
| 72 | + _sender_id: ObjectId, |
| 73 | + ) -> WaylandResult<()> { |
| 74 | + client.remove(self.0); |
| 75 | + Ok(()) |
| 76 | + } |
| 77 | +} |
0 commit comments