tony / oxwm

Fixed reloadsig, and actually persist using NET_CLIENT_INFO Browse files
tonybtw committed 2025-10-05 parent 99cb352 commit 2188e271b935668a9692a07bb3c43930860ce0e6
Showing 1 changed file with 66 additions and 26 deletions. UnifiedSplit
+66 −26 src/window_manager.rs
@@ -71,39 +71,32 @@ impl WindowManager {
71 71
72 println!("=== Scanning existing windows ==="); 72 println!("=== Scanning existing windows ===");
73 println!("Total children: {}", tree.children.len()); 73 println!("Total children: {}", tree.children.len());
74 - println!("Current selected_tags: {:b}", self.selected_tags); 74 +
75 + let net_client_info = self
76 + .connection
77 + .intern_atom(false, b"_NET_CLIENT_INFO")?
78 + .reply()?
79 + .atom;
75 80
76 for &window in &tree.children { 81 for &window in &tree.children {
77 if window == self.bar.window() { 82 if window == self.bar.window() {
78 - println!("Skipping bar window: {}", window);
79 continue; 83 continue;
80 } 84 }
81 85
82 let attrs = match self.connection.get_window_attributes(window)?.reply() { 86 let attrs = match self.connection.get_window_attributes(window)?.reply() {
83 Ok(attrs) => attrs, 87 Ok(attrs) => attrs,
84 - Err(_) => { 88 + Err(_) => continue,
85 - println!("Failed to get attributes for window: {}", window);
86 - continue;
87 - }
88 }; 89 };
89 90
90 - println!(
91 - "Window {}: override_redirect={}, map_state={:?}",
92 - window, attrs.override_redirect, attrs.map_state
93 - );
94 -
95 if attrs.override_redirect { 91 if attrs.override_redirect {
96 - println!(" -> Skipped (override_redirect)");
97 continue; 92 continue;
98 } 93 }
99 94
100 if attrs.map_state == MapState::VIEWABLE { 95 if attrs.map_state == MapState::VIEWABLE {
101 - println!( 96 + let tag = self.get_saved_tag(window, net_client_info)?;
102 - " -> Managing VIEWABLE window, tagging with {:b}", 97 + println!("Managing VIEWABLE window: {} with tag {:b}", window, tag);
103 - self.selected_tags
104 - );
105 self.windows.push(window); 98 self.windows.push(window);
106 - self.window_tags.insert(window, self.selected_tags); 99 + self.window_tags.insert(window, tag);
107 continue; 100 continue;
108 } 101 }
109 102
@@ -118,17 +111,11 @@ impl WindowManager {
118 }; 111 };
119 112
120 if has_wm_class { 113 if has_wm_class {
121 - println!( 114 + let tag = self.get_saved_tag(window, net_client_info)?;
122 - " -> Managing UNMAPPED window (has WM_CLASS), tagging with {:b}", 115 + println!("Managing UNMAPPED window: {} with tag {:b}", window, tag);
123 - self.selected_tags
124 - );
125 self.windows.push(window); 116 self.windows.push(window);
126 - self.window_tags.insert(window, self.selected_tags); 117 + self.window_tags.insert(window, tag);
127 - } else {
128 - println!(" -> Skipped UNMAPPED (no WM_CLASS)");
129 } 118 }
130 - } else {
131 - println!(" -> Skipped (map_state={:?})", attrs.map_state);
132 } 119 }
133 } 120 }
134 121
@@ -142,6 +129,53 @@ impl WindowManager {
142 Ok(()) 129 Ok(())
143 } 130 }
144 131
132 + fn get_saved_tag(&self, window: Window, net_client_info: Atom) -> Result<TagMask> {
133 + match self
134 + .connection
135 + .get_property(false, window, net_client_info, AtomEnum::CARDINAL, 0, 2)?
136 + .reply()
137 + {
138 + Ok(prop) if prop.value.len() >= 4 => {
139 + let tags = u32::from_ne_bytes([
140 + prop.value[0],
141 + prop.value[1],
142 + prop.value[2],
143 + prop.value[3],
144 + ]);
145 + println!(" Restored tag from _NET_CLIENT_INFO: {:b}", tags);
146 + return Ok(tags);
147 + }
148 + _ => {}
149 + }
150 +
151 + println!(" No saved tag, using current: {:b}", self.selected_tags);
152 + Ok(self.selected_tags)
153 + }
154 +
155 + fn save_client_tag(&self, window: Window, tag: TagMask) -> Result<()> {
156 + let net_client_info = self
157 + .connection
158 + .intern_atom(false, b"_NET_CLIENT_INFO")?
159 + .reply()?
160 + .atom;
161 +
162 + let data = [tag, 0u32];
163 + let bytes: Vec<u8> = data.iter().flat_map(|&v| v.to_ne_bytes()).collect();
164 +
165 + self.connection.change_property(
166 + PropMode::REPLACE,
167 + window,
168 + net_client_info,
169 + AtomEnum::CARDINAL,
170 + 32,
171 + 2,
172 + &bytes,
173 + )?;
174 +
175 + self.connection.flush()?;
176 + Ok(())
177 + }
178 +
145 pub fn run(&mut self) -> Result<bool> { 179 pub fn run(&mut self) -> Result<bool> {
146 println!("oxwm started on display {}", self.screen_number); 180 println!("oxwm started on display {}", self.screen_number);
147 181
@@ -279,6 +313,9 @@ impl WindowManager {
279 if let Some(focused) = self.focused_window { 313 if let Some(focused) = self.focused_window {
280 let mask = tag_mask(tag_index); 314 let mask = tag_mask(tag_index);
281 self.window_tags.insert(focused, mask); 315 self.window_tags.insert(focused, mask);
316 +
317 + let _ = self.save_client_tag(focused, mask);
318 +
282 self.update_window_visibility()?; 319 self.update_window_visibility()?;
283 self.apply_layout()?; 320 self.apply_layout()?;
284 self.update_bar()?; 321 self.update_bar()?;
@@ -354,6 +391,9 @@ impl WindowManager {
354 self.connection.map_window(event.window)?; 391 self.connection.map_window(event.window)?;
355 self.windows.push(event.window); 392 self.windows.push(event.window);
356 self.window_tags.insert(event.window, self.selected_tags); 393 self.window_tags.insert(event.window, self.selected_tags);
394 +
395 + let _ = self.save_client_tag(event.window, self.selected_tags);
396 +
357 self.apply_layout()?; 397 self.apply_layout()?;
358 self.update_bar()?; 398 self.update_bar()?;
359 self.set_focus(Some(event.window))?; 399 self.set_focus(Some(event.window))?;