Add from_resource to KeyboardHandle/PointerHandle/TouchHandle
Some checks are pending
Continuous Integration / format (push) Waiting to run
Continuous Integration / clippy-check (push) Waiting to run
Continuous Integration / check-msrv (push) Blocked by required conditions
Continuous Integration / check-minimal (push) Blocked by required conditions
Continuous Integration / smithay-check-features (push) Waiting to run
Continuous Integration / smithay-tests (push) Blocked by required conditions
Continuous Integration / smallvil-check (push) Blocked by required conditions
Continuous Integration / anvil-check-features (push) Blocked by required conditions
Continuous Integration / WLCS: ${{ matrix.job_name }} (buffer, BadBufferTest*, Bad Buffer Test) (push) Blocked by required conditions
Continuous Integration / WLCS: ${{ matrix.job_name }} (core, SelfTest*:FrameSubmission*, Core tests) (push) Blocked by required conditions
Continuous Integration / WLCS: ${{ matrix.job_name }} (output, XdgOutputV1Test*, Output tests) (push) Blocked by required conditions
Continuous Integration / WLCS: ${{ matrix.job_name }} (pointer-input, */SurfacePointerMotionTest*:RelativePointer*, Pointer input tests) (push) Blocked by required conditions
Continuous Integration / Documentation on Github Pages (push) Blocked by required conditions

It seems most protocols take a `wl_seat` as an argument rather than a
capability type, but it seems reasonable for Smithay to expose this in
some way to compositors still.
This commit is contained in:
Ian Douglas Scott 2024-07-29 12:19:47 -07:00 committed by Victoria Brekenfeld
parent aa5ea75a24
commit 605b34ef53
3 changed files with 31 additions and 1 deletions

View file

@ -21,7 +21,7 @@ use crate::{
wayland::{input_method::InputMethodSeat, text_input::TextInputSeat},
};
impl<D: SeatHandler + 'static> KeyboardHandle<D>
impl<D> KeyboardHandle<D>
where
D: SeatHandler + 'static,
<D as SeatHandler>::KeyboardFocus: WaylandFocus,
@ -82,6 +82,16 @@ where
}
}
impl<D: SeatHandler + 'static> KeyboardHandle<D> {
/// Attempt to retrieve a [`KeyboardHandle`] from an existing resource
///
/// May return `None` for a valid `WlKeyboard` that was created without
/// the keyboard capability.
pub fn from_resource(seat: &WlKeyboard) -> Option<Self> {
seat.data::<KeyboardUserData<D>>()?.handle.clone()
}
}
/// User data for keyboard
pub struct KeyboardUserData<D: SeatHandler> {
pub(crate) handle: Option<KeyboardHandle<D>>,

View file

@ -39,6 +39,16 @@ struct V120UserData {
/// WlSurface role of a cursor image icon
pub const CURSOR_IMAGE_ROLE: &str = "cursor_image";
impl<D: SeatHandler + 'static> PointerHandle<D> {
/// Attempt to retrieve a [`PointerHandle`] from an existing resource
///
/// May return `None` for a valid `WlPointer` that was created without
/// the keyboard capability.
pub fn from_resource(seat: &WlPointer) -> Option<Self> {
seat.data::<PointerUserData<D>>()?.handle.clone()
}
}
#[derive(Debug, Default)]
pub(crate) struct WlPointerHandle {
pub(crate) last_enter: Mutex<Option<Serial>>,

View file

@ -22,6 +22,16 @@ impl<D: SeatHandler> TouchHandle<D> {
}
}
impl<D: SeatHandler + 'static> TouchHandle<D> {
/// Attempt to retrieve a [`TouchHandle`] from an existing resource
///
/// May return `None` for a valid `WlTouch` that was created without
/// the keyboard capability.
pub fn from_resource(seat: &WlTouch) -> Option<Self> {
seat.data::<TouchUserData<D>>()?.handle.clone()
}
}
fn for_each_focused_touch<D: SeatHandler + 'static>(
seat: &Seat<D>,
surface: &WlSurface,