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>
impl<D: SeatHandler + 'static> KeyboardHandle<D>
Sourcepub fn set_keymap_from_string(
&self,
data: &mut D,
keymap: String,
) -> Result<(), Error>
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.
Sourcepub fn set_xkb_config(
&self,
data: &mut D,
xkb_config: XkbConfig<'_>,
) -> Result<(), Error>
pub fn set_xkb_config( &self, data: &mut D, xkb_config: XkbConfig<'_>, ) -> Result<(), Error>
Change the XkbConfig
used by the keyboard.
Sourcepub fn with_xkb_state<F, T>(&self, data: &mut D, callback: F) -> Twhere
F: FnMut(XkbContext<'_>) -> T,
pub fn with_xkb_state<F, T>(&self, data: &mut D, callback: F) -> Twhere
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.
Sourcepub fn set_grab<G: KeyboardGrab<D> + 'static>(
&self,
data: &mut D,
grab: G,
serial: Serial,
)
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.
Sourcepub fn unset_grab(&self, data: &mut D)
pub fn unset_grab(&self, data: &mut D)
Remove any current grab on this keyboard, resetting it to the default behavior
Sourcepub fn has_grab(&self, serial: Serial) -> bool
pub fn has_grab(&self, serial: Serial) -> bool
Check if this keyboard is currently grabbed with this serial
Sourcepub fn is_grabbed(&self) -> bool
pub fn is_grabbed(&self) -> bool
Check if this keyboard is currently being grabbed
Sourcepub fn grab_start_data(&self) -> Option<GrabStartData<D>>
pub fn grab_start_data(&self) -> Option<GrabStartData<D>>
Returns the start data for the grab, if any.
Sourcepub fn with_grab<T>(
&self,
f: impl FnOnce(Serial, &dyn KeyboardGrab<D>) -> T,
) -> Option<T>
pub fn with_grab<T>( &self, f: impl FnOnce(Serial, &dyn KeyboardGrab<D>) -> T, ) -> Option<T>
Calls f
with the active grab, if any.
Sourcepub fn input<T, F>(
&self,
data: &mut D,
keycode: Keycode,
state: KeyState,
serial: Serial,
time: u32,
filter: F,
) -> Option<T>
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.
Sourcepub fn input_intercept<T, F>(
&self,
data: &mut D,
keycode: Keycode,
state: KeyState,
filter: F,
) -> (T, bool)
pub fn input_intercept<T, F>( &self, data: &mut D, keycode: Keycode, state: KeyState, filter: F, ) -> (T, bool)
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.
Sourcepub fn input_forward(
&self,
data: &mut D,
keycode: Keycode,
state: KeyState,
serial: Serial,
time: u32,
mods_changed: bool,
)
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
.
Sourcepub fn set_focus(
&self,
data: &mut D,
focus: Option<<D as SeatHandler>::KeyboardFocus>,
serial: Serial,
)
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.
Sourcepub fn pressed_keys(&self) -> HashSet<Keycode>
pub fn pressed_keys(&self) -> HashSet<Keycode>
Return the key codes of the currently pressed keys.
Sourcepub fn with_pressed_keysyms<F, R>(&self, f: F) -> R
pub fn with_pressed_keysyms<F, R>(&self, f: F) -> R
Iterate over the keysyms of the currently pressed keys.
Sourcepub fn modifier_state(&self) -> ModifiersState
pub fn modifier_state(&self) -> ModifiersState
Get the current modifiers state
Sourcepub fn is_focused(&self) -> bool
pub fn is_focused(&self) -> bool
Check if keyboard has focus
Sourcepub fn change_repeat_info(&self, rate: i32, delay: i32)
pub fn change_repeat_info(&self, rate: i32, delay: i32)
Change the repeat info configured for this keyboard
Sourcepub fn last_enter(&self) -> Option<Serial>
Available on crate feature wayland_frontend
only.
pub fn last_enter(&self) -> Option<Serial>
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>
impl<D> KeyboardHandle<D>
Sourcepub fn current_focus(&self) -> Option<<D as SeatHandler>::KeyboardFocus>
pub fn current_focus(&self) -> Option<<D as SeatHandler>::KeyboardFocus>
Retrieve the current keyboard focus
Source§impl<D> KeyboardHandle<D>
impl<D> KeyboardHandle<D>
Sourcepub fn client_of_object_has_focus(&self, id: &ObjectId) -> bool
Available on crate feature wayland_frontend
only.
pub fn client_of_object_has_focus(&self, id: &ObjectId) -> bool
wayland_frontend
only.Check if client of given resource currently has keyboard focus
Source§impl<D: SeatHandler + 'static> KeyboardHandle<D>
impl<D: SeatHandler + 'static> KeyboardHandle<D>
Sourcepub fn from_resource(seat: &WlKeyboard) -> Option<Self>
Available on crate feature wayland_frontend
only.
pub fn from_resource(seat: &WlKeyboard) -> Option<Self>
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>
impl<D: SeatHandler> Clone for KeyboardHandle<D>
Source§impl<D: SeatHandler> Debug for KeyboardHandle<D>
impl<D: SeatHandler> Debug for KeyboardHandle<D>
Source§impl<D: SeatHandler> PartialEq for KeyboardHandle<D>
impl<D: SeatHandler> PartialEq for KeyboardHandle<D>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.