tony / oxwm

added config.rs and removed print debugs. Browse files
tonybtw committed 2025-10-03 parent 2eed31f commit 1a0575c4c4b77d9dabb9f740b868995e56c5b3d5
Showing 4 changed files with 68 additions and 119 deletions. UnifiedSplit
+56 −0 src/config.rs new file mode 100644
@@ -0,0 +1,56 @@
1 +use crate::keyboard::handlers::Key;
2 +use crate::keyboard::{Arg, KeyAction, keycodes};
3 +use x11rb::protocol::xproto::KeyButMask;
4 +
5 +// ========================================
6 +// APPEARANCE
7 +// ========================================
8 +pub const BORDER_WIDTH: u32 = 2;
9 +pub const BORDER_FOCUSED: u32 = 0xff0000;
10 +pub const BORDER_UNFOCUSED: u32 = 0x888888;
11 +
12 +// ========================================
13 +// DEFAULTS
14 +// ========================================
15 +pub const TERMINAL: &str = "alacritty";
16 +pub const MODKEY: KeyButMask = KeyButMask::MOD1;
17 +
18 +// ========================================
19 +// TAGS
20 +// ========================================
21 +pub const TAG_COUNT: usize = 9;
22 +
23 +// ========================================
24 +// KEYBINDINGS
25 +// ========================================
26 +#[rustfmt::skip]
27 +pub const KEYBINDINGS: &[Key] = &[
28 + Key::new(&[MODKEY], keycodes::RETURN, KeyAction::Spawn, Arg::Str(TERMINAL)),
29 +
30 + Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None),
31 + Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None),
32 + Key::new(&[MODKEY], keycodes::J, KeyAction::FocusStack, Arg::Int(-1)),
33 + Key::new(&[MODKEY], keycodes::K, KeyAction::FocusStack, Arg::Int(1)),
34 +
35 + Key::new(&[MODKEY], keycodes::KEY_1, KeyAction::ViewTag, Arg::Int(0)),
36 + Key::new(&[MODKEY], keycodes::KEY_2, KeyAction::ViewTag, Arg::Int(1)),
37 + Key::new(&[MODKEY], keycodes::KEY_3, KeyAction::ViewTag, Arg::Int(2)),
38 + Key::new(&[MODKEY], keycodes::KEY_4, KeyAction::ViewTag, Arg::Int(3)),
39 + Key::new(&[MODKEY], keycodes::KEY_5, KeyAction::ViewTag, Arg::Int(4)),
40 + Key::new(&[MODKEY], keycodes::KEY_6, KeyAction::ViewTag, Arg::Int(5)),
41 + Key::new(&[MODKEY], keycodes::KEY_7, KeyAction::ViewTag, Arg::Int(6)),
42 + Key::new(&[MODKEY], keycodes::KEY_8, KeyAction::ViewTag, Arg::Int(7)),
43 + Key::new(&[MODKEY], keycodes::KEY_9, KeyAction::ViewTag, Arg::Int(8)),
44 +
45 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_1, KeyAction::MoveToTag, Arg::Int(0)),
46 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_2, KeyAction::MoveToTag, Arg::Int(1)),
47 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_3, KeyAction::MoveToTag, Arg::Int(2)),
48 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_4, KeyAction::MoveToTag, Arg::Int(3)),
49 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_5, KeyAction::MoveToTag, Arg::Int(4)),
50 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_6, KeyAction::MoveToTag, Arg::Int(5)),
51 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_7, KeyAction::MoveToTag, Arg::Int(6)),
52 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_8, KeyAction::MoveToTag, Arg::Int(7)),
53 + Key::new(&[MODKEY, SHIFT], keycodes::KEY_9, KeyAction::MoveToTag, Arg::Int(8)),
54 +];
55 +
56 +const SHIFT: KeyButMask = KeyButMask::SHIFT;
+1 −77 src/keyboard/handlers.rs
@@ -1,4 +1,4 @@
1 -use crate::keyboard::keycodes;
1 +use crate::config::KEYBINDINGS;
2 2 use anyhow::Result;
3 3 use x11rb::connection::Connection;
4 4 use x11rb::protocol::xproto::*;
@@ -44,80 +44,6 @@ impl Key {
44 44 }
45 45 }
46 46
47 -const KEYBINDINGS: &[Key] = &[
48 - Key::new(
49 - &[KeyButMask::MOD1],
50 - keycodes::RETURN,
51 - KeyAction::Spawn,
52 - Arg::Str("alacritty"),
53 - ),
54 - Key::new(
55 - &[KeyButMask::MOD1],
56 - keycodes::Q,
57 - KeyAction::KillClient,
58 - Arg::None,
59 - ),
60 - Key::new(
61 - &[KeyButMask::MOD1, KeyButMask::SHIFT],
62 - keycodes::Q,
63 - KeyAction::Quit,
64 - Arg::None,
65 - ),
66 - Key::new(
67 - &[KeyButMask::MOD1],
68 - keycodes::K,
69 - KeyAction::FocusStack,
70 - Arg::Int(1),
71 - ),
72 - Key::new(
73 - &[KeyButMask::MOD1],
74 - keycodes::J,
75 - KeyAction::FocusStack,
76 - Arg::Int(-1),
77 - ),
78 - // NEW: Tag bindings (Mod+1 through Mod+9)
79 - Key::new(
80 - &[KeyButMask::MOD1],
81 - keycodes::KEY_1,
82 - KeyAction::ViewTag,
83 - Arg::Int(0),
84 - ),
85 - Key::new(
86 - &[KeyButMask::MOD1],
87 - keycodes::KEY_2,
88 - KeyAction::ViewTag,
89 - Arg::Int(1),
90 - ),
91 - Key::new(
92 - &[KeyButMask::MOD1],
93 - keycodes::KEY_3,
94 - KeyAction::ViewTag,
95 - Arg::Int(2),
96 - ),
97 - // ... add KEY_4 through KEY_9
98 -
99 - // NEW: Move window to tag (Mod+Shift+1 through Mod+Shift+9)
100 - Key::new(
101 - &[KeyButMask::MOD1, KeyButMask::SHIFT],
102 - keycodes::KEY_1,
103 - KeyAction::MoveToTag,
104 - Arg::Int(0),
105 - ),
106 - Key::new(
107 - &[KeyButMask::MOD1, KeyButMask::SHIFT],
108 - keycodes::KEY_2,
109 - KeyAction::MoveToTag,
110 - Arg::Int(1),
111 - ),
112 - Key::new(
113 - &[KeyButMask::MOD1, KeyButMask::SHIFT],
114 - keycodes::KEY_3,
115 - KeyAction::MoveToTag,
116 - Arg::Int(2),
117 - ),
118 - // ... etc
119 -];
120 -
121 47 fn modifiers_to_mask(modifiers: &[KeyButMask]) -> u16 {
122 48 modifiers
123 49 .iter()
@@ -141,8 +67,6 @@ pub fn setup_keybinds(connection: &impl Connection, root: Window) -> Result<()>
141 67 }
142 68
143 69 pub fn handle_key_press(event: KeyPressEvent) -> Result<(KeyAction, &'static Arg)> {
144 - println!("KeyPress: detail={}, state={:?}", event.detail, event.state);
145 -
146 70 for keybinding in KEYBINDINGS {
147 71 let modifier_mask = modifiers_to_mask(keybinding.modifiers);
148 72
+1 −0 src/main.rs
@@ -1,4 +1,5 @@
1 1 use anyhow::Result;
2 +mod config;
2 3 mod keyboard;
3 4 mod layout;
4 5 mod window_manager;
+10 −42 src/window_manager.rs
@@ -1,7 +1,7 @@
1 +use crate::config::{BORDER_FOCUSED, BORDER_UNFOCUSED, BORDER_WIDTH, TAG_COUNT};
1 2 use crate::keyboard::{self, Arg, KeyAction};
2 3 use crate::layout::Layout;
3 4 use crate::layout::tiling::TilingLayout;
4 -
5 5 use anyhow::Result;
6 6
7 7 use x11rb::connection::Connection;
@@ -9,11 +9,7 @@ use x11rb::protocol::Event;
9 9 use x11rb::protocol::xproto::*;
10 10 use x11rb::rust_connection::RustConnection;
11 11
12 -// TODO: move this to its own file? (tag.rs?)
13 12 pub type TagMask = u32;
14 -
15 -pub const TAG_COUNT: usize = 9;
16 -
17 13 pub fn tag_mask(tag: usize) -> TagMask {
18 14 1 << tag
19 15 }
@@ -68,7 +64,6 @@ impl WindowManager {
68 64
69 65 loop {
70 66 let event = self.connection.wait_for_event()?;
71 - println!("event: {:?}", event);
72 67 self.handle_event(event)?;
73 68 }
74 69 }
@@ -77,35 +72,27 @@ impl WindowManager {
77 72 match action {
78 73 KeyAction::Spawn => {
79 74 if let Arg::Str(command) = arg {
80 - println!("Spawning: {}", command);
81 75 std::process::Command::new(command).spawn()?;
82 76 }
83 77 }
84 78 KeyAction::KillClient => {
85 - println!("Closing focused window");
86 79 if let Some(focused) = self.focused_window {
87 80 match self.connection.kill_client(focused) {
88 81 Ok(_) => {
89 82 self.connection.flush()?;
90 - println!("Killed window {}", focused);
91 83 }
92 84 Err(e) => {
93 - println!("Failed to kill window {}: {}", focused, e);
85 + eprintln!("Failed to kill window {}: {}", focused, e);
94 86 }
95 87 }
96 88 }
97 89 }
98 90 KeyAction::FocusStack => {
99 91 if let Arg::Int(direction) = arg {
100 - println!("FocusStack called with direction: {}", direction);
101 - println!("Windows: {:?}", self.windows);
102 - println!("Current focused: {:?}", self.focused_window);
103 92 self.cycle_focus(*direction)?;
104 - println!("New focused: {:?}", self.focused_window);
105 93 }
106 94 }
107 95 KeyAction::Quit => {
108 - println!("Quitting window manager");
109 96 std::process::exit(0);
110 97 }
111 98 KeyAction::ViewTag => {
@@ -159,8 +146,6 @@ impl WindowManager {
159 146 }
160 147
161 148 self.selected_tags = tag_mask(tag_index);
162 - println!("Viewing tag {}", tag_index + 1);
163 -
164 149 self.update_window_visibility()?;
165 150 self.apply_layout()?;
166 151
@@ -178,9 +163,6 @@ impl WindowManager {
178 163 if let Some(focused) = self.focused_window {
179 164 let mask = tag_mask(tag_index);
180 165 self.window_tags.insert(focused, mask);
181 -
182 - println!("Moved window {} to tag {}", focused, tag_index + 1);
183 -
184 166 self.update_window_visibility()?;
185 167 self.apply_layout()?;
186 168 }
@@ -215,7 +197,6 @@ impl WindowManager {
215 197 }
216 198
217 199 pub fn set_focus(&mut self, window: Option<Window>) -> Result<()> {
218 - println!("set_focus called with: {:?}", window);
219 200 self.focused_window = window;
220 201
221 202 if let Some(win) = window {
@@ -229,14 +210,11 @@ impl WindowManager {
229 210 }
230 211
231 212 fn update_focus_visuals(&self) -> Result<()> {
232 - println!("Updating focus visuals for {} windows", self.windows.len());
233 213 for &window in &self.windows {
234 214 let (border_color, border_width) = if self.focused_window == Some(window) {
235 - println!("Window {} is FOCUSED (red border)", window);
236 - (0xff0000, 2)
215 + (BORDER_FOCUSED, BORDER_WIDTH)
237 216 } else {
238 - println!("Window {} is unfocused (gray border)", window);
239 - (0x888888, 2)
217 + (BORDER_UNFOCUSED, BORDER_WIDTH)
240 218 };
241 219
242 220 self.connection.configure_window(
@@ -263,27 +241,19 @@ impl WindowManager {
263 241 self.set_focus(Some(event.window))?;
264 242 }
265 243 Event::UnmapNotify(event) => {
266 - if self.windows.contains(&event.window) {
267 - if self.is_window_visible(event.window) {
268 - println!("Visible window {} unmapped, removing", event.window);
269 - self.remove_window(event.window)?;
270 - } else {
271 - println!(
272 - "Hidden window {} unmapped (expected), ignoring",
273 - event.window
274 - );
275 - }
244 + if self.windows.contains(&event.window) && self.is_window_visible(event.window) {
245 + self.remove_window(event.window)?;
276 246 }
277 247 }
278 248 // Event::UnmapNotify(event) => {
279 249 // if self.windows.contains(&event.window) {
280 - // println!("Window {} unmapped, removing from layout", event.window);
281 - // self.remove_window(event.window)?;
250 + // if self.is_window_visible(event.window) {
251 + // self.remove_window(event.window)?;
252 + // }
282 253 // }
283 254 // }
284 255 Event::DestroyNotify(event) => {
285 256 if self.windows.contains(&event.window) {
286 - println!("Window {} destroyed, removing from layout", event.window);
287 257 self.remove_window(event.window)?;
288 258 }
289 259 }
@@ -299,7 +269,7 @@ impl WindowManager {
299 269 fn apply_layout(&self) -> Result<()> {
300 270 let screen_width = self.screen.width_in_pixels as u32;
301 271 let screen_height = self.screen.height_in_pixels as u32;
302 - let border_width = 2u32;
272 + let border_width = BORDER_WIDTH;
303 273
304 274 let visible = self.visible_windows();
305 275 let geometries = self.layout.arrange(&visible, screen_width, screen_height);
@@ -327,8 +297,6 @@ impl WindowManager {
327 297 self.window_tags.remove(&window);
328 298
329 299 if self.windows.len() < initial_count {
330 - println!("Removed window {} from management", window);
331 -
332 300 if self.focused_window == Some(window) {
333 301 let new_focus = if self.windows.is_empty() {
334 302 None