diff options
author | tcmal <me@aria.rip> | 2024-06-05 21:19:28 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-06-05 21:19:28 +0100 |
commit | 2cb4bc8a39d27c82f7db4d7d270f2101b18b5e23 (patch) | |
tree | 4c5eaa32703bc11cf3224ab8a315877539382a5f | |
parent | c6a963cd43cadff083bfdf4454cdef2d8ddd2070 (diff) |
actually run keybinds
-rw-r--r-- | src/keys.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/keys.rs b/src/keys.rs index 7e94944..79f1984 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -1,3 +1,5 @@ +use std::process::Command; + use crate::{error::*, WM}; use xcb::{ x::{ @@ -16,6 +18,7 @@ impl WM<'_> { }; KEYBINDS.dispatch( + self, sym, ModMask::from_bits_truncate(e.state().bits()) .difference(self.keyboard_state.numlock_mask() | ModMask::LOCK), @@ -167,11 +170,19 @@ impl KeyboardInfo { } /// A bound key -#[derive(Debug)] pub struct Keybind { modifiers: ModMask, key: Keysym, - // TODO: add action + action: &'static dyn Fn(&mut WM<'_>) -> (), +} + +impl std::fmt::Debug for Keybind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Keybind") + .field("modifiers", &self.modifiers) + .field("key", &self.key) + .finish() + } } /// A set of keybinds. Currently, there is only one instance of this defined statically: [`self::KEYBINDS`]. @@ -180,7 +191,13 @@ pub struct Keybinds(&'static [Keybind]); /// The keybinds to use. const KEYBINDS: Keybinds = Keybinds(&[Keybind { modifiers: ModMask::CONTROL, - key: Keysym::a, + key: Keysym::t, + action: &|_| { + // TODO: disown this process, probably using another way to spawn commands + if let Err(e) = Command::new("xterm").spawn() { + dbg!(e); + } + }, }]); impl Keybinds { @@ -190,12 +207,12 @@ impl Keybinds { } /// Attempt to run the action for the matching keybind, if it exists. - pub fn dispatch(&self, key: Keysym, modifiers: ModMask) { + pub fn dispatch(&self, wm: &mut WM<'_>, key: Keysym, modifiers: ModMask) { if let Some(bind) = self .binds() .find(|b| b.key == key && modifiers.contains(b.modifiers)) { - dbg!(bind); // TODO: run the bind + (bind.action)(wm); } } } |