seat: add utilities to Seat

This commit is contained in:
Victor Berger 2018-11-17 23:10:48 +01:00
parent 03cf6ed35f
commit afd92d0a3d
1 changed files with 20 additions and 3 deletions

View File

@ -144,6 +144,13 @@ impl Seat {
(seat, global) (seat, global)
} }
/// Attempt to retrieve a `Seat` from an existing resource
pub fn from_resource(seat: &Resource<wl_seat::WlSeat>) -> Option<Seat> {
seat.user_data::<Arc<Mutex<Inner>>>()
.cloned()
.map(|inner| Seat { inner })
}
/// Adds the pointer capability to this seat /// Adds the pointer capability to this seat
/// ///
/// You are provided a `PointerHandle`, which allows you to send input events /// You are provided a `PointerHandle`, which allows you to send input events
@ -166,6 +173,11 @@ impl Seat {
pointer pointer
} }
/// Access the pointer of this seat if any
pub fn get_pointer(&self) -> Option<PointerHandle> {
self.inner.lock().unwrap().pointer.clone()
}
/// Remove the pointer capability from this seat /// Remove the pointer capability from this seat
/// ///
/// Clients will be appropriately notified. /// Clients will be appropriately notified.
@ -228,6 +240,11 @@ impl Seat {
Ok(keyboard) Ok(keyboard)
} }
/// Access the keyboard of this seat if any
pub fn get_keyboard(&self) -> Option<KeyboardHandle> {
self.inner.lock().unwrap().keyboard.clone()
}
/// Remove the keyboard capability from this seat /// Remove the keyboard capability from this seat
/// ///
/// Clients will be appropriately notified. /// Clients will be appropriately notified.
@ -252,8 +269,8 @@ fn implement_seat(
) -> Resource<wl_seat::WlSeat> { ) -> Resource<wl_seat::WlSeat> {
let dest_inner = inner.clone(); let dest_inner = inner.clone();
new_seat.implement( new_seat.implement(
move |request, _seat| { move |request, seat| {
let inner = inner.lock().unwrap(); let inner = seat.user_data::<Arc<Mutex<Inner>>>().unwrap().lock().unwrap();
match request { match request {
wl_seat::Request::GetPointer { id } => { wl_seat::Request::GetPointer { id } => {
let pointer = self::pointer::implement_pointer(id, inner.pointer.as_ref()); let pointer = self::pointer::implement_pointer(id, inner.pointer.as_ref());
@ -287,6 +304,6 @@ fn implement_seat(
.known_seats .known_seats
.retain(|s| !s.equals(&seat)); .retain(|s| !s.equals(&seat));
}), }),
(), inner,
) )
} }