diff options
author | tcmal <me@aria.rip> | 2024-06-26 21:52:09 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-06-26 21:52:09 +0100 |
commit | adcf670ba60c4489b14d4b9dd03a0f7799cf8fb7 (patch) | |
tree | f99dbd4a0d3504278ed16f7cd5753f2a5402675c /src/helpers.rs | |
parent | 6785d154460921cc3b774376a676a226402d8270 (diff) |
start adding some more keybinds
Diffstat (limited to 'src/helpers.rs')
-rw-r--r-- | src/helpers.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/helpers.rs b/src/helpers.rs new file mode 100644 index 0000000..ffd11d7 --- /dev/null +++ b/src/helpers.rs @@ -0,0 +1,46 @@ +//! Helpers for writing configuration + +use crate::WM; +use std::{ffi::OsStr, process::Command}; + +/// Syntax sugar for creating [`Keybind`]s. This is helpful for writing [`crate::config::KEYBINDS`] +/// +/// ```rust +/// /// Control + Shift + t prints "It Works!" +/// bind!(ModMask::CONTROL | ModMask::SHIFT + t -> &|_| {println!("It Works!")}) +/// ``` +#[macro_export] +macro_rules! bind { + ($mod:expr , $key:ident -> $action:expr) => { + Keybind { + modifiers: $mod, + key: Keysym::$key, + action: $action, + } + }; +} + +/// Execute the given command with arguments, disowning the process. +pub fn spawn<I, S>(cmd: &str, args: I) +where + I: IntoIterator<Item = S>, + S: AsRef<OsStr>, +{ + let c = match Command::new(cmd).args(args).spawn() { + Ok(c) => c, + Err(e) => { + eprintln!("error spawning {cmd}: {e:#?}"); + return; + } + }; +} + +/// Move focus to the next window on the stack +pub fn focus_next(wm: &mut WM<'_>) { + wm.clients.change_focus(&wm.conn, true); +} + +/// Move focus to the next window on the stack +pub fn focus_prev(wm: &mut WM<'_>) { + wm.clients.change_focus(&wm.conn, false); +} |