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