refactor(wayland/seat): boolean for keypress instead of u32

This commit is contained in:
Nova
2023-09-08 20:23:40 -04:00
parent 558fb1aa4e
commit f78da4b198
2 changed files with 13 additions and 12 deletions

View File

@@ -69,16 +69,11 @@ impl KeyboardInfo {
keys: FxHashSet::default(), keys: FxHashSet::default(),
} }
} }
pub fn process(&mut self, key: u32, state: u32, keyboard: &WlKeyboard) -> Result<usize> { pub fn process(&mut self, key: u32, pressed: bool, keyboard: &WlKeyboard) -> Result<usize> {
let wl_key_state = match state { let xkb_key_state = if pressed {
0 => KeyState::Released, xkb::KeyDirection::Down
1 => KeyState::Pressed, } else {
_ => color_eyre::eyre::bail!("Invalid key state!"), xkb::KeyDirection::Up
};
let xkb_key_state = match state {
0 => xkb::KeyDirection::Up,
1 => xkb::KeyDirection::Down,
_ => color_eyre::eyre::bail!("Invalid key state!"),
}; };
let state_components = self.state.update_key(key + 8, xkb_key_state); let state_components = self.state.update_key(key + 8, xkb_key_state);
if state_components != 0 { if state_components != 0 {
@@ -91,6 +86,12 @@ impl KeyboardInfo {
0, 0,
); );
} }
let wl_key_state = if pressed {
KeyState::Pressed
} else {
KeyState::Released
};
keyboard.key(SERIAL_COUNTER.inc(), 0, key, wl_key_state); keyboard.key(SERIAL_COUNTER.inc(), 0, key, wl_key_state);
match wl_key_state { match wl_key_state {
KeyState::Pressed => { KeyState::Pressed => {
@@ -121,7 +122,7 @@ pub enum PointerEvent {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum KeyboardEvent { pub enum KeyboardEvent {
Keymap, Keymap,
Key { key: u32, state: u32 }, Key { key: u32, state: bool },
} }
const POINTER_EVENT_TIMEOUT: Duration = Duration::from_millis(50); const POINTER_EVENT_TIMEOUT: Duration = Duration::from_millis(50);

View File

@@ -1016,7 +1016,7 @@ impl Backend for XDGBackend {
&surface, &surface,
KeyboardEvent::Key { KeyboardEvent::Key {
key: key.abs() as u32, key: key.abs() as u32,
state: if key < 0 { 1 } else { 0 }, state: key < 0,
}, },
); );
} }