tony / oxwm

Branch: 5e36ac3
Switch branches/tags
master
emzywastaken Fix config reload to reuse original config file path 54ea2dc 2025-12-14
350 lines · 10.5 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 .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
91 // Window rules
92 pub window_rules: Vec<WindowRule>,
93
94 // Status bar
95 pub status_blocks: Vec<crate::bar::BlockConfig>,
96
97 // Bar color schemes
98 pub scheme_normal: ColorScheme,
99 pub scheme_occupied: ColorScheme,
100 pub scheme_selected: ColorScheme,
101
102 pub autostart: Vec<String>,
103 pub auto_tile: bool,
104 }
105
106 #[derive(Debug, Clone, Copy)]
107 pub struct ColorScheme {
108 pub foreground: u32,
109 pub background: u32,
110 pub underline: u32,
111 }
112
113 impl Default for Config {
114 fn default() -> Self {
115 use crate::keyboard::handlers::KeyBinding;
116 use crate::keyboard::{Arg, KeyAction, keysyms};
117 use x11rb::protocol::xproto::KeyButMask;
118
119 const MODKEY: KeyButMask = KeyButMask::MOD4;
120 const SHIFT: KeyButMask = KeyButMask::SHIFT;
121
122 const TERMINAL: &str = "st";
123
124 Self {
125 path: None,
126 border_width: 2,
127 border_focused: 0x6dade3,
128 border_unfocused: 0xbbbbbb,
129 font: "monospace:size=10".to_string(),
130 gaps_enabled: false,
131 smartgaps_enabled: true,
132 gap_inner_horizontal: 0,
133 gap_inner_vertical: 0,
134 gap_outer_horizontal: 0,
135 gap_outer_vertical: 0,
136 terminal: TERMINAL.to_string(),
137 modkey: MODKEY,
138 tags: vec!["1", "2", "3", "4", "5", "6", "7", "8", "9"]
139 .into_iter()
140 .map(String::from)
141 .collect(),
142 layout_symbols: vec![],
143 keybindings: vec![
144 KeyBinding::single_key(
145 vec![MODKEY],
146 keysyms::XK_RETURN,
147 KeyAction::Spawn,
148 Arg::Str(TERMINAL.to_string()),
149 ),
150 KeyBinding::single_key(
151 vec![MODKEY],
152 keysyms::XK_D,
153 KeyAction::Spawn,
154 Arg::Array(vec![
155 "sh".to_string(),
156 "-c".to_string(),
157 "dmenu_run -l 10".to_string(),
158 ]),
159 ),
160 KeyBinding::single_key(
161 vec![MODKEY],
162 keysyms::XK_Q,
163 KeyAction::KillClient,
164 Arg::None,
165 ),
166 KeyBinding::single_key(
167 vec![MODKEY],
168 keysyms::XK_N,
169 KeyAction::CycleLayout,
170 Arg::None,
171 ),
172 KeyBinding::single_key(
173 vec![MODKEY, SHIFT],
174 keysyms::XK_F,
175 KeyAction::ToggleFullScreen,
176 Arg::None,
177 ),
178 KeyBinding::single_key(
179 vec![MODKEY],
180 keysyms::XK_A,
181 KeyAction::ToggleGaps,
182 Arg::None,
183 ),
184 KeyBinding::single_key(
185 vec![MODKEY, SHIFT],
186 keysyms::XK_Q,
187 KeyAction::Quit,
188 Arg::None,
189 ),
190 KeyBinding::single_key(
191 vec![MODKEY, SHIFT],
192 keysyms::XK_R,
193 KeyAction::Restart,
194 Arg::None,
195 ),
196 KeyBinding::single_key(
197 vec![MODKEY],
198 keysyms::XK_F,
199 KeyAction::ToggleFloating,
200 Arg::None,
201 ),
202 KeyBinding::single_key(
203 vec![MODKEY],
204 keysyms::XK_J,
205 KeyAction::FocusStack,
206 Arg::Int(-1),
207 ),
208 KeyBinding::single_key(
209 vec![MODKEY],
210 keysyms::XK_K,
211 KeyAction::FocusStack,
212 Arg::Int(1),
213 ),
214 KeyBinding::single_key(
215 vec![MODKEY],
216 keysyms::XK_1,
217 KeyAction::ViewTag,
218 Arg::Int(0),
219 ),
220 KeyBinding::single_key(
221 vec![MODKEY],
222 keysyms::XK_2,
223 KeyAction::ViewTag,
224 Arg::Int(1),
225 ),
226 KeyBinding::single_key(
227 vec![MODKEY],
228 keysyms::XK_3,
229 KeyAction::ViewTag,
230 Arg::Int(2),
231 ),
232 KeyBinding::single_key(
233 vec![MODKEY],
234 keysyms::XK_4,
235 KeyAction::ViewTag,
236 Arg::Int(3),
237 ),
238 KeyBinding::single_key(
239 vec![MODKEY],
240 keysyms::XK_5,
241 KeyAction::ViewTag,
242 Arg::Int(4),
243 ),
244 KeyBinding::single_key(
245 vec![MODKEY],
246 keysyms::XK_6,
247 KeyAction::ViewTag,
248 Arg::Int(5),
249 ),
250 KeyBinding::single_key(
251 vec![MODKEY],
252 keysyms::XK_7,
253 KeyAction::ViewTag,
254 Arg::Int(6),
255 ),
256 KeyBinding::single_key(
257 vec![MODKEY],
258 keysyms::XK_8,
259 KeyAction::ViewTag,
260 Arg::Int(7),
261 ),
262 KeyBinding::single_key(
263 vec![MODKEY],
264 keysyms::XK_9,
265 KeyAction::ViewTag,
266 Arg::Int(8),
267 ),
268 KeyBinding::single_key(
269 vec![MODKEY, SHIFT],
270 keysyms::XK_1,
271 KeyAction::MoveToTag,
272 Arg::Int(0),
273 ),
274 KeyBinding::single_key(
275 vec![MODKEY, SHIFT],
276 keysyms::XK_2,
277 KeyAction::MoveToTag,
278 Arg::Int(1),
279 ),
280 KeyBinding::single_key(
281 vec![MODKEY, SHIFT],
282 keysyms::XK_3,
283 KeyAction::MoveToTag,
284 Arg::Int(2),
285 ),
286 KeyBinding::single_key(
287 vec![MODKEY, SHIFT],
288 keysyms::XK_4,
289 KeyAction::MoveToTag,
290 Arg::Int(3),
291 ),
292 KeyBinding::single_key(
293 vec![MODKEY, SHIFT],
294 keysyms::XK_5,
295 KeyAction::MoveToTag,
296 Arg::Int(4),
297 ),
298 KeyBinding::single_key(
299 vec![MODKEY, SHIFT],
300 keysyms::XK_6,
301 KeyAction::MoveToTag,
302 Arg::Int(5),
303 ),
304 KeyBinding::single_key(
305 vec![MODKEY, SHIFT],
306 keysyms::XK_7,
307 KeyAction::MoveToTag,
308 Arg::Int(6),
309 ),
310 KeyBinding::single_key(
311 vec![MODKEY, SHIFT],
312 keysyms::XK_8,
313 KeyAction::MoveToTag,
314 Arg::Int(7),
315 ),
316 KeyBinding::single_key(
317 vec![MODKEY, SHIFT],
318 keysyms::XK_9,
319 KeyAction::MoveToTag,
320 Arg::Int(8),
321 ),
322 ],
323 window_rules: vec![],
324 status_blocks: vec![crate::bar::BlockConfig {
325 format: "{}".to_string(),
326 command: crate::bar::BlockCommand::DateTime("%a, %b %d - %-I:%M %P".to_string()),
327 interval_secs: 1,
328 color: 0x0db9d7,
329 underline: true,
330 }],
331 scheme_normal: ColorScheme {
332 foreground: 0xbbbbbb,
333 background: 0x1a1b26,
334 underline: 0x444444,
335 },
336 scheme_occupied: ColorScheme {
337 foreground: 0x0db9d7,
338 background: 0x1a1b26,
339 underline: 0x0db9d7,
340 },
341 scheme_selected: ColorScheme {
342 foreground: 0x0db9d7,
343 background: 0x1a1b26,
344 underline: 0xad8ee6,
345 },
346 autostart: vec![],
347 auto_tile: false,
348 }
349 }
350 }