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 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 T)

🔬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 + Send + Sync>

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