tony / oxwm

fixed tag bug indicator Browse files
tonybtw committed 2025-10-05 parent 2188e27 commit dea5239d3c5939ade9f036ce1be2d543f447841e
Showing 1 changed file with 61 additions and 1 deletions. UnifiedSplit
+61 −1 src/window_manager.rs
@@ -48,6 +48,8 @@ impl WindowManager {
48 48
49 49 let bar = Bar::new(&connection, &screen, screen_number)?;
50 50
51 + let selected_tags = Self::get_saved_selected_tags(&connection, root)?;
52 +
51 53 let mut window_manger = Self {
52 54 connection,
53 55 screen_number,
@@ -57,15 +59,46 @@ impl WindowManager {
57 59 focused_window: None,
58 60 layout: Box::new(TilingLayout),
59 61 window_tags: std::collections::HashMap::new(),
60 - selected_tags: tag_mask(0),
62 + selected_tags,
61 63 bar,
62 64 };
63 65
64 66 window_manger.scan_existing_windows()?;
67 + window_manger.update_bar()?;
65 68
66 69 Ok(window_manger)
67 70 }
68 71
72 + fn get_saved_selected_tags(connection: &RustConnection, root: Window) -> Result<TagMask> {
73 + let net_current_desktop = connection
74 + .intern_atom(false, b"_NET_CURRENT_DESKTOP")?
75 + .reply()?
76 + .atom;
77 +
78 + match connection
79 + .get_property(false, root, net_current_desktop, AtomEnum::CARDINAL, 0, 1)?
80 + .reply()
81 + {
82 + Ok(prop) if prop.value.len() >= 4 => {
83 + // I don't undestand this but I got it from dwm->persist_tags patch and it worked.
84 + let desktop = u32::from_ne_bytes([
85 + prop.value[0],
86 + prop.value[1],
87 + prop.value[2],
88 + prop.value[3],
89 + ]);
90 + if desktop < TAG_COUNT as u32 {
91 + println!("Restored selected tag: {}", desktop);
92 + return Ok(tag_mask(desktop as usize));
93 + }
94 + }
95 + _ => {}
96 + }
97 +
98 + println!("No saved tag, defaulting to tag 0");
99 + Ok(tag_mask(0))
100 + }
101 +
69 102 fn scan_existing_windows(&mut self) -> Result<()> {
70 103 let tree = self.connection.query_tree(self.root)?.reply()?;
71 104
@@ -295,6 +328,9 @@ impl WindowManager {
295 328 }
296 329
297 330 self.selected_tags = tag_mask(tag_index);
331 +
332 + self.save_selected_tags()?;
333 +
298 334 self.update_window_visibility()?;
299 335 self.apply_layout()?;
300 336 self.update_bar()?;
@@ -305,6 +341,30 @@ impl WindowManager {
305 341 Ok(())
306 342 }
307 343
344 + fn save_selected_tags(&self) -> Result<()> {
345 + let net_current_desktop = self
346 + .connection
347 + .intern_atom(false, b"_NET_CURRENT_DESKTOP")?
348 + .reply()?
349 + .atom;
350 +
351 + let desktop = self.selected_tags.trailing_zeros();
352 +
353 + let bytes = (desktop as u32).to_ne_bytes();
354 + self.connection.change_property(
355 + PropMode::REPLACE,
356 + self.root,
357 + net_current_desktop,
358 + AtomEnum::CARDINAL,
359 + 32,
360 + 1,
361 + &bytes,
362 + )?;
363 +
364 + self.connection.flush()?;
365 + Ok(())
366 + }
367 +
308 368 pub fn move_to_tag(&mut self, tag_index: usize) -> Result<()> {
309 369 if tag_index >= TAG_COUNT {
310 370 return Ok(());