diff --git a/src/wayland/seat.rs b/src/wayland/seat.rs index 9a01b47..edc21dd 100644 --- a/src/wayland/seat.rs +++ b/src/wayland/seat.rs @@ -69,16 +69,11 @@ impl KeyboardInfo { keys: FxHashSet::default(), } } - pub fn process(&mut self, key: u32, state: u32, keyboard: &WlKeyboard) -> Result { - let wl_key_state = match state { - 0 => KeyState::Released, - 1 => KeyState::Pressed, - _ => color_eyre::eyre::bail!("Invalid key state!"), - }; - let xkb_key_state = match state { - 0 => xkb::KeyDirection::Up, - 1 => xkb::KeyDirection::Down, - _ => color_eyre::eyre::bail!("Invalid key state!"), + pub fn process(&mut self, key: u32, pressed: bool, keyboard: &WlKeyboard) -> Result { + let xkb_key_state = if pressed { + xkb::KeyDirection::Down + } else { + xkb::KeyDirection::Up }; let state_components = self.state.update_key(key + 8, xkb_key_state); if state_components != 0 { @@ -91,6 +86,12 @@ impl KeyboardInfo { 0, ); } + + let wl_key_state = if pressed { + KeyState::Pressed + } else { + KeyState::Released + }; keyboard.key(SERIAL_COUNTER.inc(), 0, key, wl_key_state); match wl_key_state { KeyState::Pressed => { @@ -121,7 +122,7 @@ pub enum PointerEvent { #[derive(Debug, Clone)] pub enum KeyboardEvent { Keymap, - Key { key: u32, state: u32 }, + Key { key: u32, state: bool }, } const POINTER_EVENT_TIMEOUT: Duration = Duration::from_millis(50); diff --git a/src/wayland/xdg_shell.rs b/src/wayland/xdg_shell.rs index e15c9a1..e719a5e 100644 --- a/src/wayland/xdg_shell.rs +++ b/src/wayland/xdg_shell.rs @@ -1016,7 +1016,7 @@ impl Backend for XDGBackend { &surface, KeyboardEvent::Key { key: key.abs() as u32, - state: if key < 0 { 1 } else { 0 }, + state: key < 0, }, ); }