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