tony / oxwm

Branch: f8f0c96
Switch branches/tags
master
tonybtw Added hide_vacant_tags() feature from dwm patch into oxwm as optional flag. f8f0c96 2025-12-29
360 lines · 10.9 KB Raw Blame History
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 .is_none_or(|c| class.contains(c.as_str()));
47 let instance_matches = self
48 .instance
49 .as_ref()
50 .is_none_or(|i| instance.contains(i.as_str()));
51 let title_matches = self
52 .title
53 .as_ref()
54 .is_none_or(|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 pub scheme_urgent: ColorScheme,
103
104 pub autostart: Vec<String>,
105 pub auto_tile: bool,
106 pub hide_vacant_tags: 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 hide_vacant_tags: false,
358 }
359 }
360 }