tony / oxwm

Fixed hot reload? Browse files
tonybtw committed 2025-10-06 parent 605d25b commit a40c8d0023f24cb369b789709690224bc6acf71b
Showing 2 changed files with 61 additions and 27 deletions. UnifiedSplit
+0 −2 src/keyboard/handlers.rs
@@ -57,8 +57,6 @@ pub fn setup_keybinds(connection: &impl Connection, root: Window) -> Result<()>
57 57 for keybinding in KEYBINDINGS {
58 58 let modifier_mask = modifiers_to_mask(keybinding.modifiers);
59 59
60 - println!("Grabbing key {} with mod {}", keybinding.key, modifier_mask);
61 -
62 60 connection.grab_key(
63 61 false,
64 62 root,
+61 −25 src/window_manager.rs
@@ -86,8 +86,8 @@ impl WindowManager {
86 86 .get_property(false, root, net_current_desktop, AtomEnum::CARDINAL, 0, 1)?
87 87 .reply()
88 88 {
89 + // I don't undestand this but I got it from dwm->persist_tags patch and it worked.
89 90 Ok(prop) if prop.value.len() >= 4 => {
90 - // I don't undestand this but I got it from dwm->persist_tags patch and it worked.
91 91 let desktop = u32::from_ne_bytes([
92 92 prop.value[0],
93 93 prop.value[1],
@@ -95,29 +95,32 @@ impl WindowManager {
95 95 prop.value[3],
96 96 ]);
97 97 if desktop < TAG_COUNT as u32 {
98 - println!("Restored selected tag: {}", desktop);
99 - return Ok(tag_mask(desktop as usize));
98 + let mask = tag_mask(desktop as usize);
99 + return Ok(mask);
100 100 }
101 101 }
102 - _ => {}
102 + Ok(_) => {}
103 + Err(e) => {
104 + eprintln!("No _NET_CURRENT_DESKTOP property ({})", e);
105 + }
103 106 }
104 -
105 - println!("No saved tag, defaulting to tag 0");
106 107 Ok(tag_mask(0))
107 108 }
108 109
109 110 fn scan_existing_windows(&mut self) -> Result<()> {
110 111 let tree = self.connection.query_tree(self.root)?.reply()?;
111 -
112 - println!("=== Scanning existing windows ===");
113 - println!("Total children: {}", tree.children.len());
114 -
115 112 let net_client_info = self
116 113 .connection
117 114 .intern_atom(false, b"_NET_CLIENT_INFO")?
118 115 .reply()?
119 116 .atom;
120 117
118 + let wm_state_atom = self
119 + .connection
120 + .intern_atom(false, b"WM_STATE")?
121 + .reply()?
122 + .atom;
123 +
121 124 for &window in &tree.children {
122 125 if window == self.bar.window() {
123 126 continue;
@@ -134,13 +137,25 @@ impl WindowManager {
134 137
135 138 if attrs.map_state == MapState::VIEWABLE {
136 139 let tag = self.get_saved_tag(window, net_client_info)?;
137 - println!("Managing VIEWABLE window: {} with tag {:b}", window, tag);
138 140 self.windows.push(window);
139 141 self.window_tags.insert(window, tag);
140 142 continue;
141 143 }
142 144
143 145 if attrs.map_state == MapState::UNMAPPED {
146 + let has_wm_state = match self
147 + .connection
148 + .get_property(false, window, wm_state_atom, AtomEnum::ANY, 0, 2)?
149 + .reply()
150 + {
151 + Ok(prop) => !prop.value.is_empty(),
152 + Err(_) => false,
153 + };
154 +
155 + if !has_wm_state {
156 + continue;
157 + }
158 +
144 159 let has_wm_class = match self
145 160 .connection
146 161 .get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024)?
@@ -152,15 +167,12 @@ impl WindowManager {
152 167
153 168 if has_wm_class {
154 169 let tag = self.get_saved_tag(window, net_client_info)?;
155 - println!("Managing UNMAPPED window: {} with tag {:b}", window, tag);
156 170 self.windows.push(window);
157 171 self.window_tags.insert(window, tag);
158 172 }
159 173 }
160 174 }
161 175
162 - println!("Total managed windows: {}", self.windows.len());
163 -
164 176 if let Some(&first) = self.windows.first() {
165 177 self.set_focus(Some(first))?;
166 178 }
@@ -182,13 +194,17 @@ impl WindowManager {
182 194 prop.value[2],
183 195 prop.value[3],
184 196 ]);
185 - println!(" Restored tag from _NET_CLIENT_INFO: {:b}", tags);
186 - return Ok(tags);
197 +
198 + if tags != 0 && tags < (1 << crate::config::TAG_COUNT) {
199 + return Ok(tags);
200 + }
201 + }
202 + Ok(_) => {}
203 + Err(e) => {
204 + eprintln!("No _NET_CLIENT_INFO property ({})", e);
187 205 }
188 - _ => {}
189 206 }
190 207
191 - println!(" No saved tag, using current: {:b}", self.selected_tags);
192 208 Ok(self.selected_tags)
193 209 }
194 210
@@ -199,8 +215,7 @@ impl WindowManager {
199 215 .reply()?
200 216 .atom;
201 217
202 - let data = [tag, 0u32];
203 - let bytes: Vec<u8> = data.iter().flat_map(|&v| v.to_ne_bytes()).collect();
218 + let bytes = tag.to_ne_bytes().to_vec();
204 219
205 220 self.connection.change_property(
206 221 PropMode::REPLACE,
@@ -208,6 +223,30 @@ impl WindowManager {
208 223 net_client_info,
209 224 AtomEnum::CARDINAL,
210 225 32,
226 + 1,
227 + &bytes,
228 + )?;
229 +
230 + self.connection.flush()?;
231 + Ok(())
232 + }
233 +
234 + fn set_wm_state(&self, window: Window, state: u32) -> Result<()> {
235 + let wm_state_atom = self
236 + .connection
237 + .intern_atom(false, b"WM_STATE")?
238 + .reply()?
239 + .atom;
240 +
241 + let data = [state, 0u32]; // No icon window
242 + let bytes: Vec<u8> = data.iter().flat_map(|&v| v.to_ne_bytes()).collect();
243 +
244 + self.connection.change_property(
245 + PropMode::REPLACE,
246 + window,
247 + wm_state_atom,
248 + wm_state_atom,
249 + 32,
211 250 2,
212 251 &bytes,
213 252 )?;
@@ -468,6 +507,8 @@ impl WindowManager {
468 507 self.windows.push(event.window);
469 508 self.window_tags.insert(event.window, self.selected_tags);
470 509
510 + self.set_wm_state(event.window, 1)?;
511 +
471 512 let _ = self.save_client_tag(event.window, self.selected_tags);
472 513
473 514 self.apply_layout()?;
@@ -493,12 +534,7 @@ impl WindowManager {
493 534 }
494 535 }
495 536 Event::KeyPress(event) => {
496 - println!("━━━ KeyPress Event ━━━");
497 - println!("Key code: {}", event.detail);
498 -
499 537 let (action, arg) = keyboard::handle_key_press(event)?;
500 - println!(" -> Matched action: {:?}", action);
501 -
502 538 match action {
503 539 KeyAction::Quit => return Ok(Some(false)),
504 540 KeyAction::Restart => return Ok(Some(true)),