blob: b7488dd90b0f2cc350297a5faa75e774e0e6f109 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
//! 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>,
{
if let Err(e) = Command::new(cmd).args(args).spawn() {
eprintln!("error spawning {cmd}: {e:#?}");
};
}
/// 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);
}
/// Toggle floating status for the currently focused window
pub fn toggle_floating(wm: &mut WM<'_>) {
if let Some(pos) = wm.clients.focused_pos() {
wm.clients.toggle_floating(&wm.conn, pos);
}
}
|