| 1 | use std::path::PathBuf; |
| 2 | |
| 3 | pub mod animations; |
| 4 | pub mod bar; |
| 5 | pub mod client; |
| 6 | pub mod config; |
| 7 | pub mod errors; |
| 8 | pub mod keyboard; |
| 9 | pub mod layout; |
| 10 | pub mod monitor; |
| 11 | pub mod overlay; |
| 12 | pub mod signal; |
| 13 | pub mod size_hints; |
| 14 | pub mod tab_bar; |
| 15 | pub mod window_manager; |
| 16 | |
| 17 | pub mod prelude { |
| 18 | pub use crate::ColorScheme; |
| 19 | pub use crate::LayoutSymbolOverride; |
| 20 | pub use crate::WindowRule; |
| 21 | pub use crate::bar::{BlockCommand, BlockConfig}; |
| 22 | pub use crate::keyboard::{Arg, KeyAction, handlers::KeyBinding, keysyms}; |
| 23 | pub use x11rb::protocol::xproto::KeyButMask; |
| 24 | } |
| 25 | |
| 26 | #[derive(Debug, Clone)] |
| 27 | pub struct LayoutSymbolOverride { |
| 28 | pub name: String, |
| 29 | pub symbol: String, |
| 30 | } |
| 31 | |
| 32 | #[derive(Debug, Clone)] |
| 33 | pub struct WindowRule { |
| 34 | pub class: Option<String>, |
| 35 | pub instance: Option<String>, |
| 36 | pub title: Option<String>, |
| 37 | pub tags: Option<u32>, |
| 38 | pub is_floating: Option<bool>, |
| 39 | pub monitor: Option<usize>, |
| 40 | } |
| 41 | |
| 42 | impl WindowRule { |
| 43 | pub fn matches(&self, class: &str, instance: &str, title: &str) -> bool { |
| 44 | let class_matches = self |
| 45 | .class |
| 46 | .as_ref() |
| 47 | .is_none_or(|c| class.contains(c.as_str())); |
| 48 | let instance_matches = self |
| 49 | .instance |
| 50 | .as_ref() |
| 51 | .is_none_or(|i| instance.contains(i.as_str())); |
| 52 | let title_matches = self |
| 53 | .title |
| 54 | .as_ref() |
| 55 | .is_none_or(|t| title.contains(t.as_str())); |
| 56 | class_matches && instance_matches && title_matches |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | #[derive(Debug, Clone)] |
| 61 | pub struct Config { |
| 62 | // Meta |
| 63 | pub path: Option<PathBuf>, |
| 64 | |
| 65 | // Appearance |
| 66 | pub border_width: u32, |
| 67 | pub border_focused: u32, |
| 68 | pub border_unfocused: u32, |
| 69 | pub font: String, |
| 70 | |
| 71 | // Gaps |
| 72 | pub gaps_enabled: bool, |
| 73 | pub smartgaps_enabled: bool, |
| 74 | pub gap_inner_horizontal: u32, |
| 75 | pub gap_inner_vertical: u32, |
| 76 | pub gap_outer_horizontal: u32, |
| 77 | pub gap_outer_vertical: u32, |
| 78 | |
| 79 | // Basics |
| 80 | pub terminal: String, |
| 81 | pub modkey: x11rb::protocol::xproto::KeyButMask, |
| 82 | |
| 83 | // Tags |
| 84 | pub tags: Vec<String>, |
| 85 | |
| 86 | // Layout symbol overrides |
| 87 | pub layout_symbols: Vec<LayoutSymbolOverride>, |
| 88 | |
| 89 | // Keybindings |
| 90 | pub keybindings: Vec<crate::keyboard::handlers::Key>, |
| 91 | pub tag_back_and_forth: bool, |
| 92 | |
| 93 | // Window rules |
| 94 | pub window_rules: Vec<WindowRule>, |
| 95 | |
| 96 | // Status bar |
| 97 | pub status_blocks: Vec<crate::bar::BlockConfig>, |
| 98 | |
| 99 | // Bar color schemes |
| 100 | pub scheme_normal: ColorScheme, |
| 101 | pub scheme_occupied: ColorScheme, |
| 102 | pub scheme_selected: ColorScheme, |
| 103 | pub scheme_urgent: ColorScheme, |
| 104 | |
| 105 | pub autostart: Vec<String>, |
| 106 | pub auto_tile: bool, |
| 107 | } |
| 108 | |
| 109 | #[derive(Debug, Clone, Copy)] |
| 110 | pub struct ColorScheme { |
| 111 | pub foreground: u32, |
| 112 | pub background: u32, |
| 113 | pub underline: u32, |
| 114 | } |
| 115 | |
| 116 | impl Default for Config { |
| 117 | fn default() -> Self { |
| 118 | use crate::keyboard::handlers::KeyBinding; |
| 119 | use crate::keyboard::{Arg, KeyAction, keysyms}; |
| 120 | use x11rb::protocol::xproto::KeyButMask; |
| 121 | |
| 122 | const MODKEY: KeyButMask = KeyButMask::MOD4; |
| 123 | const SHIFT: KeyButMask = KeyButMask::SHIFT; |
| 124 | |
| 125 | const TERMINAL: &str = "st"; |
| 126 | |
| 127 | Self { |
| 128 | path: None, |
| 129 | border_width: 2, |
| 130 | border_focused: 0x6dade3, |
| 131 | border_unfocused: 0xbbbbbb, |
| 132 | font: "monospace:size=10".to_string(), |
| 133 | gaps_enabled: false, |
| 134 | smartgaps_enabled: true, |
| 135 | gap_inner_horizontal: 0, |
| 136 | gap_inner_vertical: 0, |
| 137 | gap_outer_horizontal: 0, |
| 138 | gap_outer_vertical: 0, |
| 139 | terminal: TERMINAL.to_string(), |
| 140 | modkey: MODKEY, |
| 141 | tags: vec!["1", "2", "3", "4", "5", "6", "7", "8", "9"] |
| 142 | .into_iter() |
| 143 | .map(String::from) |
| 144 | .collect(), |
| 145 | layout_symbols: vec![], |
| 146 | keybindings: vec![ |
| 147 | KeyBinding::single_key( |
| 148 | vec![MODKEY], |
| 149 | keysyms::XK_RETURN, |
| 150 | KeyAction::Spawn, |
| 151 | Arg::Str(TERMINAL.to_string()), |
| 152 | ), |
| 153 | KeyBinding::single_key( |
| 154 | vec![MODKEY], |
| 155 | keysyms::XK_D, |
| 156 | KeyAction::Spawn, |
| 157 | Arg::Array(vec![ |
| 158 | "sh".to_string(), |
| 159 | "-c".to_string(), |
| 160 | "dmenu_run -l 10".to_string(), |
| 161 | ]), |
| 162 | ), |
| 163 | KeyBinding::single_key( |
| 164 | vec![MODKEY], |
| 165 | keysyms::XK_Q, |
| 166 | KeyAction::KillClient, |
| 167 | Arg::None, |
| 168 | ), |
| 169 | KeyBinding::single_key( |
| 170 | vec![MODKEY], |
| 171 | keysyms::XK_N, |
| 172 | KeyAction::CycleLayout, |
| 173 | Arg::None, |
| 174 | ), |
| 175 | KeyBinding::single_key( |
| 176 | vec![MODKEY, SHIFT], |
| 177 | keysyms::XK_F, |
| 178 | KeyAction::ToggleFullScreen, |
| 179 | Arg::None, |
| 180 | ), |
| 181 | KeyBinding::single_key( |
| 182 | vec![MODKEY], |
| 183 | keysyms::XK_A, |
| 184 | KeyAction::ToggleGaps, |
| 185 | Arg::None, |
| 186 | ), |
| 187 | KeyBinding::single_key( |
| 188 | vec![MODKEY, SHIFT], |
| 189 | keysyms::XK_Q, |
| 190 | KeyAction::Quit, |
| 191 | Arg::None, |
| 192 | ), |
| 193 | KeyBinding::single_key( |
| 194 | vec![MODKEY, SHIFT], |
| 195 | keysyms::XK_R, |
| 196 | KeyAction::Restart, |
| 197 | Arg::None, |
| 198 | ), |
| 199 | KeyBinding::single_key( |
| 200 | vec![MODKEY], |
| 201 | keysyms::XK_F, |
| 202 | KeyAction::ToggleFloating, |
| 203 | Arg::None, |
| 204 | ), |
| 205 | KeyBinding::single_key( |
| 206 | vec![MODKEY], |
| 207 | keysyms::XK_J, |
| 208 | KeyAction::FocusStack, |
| 209 | Arg::Int(-1), |
| 210 | ), |
| 211 | KeyBinding::single_key( |
| 212 | vec![MODKEY], |
| 213 | keysyms::XK_K, |
| 214 | KeyAction::FocusStack, |
| 215 | Arg::Int(1), |
| 216 | ), |
| 217 | KeyBinding::single_key( |
| 218 | vec![MODKEY], |
| 219 | keysyms::XK_1, |
| 220 | KeyAction::ViewTag, |
| 221 | Arg::Int(0), |
| 222 | ), |
| 223 | KeyBinding::single_key( |
| 224 | vec![MODKEY], |
| 225 | keysyms::XK_2, |
| 226 | KeyAction::ViewTag, |
| 227 | Arg::Int(1), |
| 228 | ), |
| 229 | KeyBinding::single_key( |
| 230 | vec![MODKEY], |
| 231 | keysyms::XK_3, |
| 232 | KeyAction::ViewTag, |
| 233 | Arg::Int(2), |
| 234 | ), |
| 235 | KeyBinding::single_key( |
| 236 | vec![MODKEY], |
| 237 | keysyms::XK_4, |
| 238 | KeyAction::ViewTag, |
| 239 | Arg::Int(3), |
| 240 | ), |
| 241 | KeyBinding::single_key( |
| 242 | vec![MODKEY], |
| 243 | keysyms::XK_5, |
| 244 | KeyAction::ViewTag, |
| 245 | Arg::Int(4), |
| 246 | ), |
| 247 | KeyBinding::single_key( |
| 248 | vec![MODKEY], |
| 249 | keysyms::XK_6, |
| 250 | KeyAction::ViewTag, |
| 251 | Arg::Int(5), |
| 252 | ), |
| 253 | KeyBinding::single_key( |
| 254 | vec![MODKEY], |
| 255 | keysyms::XK_7, |
| 256 | KeyAction::ViewTag, |
| 257 | Arg::Int(6), |
| 258 | ), |
| 259 | KeyBinding::single_key( |
| 260 | vec![MODKEY], |
| 261 | keysyms::XK_8, |
| 262 | KeyAction::ViewTag, |
| 263 | Arg::Int(7), |
| 264 | ), |
| 265 | KeyBinding::single_key( |
| 266 | vec![MODKEY], |
| 267 | keysyms::XK_9, |
| 268 | KeyAction::ViewTag, |
| 269 | Arg::Int(8), |
| 270 | ), |
| 271 | KeyBinding::single_key( |
| 272 | vec![MODKEY, SHIFT], |
| 273 | keysyms::XK_1, |
| 274 | KeyAction::MoveToTag, |
| 275 | Arg::Int(0), |
| 276 | ), |
| 277 | KeyBinding::single_key( |
| 278 | vec![MODKEY, SHIFT], |
| 279 | keysyms::XK_2, |
| 280 | KeyAction::MoveToTag, |
| 281 | Arg::Int(1), |
| 282 | ), |
| 283 | KeyBinding::single_key( |
| 284 | vec![MODKEY, SHIFT], |
| 285 | keysyms::XK_3, |
| 286 | KeyAction::MoveToTag, |
| 287 | Arg::Int(2), |
| 288 | ), |
| 289 | KeyBinding::single_key( |
| 290 | vec![MODKEY, SHIFT], |
| 291 | keysyms::XK_4, |
| 292 | KeyAction::MoveToTag, |
| 293 | Arg::Int(3), |
| 294 | ), |
| 295 | KeyBinding::single_key( |
| 296 | vec![MODKEY, SHIFT], |
| 297 | keysyms::XK_5, |
| 298 | KeyAction::MoveToTag, |
| 299 | Arg::Int(4), |
| 300 | ), |
| 301 | KeyBinding::single_key( |
| 302 | vec![MODKEY, SHIFT], |
| 303 | keysyms::XK_6, |
| 304 | KeyAction::MoveToTag, |
| 305 | Arg::Int(5), |
| 306 | ), |
| 307 | KeyBinding::single_key( |
| 308 | vec![MODKEY, SHIFT], |
| 309 | keysyms::XK_7, |
| 310 | KeyAction::MoveToTag, |
| 311 | Arg::Int(6), |
| 312 | ), |
| 313 | KeyBinding::single_key( |
| 314 | vec![MODKEY, SHIFT], |
| 315 | keysyms::XK_8, |
| 316 | KeyAction::MoveToTag, |
| 317 | Arg::Int(7), |
| 318 | ), |
| 319 | KeyBinding::single_key( |
| 320 | vec![MODKEY, SHIFT], |
| 321 | keysyms::XK_9, |
| 322 | KeyAction::MoveToTag, |
| 323 | Arg::Int(8), |
| 324 | ), |
| 325 | ], |
| 326 | tag_back_and_forth: false, |
| 327 | window_rules: vec![], |
| 328 | status_blocks: vec![crate::bar::BlockConfig { |
| 329 | format: "{}".to_string(), |
| 330 | command: crate::bar::BlockCommand::DateTime("%a, %b %d - %-I:%M %P".to_string()), |
| 331 | interval_secs: 1, |
| 332 | color: 0x0db9d7, |
| 333 | underline: true, |
| 334 | }], |
| 335 | scheme_normal: ColorScheme { |
| 336 | foreground: 0xbbbbbb, |
| 337 | background: 0x1a1b26, |
| 338 | underline: 0x444444, |
| 339 | }, |
| 340 | scheme_occupied: ColorScheme { |
| 341 | foreground: 0x0db9d7, |
| 342 | background: 0x1a1b26, |
| 343 | underline: 0x0db9d7, |
| 344 | }, |
| 345 | scheme_selected: ColorScheme { |
| 346 | foreground: 0x0db9d7, |
| 347 | background: 0x1a1b26, |
| 348 | underline: 0xad8ee6, |
| 349 | }, |
| 350 | scheme_urgent: ColorScheme { |
| 351 | foreground: 0xff5555, |
| 352 | background: 0x1a1b26, |
| 353 | underline: 0xff5555, |
| 354 | }, |
| 355 | autostart: vec![], |
| 356 | auto_tile: false, |
| 357 | } |
| 358 | } |
| 359 | } |