tony / oxwm

Debugging sigtem restart Browse files
tonybtw committed 2025-10-05 parent 6f540a5 commit a3977f8c921e4baaa2a620e9fd506367ad199a39
Showing 5 changed files with 96 additions and 28 deletions. UnifiedSplit
+36 −6 src/bar/bar.rs
@@ -23,6 +23,7 @@ pub struct Bar {
23 23
24 blocks: Vec<Box<dyn Block>>, 24 blocks: Vec<Box<dyn Block>>,
25 block_last_updates: Vec<Instant>, 25 block_last_updates: Vec<Instant>,
26 + block_underlines: Vec<bool>,
26 status_text: String, 27 status_text: String,
27 } 28 }
28 29
@@ -89,12 +90,12 @@ impl Bar {
89 .map(|config| config.to_block()) 90 .map(|config| config.to_block())
90 .collect(); 91 .collect();
91 92
93 + let block_underlines: Vec<bool> = STATUS_BLOCKS
94 + .iter()
95 + .map(|config| config.underline)
96 + .collect();
97 +
92 let block_last_updates = vec![Instant::now(); blocks.len()]; 98 let block_last_updates = vec![Instant::now(); blocks.len()];
93 - // let blocks: Vec<Box<dyn Block>> = vec![
94 - // Box::new(Uname::new(UNAME_PREFIX, UNAME_COLOR)),
95 - // Box::new(Sep::new(SEPARATOR, SEP_COLOR)),
96 - // Box::new(Clock::new(CLOCK_FORMAT, CLOCK_COLOR)),
97 - // ];
98 99
99 Ok(Bar { 100 Ok(Bar {
100 window, 101 window,
@@ -108,6 +109,7 @@ impl Bar {
108 needs_redraw: true, 109 needs_redraw: true,
109 blocks, 110 blocks,
110 block_last_updates, 111 block_last_updates,
112 + block_underlines,
111 status_text: String::new(), 113 status_text: String::new(),
112 }) 114 })
113 } 115 }
@@ -237,7 +239,7 @@ impl Bar {
237 let padding = 10; 239 let padding = 10;
238 let mut x_position = self.width as i16 - padding; 240 let mut x_position = self.width as i16 - padding;
239 241
240 - for block in self.blocks.iter_mut().rev() { 242 + for (i, block) in self.blocks.iter_mut().enumerate().rev() {
241 if let Ok(text) = block.content() { 243 if let Ok(text) = block.content() {
242 let text_width = self.font.text_width(&text); 244 let text_width = self.font.text_width(&text);
243 x_position -= text_width as i16; 245 x_position -= text_width as i16;
@@ -247,6 +249,33 @@ impl Bar {
247 249
248 self.font_draw 250 self.font_draw
249 .draw_text(&self.font, block.color(), x_position, text_y, &text); 251 .draw_text(&self.font, block.color(), x_position, text_y, &text);
252 +
253 + if self.block_underlines[i] {
254 + let font_height = self.font.height();
255 + let underline_height = font_height / 8;
256 + let bottom_gap = 3;
257 + let underline_y = self.height as i16 - underline_height as i16 - bottom_gap;
258 +
259 + let underline_padding = 8;
260 + let underline_width = text_width + underline_padding;
261 + let underline_x = x_position - (underline_padding / 2) as i16;
262 +
263 + connection.change_gc(
264 + self.graphics_context,
265 + &ChangeGCAux::new().foreground(block.color()),
266 + )?;
267 +
268 + connection.poly_fill_rectangle(
269 + self.window,
270 + self.graphics_context,
271 + &[Rectangle {
272 + x: underline_x,
273 + y: underline_y,
274 + width: underline_width,
275 + height: underline_height,
276 + }],
277 + )?;
278 + }
250 } 279 }
251 } 280 }
252 } 281 }
@@ -273,6 +302,7 @@ impl Bar {
273 } 302 }
274 None 303 None
275 } 304 }
305 +
276 pub fn needs_redraw(&self) -> bool { 306 pub fn needs_redraw(&self) -> bool {
277 self.needs_redraw 307 self.needs_redraw
278 } 308 }
+1 −0 src/bar/blocks/mod.rs
@@ -20,6 +20,7 @@ pub struct BlockConfig {
20 pub command: BlockCommand, 20 pub command: BlockCommand,
21 pub interval_secs: u64, 21 pub interval_secs: u64,
22 pub color: u32, 22 pub color: u32,
23 + pub underline: bool,
23 } 24 }
24 25
25 pub enum BlockCommand { 26 pub enum BlockCommand {
+12 −7 src/config.rs
@@ -116,36 +116,41 @@ pub const STATUS_BLOCKS: &[BlockConfig] = &[
116 BlockConfig { 116 BlockConfig {
117 format: "", 117 format: "",
118 command: BlockCommand::Battery { 118 command: BlockCommand::Battery {
119 - format_charging: " 󰂄 Bat: {}%", 119 + format_charging: "󰂄 Bat: {}%",
120 - format_discharging: " 󰁹 Bat:{}%", 120 + format_discharging: "󰁹 Bat:{}%",
121 - format_full: " 󰁹 Bat: {}%", 121 + format_full: "󰁹 Bat: {}%",
122 }, 122 },
123 interval_secs: 30, 123 interval_secs: 30,
124 color: BLUE, 124 color: BLUE,
125 + underline: true,
125 }, 126 },
126 BlockConfig { 127 BlockConfig {
127 - format: " | ", 128 + format: " | ",
128 command: BlockCommand::Static(""), 129 command: BlockCommand::Static(""),
129 interval_secs: u64::MAX, 130 interval_secs: u64::MAX,
130 color: GRAY_LIGHT, 131 color: GRAY_LIGHT,
132 + underline: false,
131 }, 133 },
132 BlockConfig { 134 BlockConfig {
133 - format: "  {}", 135 + format: " {}",
134 command: BlockCommand::Shell("uname -r"), 136 command: BlockCommand::Shell("uname -r"),
135 interval_secs: u64::MAX, 137 interval_secs: u64::MAX,
136 color: RED, 138 color: RED,
139 + underline: true,
137 }, 140 },
138 BlockConfig { 141 BlockConfig {
139 - format: " | ", 142 + format: " | ",
140 command: BlockCommand::Static(""), 143 command: BlockCommand::Static(""),
141 interval_secs: u64::MAX, 144 interval_secs: u64::MAX,
142 color: GRAY_LIGHT, 145 color: GRAY_LIGHT,
146 + underline: false,
143 }, 147 },
144 BlockConfig { 148 BlockConfig {
145 - format: " 󰸘 {}", 149 + format: "󰸘 {}",
146 command: BlockCommand::DateTime("%a, %b %d - %-I:%M %P"), 150 command: BlockCommand::DateTime("%a, %b %d - %-I:%M %P"),
147 interval_secs: 1, 151 interval_secs: 1,
148 color: CYAN, 152 color: CYAN,
153 + underline: true,
149 }, 154 },
150 ]; 155 ];
151 156
+7 −8 src/main.rs
@@ -6,18 +6,17 @@ mod layout;
6 mod window_manager; 6 mod window_manager;
7 7
8 fn main() -> Result<()> { 8 fn main() -> Result<()> {
9 - loop { 9 + let args: Vec<String> = std::env::args().collect();
10 - let mut window_manager = window_manager::WindowManager::new()?;
11 - let should_restart = window_manager.run()?;
12 10
13 - if !should_restart { 11 + let mut window_manager = window_manager::WindowManager::new()?;
14 - break; 12 + let should_restart = window_manager.run()?;
15 - }
16 13
14 + drop(window_manager);
15 +
16 + if should_restart {
17 use std::os::unix::process::CommandExt; 17 use std::os::unix::process::CommandExt;
18 - let err = std::process::Command::new(config::WM_BINARY).exec(); 18 + let err = std::process::Command::new(&args[0]).args(&args[1..]).exec();
19 eprintln!("Failed to restart: {}", err); 19 eprintln!("Failed to restart: {}", err);
20 - break;
21 } 20 }
22 21
23 Ok(()) 22 Ok(())
+40 −7 src/window_manager.rs
@@ -69,20 +69,53 @@ impl WindowManager {
69 fn scan_existing_windows(&mut self) -> Result<()> { 69 fn scan_existing_windows(&mut self) -> Result<()> {
70 let tree = self.connection.query_tree(self.root)?.reply()?; 70 let tree = self.connection.query_tree(self.root)?.reply()?;
71 71
72 + println!("=== Scanning existing windows ===");
73 + println!("Total children: {}", tree.children.len());
74 + println!("Current selected_tags: {:b}", self.selected_tags);
75 +
72 for &window in &tree.children { 76 for &window in &tree.children {
73 - if let Ok(attrs) = self.connection.get_window_attributes(window)?.reply() { 77 + if window == self.bar.window() {
74 - if window != self.bar.window() 78 + println!("Skipping bar window: {}", window);
75 - && attrs.map_state == MapState::VIEWABLE 79 + continue;
76 - && !attrs.override_redirect 80 + }
77 - { 81 +
78 - self.windows.push(window); 82 + let attrs = match self.connection.get_window_attributes(window)?.reply() {
79 - self.window_tags.insert(window, self.selected_tags); 83 + Ok(attrs) => attrs,
84 + Err(_) => {
85 + println!("Failed to get attributes for window: {}", window);
86 + continue;
80 } 87 }
88 + };
89 +
90 + println!(
91 + "Window {}: override_redirect={}, map_state={:?}",
92 + window, attrs.override_redirect, attrs.map_state
93 + );
94 +
95 + if attrs.override_redirect {
96 + println!(" -> Skipped (override_redirect)");
97 + continue;
98 + }
99 +
100 + if attrs.map_state == MapState::VIEWABLE || attrs.map_state == MapState::UNMAPPED {
101 + println!(
102 + " -> Managing window, tagging with {:b}",
103 + self.selected_tags
104 + );
105 + self.windows.push(window);
106 + self.window_tags.insert(window, self.selected_tags);
107 + } else {
108 + println!(" -> Skipped (map_state={:?})", attrs.map_state);
81 } 109 }
82 } 110 }
111 +
112 + println!("Total managed windows: {}", self.windows.len());
113 +
83 if let Some(&first) = self.windows.first() { 114 if let Some(&first) = self.windows.first() {
84 self.set_focus(Some(first))?; 115 self.set_focus(Some(first))?;
85 } 116 }
117 +
118 + self.apply_layout()?;
86 Ok(()) 119 Ok(())
87 } 120 }
88 121