wayland.seat: review docs & API

This commit is contained in:
Victor Berger 2021-07-01 23:24:05 +02:00 committed by Victor Berger
parent e96272cae5
commit 694666b31f
2 changed files with 7 additions and 22 deletions

View File

@ -103,7 +103,7 @@ impl Inner {
/// This struct gives you access to the control of the /// This struct gives you access to the control of the
/// capabilities of the associated seat. /// capabilities of the associated seat.
/// ///
/// It is directly inserted in the event loop by its [`new`](Seat::new) method. /// It is directly inserted in the wayland display by its [`new`](Seat::new) method.
/// ///
/// This is an handle to the inner logic, it can be cloned. /// This is an handle to the inner logic, it can be cloned.
/// ///
@ -117,7 +117,7 @@ impl Seat {
/// Create a new seat global /// Create a new seat global
/// ///
/// A new seat global is created with given name and inserted /// A new seat global is created with given name and inserted
/// into this event loop. /// into this wayland display.
/// ///
/// You are provided with the state token to retrieve it (allowing /// You are provided with the state token to retrieve it (allowing
/// you to add or remove capabilities from it), and the global handle, /// you to add or remove capabilities from it), and the global handle,
@ -176,8 +176,8 @@ impl Seat {
/// will overwrite it, and will be seen by the clients as if the /// will overwrite it, and will be seen by the clients as if the
/// mouse was unplugged and a new one was plugged. /// mouse was unplugged and a new one was plugged.
/// ///
/// You need to provide a compositor token, as well as a callback that will be notified /// You need to provide a callback that will be notified whenever a client requests
/// whenever a client requests to set a custom cursor image. /// to set a custom cursor image.
/// ///
/// # Examples /// # Examples
/// ///
@ -193,7 +193,7 @@ impl Seat {
/// # None /// # None
/// # ); /// # );
/// let pointer_handle = seat.add_pointer( /// let pointer_handle = seat.add_pointer(
/// |new_status| { /* a closure handling requests from clients tot change the cursor icon */ } /// |new_status| { /* a closure handling requests from clients to change the cursor icon */ }
/// ); /// );
/// ``` /// ```
pub fn add_pointer<F>(&mut self, cb: F) -> PointerHandle pub fn add_pointer<F>(&mut self, cb: F) -> PointerHandle

View File

@ -74,25 +74,10 @@ impl fmt::Debug for PointerInternal {
} }
impl PointerInternal { impl PointerInternal {
fn new<F>(mut cb: F) -> PointerInternal fn new<F>(cb: F) -> PointerInternal
where where
F: FnMut(CursorImageStatus) + 'static, F: FnMut(CursorImageStatus) + 'static,
{ {
let mut old_status = CursorImageStatus::Default;
let wrapper = move |new_status: CursorImageStatus| {
if let CursorImageStatus::Image(surface) =
::std::mem::replace(&mut old_status, new_status.clone())
{
match new_status {
CursorImageStatus::Image(ref new_surface) if new_surface == &surface => {
// don't remove the role, we are just re-binding the same surface
}
_ => {}
}
}
cb(new_status)
};
PointerInternal { PointerInternal {
known_pointers: Vec::new(), known_pointers: Vec::new(),
focus: None, focus: None,
@ -100,7 +85,7 @@ impl PointerInternal {
location: (0.0, 0.0), location: (0.0, 0.0),
grab: GrabStatus::None, grab: GrabStatus::None,
pressed_buttons: Vec::new(), pressed_buttons: Vec::new(),
image_callback: Box::new(wrapper) as Box<_>, image_callback: Box::new(cb) as Box<_>,
} }
} }