tony / oxwm

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