tony / oxwm

Branch: 5767bfd
Switch branches/tags
master
tonybtw Added window rules such as opening a window in a specific tag, or opening it floating. 3a6a48d 2025-12-01
336 lines · 10.7 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 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, SHIFT],
179 keysyms::XK_K,
180 KeyAction::ExchangeClient,
181 Arg::Int(0), // UP
182 ),
183 KeyBinding::single_key(
184 vec![MODKEY, SHIFT],
185 keysyms::XK_J,
186 KeyAction::ExchangeClient,
187 Arg::Int(1), // DOWN
188 ),
189 KeyBinding::single_key(
190 vec![MODKEY, SHIFT],
191 keysyms::XK_H,
192 KeyAction::ExchangeClient,
193 Arg::Int(2), // LEFT
194 ),
195 KeyBinding::single_key(
196 vec![MODKEY, SHIFT],
197 keysyms::XK_L,
198 KeyAction::ExchangeClient,
199 Arg::Int(3), // RIGHT
200 ),
201 KeyBinding::single_key(
202 vec![MODKEY],
203 keysyms::XK_1,
204 KeyAction::ViewTag,
205 Arg::Int(0),
206 ),
207 KeyBinding::single_key(
208 vec![MODKEY],
209 keysyms::XK_2,
210 KeyAction::ViewTag,
211 Arg::Int(1),
212 ),
213 KeyBinding::single_key(
214 vec![MODKEY],
215 keysyms::XK_3,
216 KeyAction::ViewTag,
217 Arg::Int(2),
218 ),
219 KeyBinding::single_key(
220 vec![MODKEY],
221 keysyms::XK_4,
222 KeyAction::ViewTag,
223 Arg::Int(3),
224 ),
225 KeyBinding::single_key(
226 vec![MODKEY],
227 keysyms::XK_5,
228 KeyAction::ViewTag,
229 Arg::Int(4),
230 ),
231 KeyBinding::single_key(
232 vec![MODKEY],
233 keysyms::XK_6,
234 KeyAction::ViewTag,
235 Arg::Int(5),
236 ),
237 KeyBinding::single_key(
238 vec![MODKEY],
239 keysyms::XK_7,
240 KeyAction::ViewTag,
241 Arg::Int(6),
242 ),
243 KeyBinding::single_key(
244 vec![MODKEY],
245 keysyms::XK_8,
246 KeyAction::ViewTag,
247 Arg::Int(7),
248 ),
249 KeyBinding::single_key(
250 vec![MODKEY],
251 keysyms::XK_9,
252 KeyAction::ViewTag,
253 Arg::Int(8),
254 ),
255 KeyBinding::single_key(
256 vec![MODKEY, SHIFT],
257 keysyms::XK_1,
258 KeyAction::MoveToTag,
259 Arg::Int(0),
260 ),
261 KeyBinding::single_key(
262 vec![MODKEY, SHIFT],
263 keysyms::XK_2,
264 KeyAction::MoveToTag,
265 Arg::Int(1),
266 ),
267 KeyBinding::single_key(
268 vec![MODKEY, SHIFT],
269 keysyms::XK_3,
270 KeyAction::MoveToTag,
271 Arg::Int(2),
272 ),
273 KeyBinding::single_key(
274 vec![MODKEY, SHIFT],
275 keysyms::XK_4,
276 KeyAction::MoveToTag,
277 Arg::Int(3),
278 ),
279 KeyBinding::single_key(
280 vec![MODKEY, SHIFT],
281 keysyms::XK_5,
282 KeyAction::MoveToTag,
283 Arg::Int(4),
284 ),
285 KeyBinding::single_key(
286 vec![MODKEY, SHIFT],
287 keysyms::XK_6,
288 KeyAction::MoveToTag,
289 Arg::Int(5),
290 ),
291 KeyBinding::single_key(
292 vec![MODKEY, SHIFT],
293 keysyms::XK_7,
294 KeyAction::MoveToTag,
295 Arg::Int(6),
296 ),
297 KeyBinding::single_key(
298 vec![MODKEY, SHIFT],
299 keysyms::XK_8,
300 KeyAction::MoveToTag,
301 Arg::Int(7),
302 ),
303 KeyBinding::single_key(
304 vec![MODKEY, SHIFT],
305 keysyms::XK_9,
306 KeyAction::MoveToTag,
307 Arg::Int(8),
308 ),
309 ],
310 window_rules: vec![],
311 status_blocks: vec![crate::bar::BlockConfig {
312 format: "{}".to_string(),
313 command: crate::bar::BlockCommand::DateTime("%a, %b %d - %-I:%M %P".to_string()),
314 interval_secs: 1,
315 color: 0x0db9d7,
316 underline: true,
317 }],
318 scheme_normal: ColorScheme {
319 foreground: 0xbbbbbb,
320 background: 0x1a1b26,
321 underline: 0x444444,
322 },
323 scheme_occupied: ColorScheme {
324 foreground: 0x0db9d7,
325 background: 0x1a1b26,
326 underline: 0x0db9d7,
327 },
328 scheme_selected: ColorScheme {
329 foreground: 0x0db9d7,
330 background: 0x1a1b26,
331 underline: 0xad8ee6,
332 },
333 autostart: vec![],
334 }
335 }
336 }