smithay::input::keyboard

Struct KeyboardHandle

Source
pub struct KeyboardHandle<D: SeatHandler> { /* private fields */ }
Expand description

An handle to a keyboard handler

It can be cloned and all clones manipulate the same internal state.

This handle gives you 2 main ways to interact with the keyboard handling:

  • set the current focus for this keyboard: designing the surface that will receive the key inputs using the KeyboardHandle::set_focus method.
  • process key inputs from the input backend, allowing them to be caught at the compositor-level or forwarded to the client. See the documentation of the KeyboardHandle::input method for details.

Implementations§

Source§

impl<D: SeatHandler + 'static> KeyboardHandle<D>

Source

pub fn set_keymap_from_string( &self, data: &mut D, keymap: String, ) -> Result<(), Error>

Change the Keymap used by the keyboard.

The input is a keymap in XKB_KEYMAP_FORMAT_TEXT_V1 format.

Source

pub fn set_xkb_config( &self, data: &mut D, xkb_config: XkbConfig<'_>, ) -> Result<(), Error>

Change the XkbConfig used by the keyboard.

Source

pub fn with_xkb_state<F, T>(&self, data: &mut D, callback: F) -> T
where F: FnMut(XkbContext<'_>) -> T,

Access the underlying Xkb state and perform mutable operations on it, like changing layouts.

The changes to the state are automatically broadcasted to the focused client on exit.

Source

pub fn set_grab<G: KeyboardGrab<D> + 'static>( &self, data: &mut D, grab: G, serial: Serial, )

Change the current grab on this keyboard to the provided grab

Overwrites any current grab.

Source

pub fn unset_grab(&self, data: &mut D)

Remove any current grab on this keyboard, resetting it to the default behavior

Source

pub fn has_grab(&self, serial: Serial) -> bool

Check if this keyboard is currently grabbed with this serial

Source

pub fn is_grabbed(&self) -> bool

Check if this keyboard is currently being grabbed

Source

pub fn grab_start_data(&self) -> Option<GrabStartData<D>>

Returns the start data for the grab, if any.

Source

pub fn with_grab<T>( &self, f: impl FnOnce(Serial, &dyn KeyboardGrab<D>) -> T, ) -> Option<T>

Calls f with the active grab, if any.

Source

pub fn input<T, F>( &self, data: &mut D, keycode: Keycode, state: KeyState, serial: Serial, time: u32, filter: F, ) -> Option<T>

Handle a keystroke

All keystrokes from the input backend should be fed in order to this method of the keyboard handler. It will internally track the state of the keymap.

The filter argument is expected to be a closure which will peek at the generated input as interpreted by the keymap before it is forwarded to the focused client. If this closure returns FilterResult::Forward, the input will not be sent to the client. If it returns FilterResult::Intercept a value can be passed to be returned by the whole function. This mechanism can be used to implement compositor-level key bindings for example.

The module keysyms exposes definitions of all possible keysyms to be compared against. This includes non-character keysyms, such as XF86 special keys.

Source

pub fn input_intercept<T, F>( &self, data: &mut D, keycode: Keycode, state: KeyState, filter: F, ) -> (T, bool)
where F: FnOnce(&mut D, &ModifiersState, KeysymHandle<'_>) -> T,

Update the state of the keyboard without forwarding the event to the focused client

Useful in conjunction with KeyboardHandle::input_forward in case you want to asynchronously decide if the event should be forwarded to the focused client.

Prefer using KeyboardHandle::input if this decision can be done synchronously in the filter closure.

Source

pub fn input_forward( &self, data: &mut D, keycode: Keycode, state: KeyState, serial: Serial, time: u32, mods_changed: bool, )

Forward a key event to the focused client

Useful in conjunction with KeyboardHandle::input_intercept.

Source

pub fn set_focus( &self, data: &mut D, focus: Option<<D as SeatHandler>::KeyboardFocus>, serial: Serial, )

Set the current focus of this keyboard

If the new focus is different from the previous one, any previous focus will be sent a wl_keyboard::Event::Leave event, and if the new focus is not None, a wl_keyboard::Event::Enter event will be sent.

Source

pub fn pressed_keys(&self) -> HashSet<Keycode>

Return the key codes of the currently pressed keys.

Source

pub fn with_pressed_keysyms<F, R>(&self, f: F) -> R
where F: FnOnce(Vec<KeysymHandle<'_>>) -> R, R: 'static,

Iterate over the keysyms of the currently pressed keys.

Source

pub fn modifier_state(&self) -> ModifiersState

Get the current modifiers state

Source

pub fn led_state(&self) -> LedState

Get the current led state

Source

pub fn is_focused(&self) -> bool

Check if keyboard has focus

Source

pub fn change_repeat_info(&self, rate: i32, delay: i32)

Change the repeat info configured for this keyboard

Source

pub fn last_enter(&self) -> Option<Serial>

Available on crate feature wayland_frontend only.

Access the Serial of the last keyboard_enter event, if that focus is still active.

In other words this will return None again, once a keyboard_leave occurred.

Source§

impl<D> KeyboardHandle<D>

Source

pub fn current_focus(&self) -> Option<<D as SeatHandler>::KeyboardFocus>

Retrieve the current keyboard focus

Source§

impl<D> KeyboardHandle<D>
where D: SeatHandler + 'static, <D as SeatHandler>::KeyboardFocus: WaylandFocus,

Source

pub fn client_of_object_has_focus(&self, id: &ObjectId) -> bool

Available on crate feature wayland_frontend only.

Check if client of given resource currently has keyboard focus

Source§

impl<D: SeatHandler + 'static> KeyboardHandle<D>

Source

pub fn from_resource(seat: &WlKeyboard) -> Option<Self>

Available on crate feature wayland_frontend only.

Attempt to retrieve a KeyboardHandle from an existing resource

May return None for a valid WlKeyboard that was created without the keyboard capability.

Trait Implementations§

Source§

impl<D: SeatHandler> Clone for KeyboardHandle<D>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D: SeatHandler> Debug for KeyboardHandle<D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<D: SeatHandler> PartialEq for KeyboardHandle<D>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<D> Freeze for KeyboardHandle<D>

§

impl<D> !RefUnwindSafe for KeyboardHandle<D>

§

impl<D> Send for KeyboardHandle<D>

§

impl<D> Sync for KeyboardHandle<D>

§

impl<D> Unpin for KeyboardHandle<D>

§

impl<D> !UnwindSafe for KeyboardHandle<D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more