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