//! Helpers for writing configuration use crate::{ clients::{Tag, TagFocus}, 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) => { $crate::keys::Keybind { modifiers: $mod, key: ::xkeysym::Keysym::$key, action: $action, } }; } /// Syntax sugar for creating [`ButtonBind`]s. See also: [`self::bind`]. #[macro_export] macro_rules! bind_btn { ($mod:expr , $key:ident -> $action:expr) => { $crate::buttons::ButtonBind { modifiers: $mod, button: ::xcb::x::ButtonIndex::$key, action: $action, } }; } /// Execute the given command with arguments, disowning the process. pub fn spawn(cmd: &str, args: I) where I: IntoIterator, S: AsRef, { 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); } } /// Toggle fullscreen status for the currently focused window pub fn toggle_fullscreen(wm: &mut WM<'_>) { if let Some(pos) = wm.clients.focused_pos() { wm.clients.toggle_fullscreen(&wm.conn, pos); } } /// Set the focused tag for the currently selected monitor pub fn set_tag_focus(wm: &mut WM<'_>, tag_focus: TagFocus) { wm.clients .set_mon_tag_focus(&wm.conn, wm.clients.focused_mon_idx(), tag_focus); } /// Set the tag for the currently selected client pub fn set_tag(wm: &mut WM<'_>, tag: Tag) { if let Some(pos) = wm.clients.focused_pos() { wm.clients.set_client_tag(&wm.conn, pos, tag); } } /// Move the currently focused window with the mouse pub fn mouse_move(wm: &mut WM<'_>) { if let Err(e) = wm.mouse_move() { println!("error when moving with mouse: {e:?}"); } } /// Resize the currently focused window with the mouse pub fn mouse_resize(wm: &mut WM<'_>) { if let Err(e) = wm.mouse_resize() { println!("error when resizing with mouse: {e:?}"); } }