From afd92d0a3d9a7f591196cea1abc3c4487d6ee6cd Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Sat, 17 Nov 2018 23:10:48 +0100 Subject: [PATCH] seat: add utilities to Seat --- src/wayland/seat/mod.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/wayland/seat/mod.rs b/src/wayland/seat/mod.rs index 65e0815..41e60d1 100644 --- a/src/wayland/seat/mod.rs +++ b/src/wayland/seat/mod.rs @@ -144,6 +144,13 @@ impl Seat { (seat, global) } + /// Attempt to retrieve a `Seat` from an existing resource + pub fn from_resource(seat: &Resource) -> Option { + seat.user_data::>>() + .cloned() + .map(|inner| Seat { inner }) + } + /// Adds the pointer capability to this seat /// /// You are provided a `PointerHandle`, which allows you to send input events @@ -166,6 +173,11 @@ impl Seat { pointer } + /// Access the pointer of this seat if any + pub fn get_pointer(&self) -> Option { + self.inner.lock().unwrap().pointer.clone() + } + /// Remove the pointer capability from this seat /// /// Clients will be appropriately notified. @@ -228,6 +240,11 @@ impl Seat { Ok(keyboard) } + /// Access the keyboard of this seat if any + pub fn get_keyboard(&self) -> Option { + self.inner.lock().unwrap().keyboard.clone() + } + /// Remove the keyboard capability from this seat /// /// Clients will be appropriately notified. @@ -252,8 +269,8 @@ fn implement_seat( ) -> Resource { let dest_inner = inner.clone(); new_seat.implement( - move |request, _seat| { - let inner = inner.lock().unwrap(); + move |request, seat| { + let inner = seat.user_data::>>().unwrap().lock().unwrap(); match request { wl_seat::Request::GetPointer { id } => { let pointer = self::pointer::implement_pointer(id, inner.pointer.as_ref()); @@ -287,6 +304,6 @@ fn implement_seat( .known_seats .retain(|s| !s.equals(&seat)); }), - (), + inner, ) }