//! Helpers for writing configuration use crate::{ clients::{Tag, TagFocus}, WM, }; use std::{ffi::OsStr, process::Command}; /// Syntax sugar for creating [`Keybind`](`crate::keys::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`](`crate::buttons::ButtonBind`)s. See also: [`crate::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. 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); } } /// Send the kill signal to the currently focused client pub fn kill_client(wm: &mut WM<'_>) { if let Some(pos) = wm.clients.focused_pos() { wm.clients.kill_client(&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:?}"); } }