modifiers: Support Control and Alt

Control and Alt are special in that they aren't expected to switch levels, and so don't need to change what characters are output.

Use in layouts by adding `modifier: Control` or `modifier: Alt` in place of `text: "foo"`.

The latching of the modifier will force the keyboard to emit raw key presses and prevent it from outputting text.
This commit is contained in:
Dorota Czaplejewicz
2020-01-15 15:23:06 +00:00
parent c28f07fcfd
commit 92e9d994fe
13 changed files with 193 additions and 34 deletions

View File

@ -1,6 +1,6 @@
/*! Managing the events belonging to virtual-keyboard interface. */
use ::keyboard::{ KeyCode, PressType };
use ::keyboard::{ KeyCode, Modifiers, PressType };
use ::layout::c::LevelKeyboard;
use ::submission::Timestamp;
@ -26,6 +26,11 @@ pub mod c {
virtual_keyboard: ZwpVirtualKeyboardV1,
keyboard: LevelKeyboard,
);
pub fn eek_virtual_keyboard_set_modifiers(
virtual_keyboard: ZwpVirtualKeyboardV1,
modifiers: u32,
);
}
}
@ -33,7 +38,7 @@ pub mod c {
pub struct VirtualKeyboard(pub c::ZwpVirtualKeyboardV1);
impl VirtualKeyboard {
// TODO: split out keyboard state management
// TODO: error out if keymap not set
pub fn switch(
&self,
keycodes: &Vec<KeyCode>,
@ -68,12 +73,16 @@ impl VirtualKeyboard {
}
}
pub fn set_modifiers_state(&self, modifiers: Modifiers) {
let modifiers = modifiers.bits() as u32;
unsafe {
c::eek_virtual_keyboard_set_modifiers(self.0, modifiers);
}
}
pub fn update_keymap(&self, keyboard: LevelKeyboard) {
unsafe {
c::eek_virtual_keyboard_update_keymap(
self.0,
keyboard,
);
c::eek_virtual_keyboard_update_keymap(self.0, keyboard);
}
}
}