tony / oxwm

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