Debugging sigtem restart
Browse files
+36 −6 src/bar/bar.rs
| @@ -23,6 +23,7 @@ pub struct Bar { | ||
| 23 | 23 | |
| 24 | 24 | blocks: Vec<Box<dyn Block>>, |
| 25 | 25 | block_last_updates: Vec<Instant>, |
| 26 | + block_underlines: Vec<bool>, | |
| 26 | 27 | status_text: String, |
| 27 | 28 | } |
| 28 | 29 | |
| @@ -89,12 +90,12 @@ impl Bar { | ||
| 89 | 90 | .map(|config| config.to_block()) |
| 90 | 91 | .collect(); |
| 91 | 92 | |
| 93 | + let block_underlines: Vec<bool> = STATUS_BLOCKS | |
| 94 | + .iter() | |
| 95 | + .map(|config| config.underline) | |
| 96 | + .collect(); | |
| 97 | + | |
| 92 | 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 | 100 | Ok(Bar { |
| 100 | 101 | window, |
| @@ -108,6 +109,7 @@ impl Bar { | ||
| 108 | 109 | needs_redraw: true, |
| 109 | 110 | blocks, |
| 110 | 111 | block_last_updates, |
| 112 | + block_underlines, | |
| 111 | 113 | status_text: String::new(), |
| 112 | 114 | }) |
| 113 | 115 | } |
| @@ -237,7 +239,7 @@ impl Bar { | ||
| 237 | 239 | let padding = 10; |
| 238 | 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 | 243 | if let Ok(text) = block.content() { |
| 242 | 244 | let text_width = self.font.text_width(&text); |
| 243 | 245 | x_position -= text_width as i16; |
| @@ -247,6 +249,33 @@ impl Bar { | ||
| 247 | 249 | |
| 248 | 250 | self.font_draw |
| 249 | 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 | 303 | None |
| 275 | 304 | } |
| 305 | + | |
| 276 | 306 | pub fn needs_redraw(&self) -> bool { |
| 277 | 307 | self.needs_redraw |
| 278 | 308 | } |
+1 −0 src/bar/blocks/mod.rs
| @@ -20,6 +20,7 @@ pub struct BlockConfig { | ||
| 20 | 20 | pub command: BlockCommand, |
| 21 | 21 | pub interval_secs: u64, |
| 22 | 22 | pub color: u32, |
| 23 | + pub underline: bool, | |
| 23 | 24 | } |
| 24 | 25 | |
| 25 | 26 | pub enum BlockCommand { |
+12 −7 src/config.rs
| @@ -116,36 +116,41 @@ pub const STATUS_BLOCKS: &[BlockConfig] = &[ | ||
| 116 | 116 | BlockConfig { |
| 117 | 117 | format: "", |
| 118 | 118 | command: BlockCommand::Battery { |
| 119 | - format_charging: " Bat: {}%", | |
| 120 | - format_discharging: " Bat:{}%", | |
| 121 | - format_full: " Bat: {}%", | |
| 119 | + format_charging: " Bat: {}%", | |
| 120 | + format_discharging: " Bat:{}%", | |
| 121 | + format_full: " Bat: {}%", | |
| 122 | 122 | }, |
| 123 | 123 | interval_secs: 30, |
| 124 | 124 | color: BLUE, |
| 125 | + underline: true, | |
| 125 | 126 | }, |
| 126 | 127 | BlockConfig { |
| 127 | - format: " | ", | |
| 128 | + format: " | ", | |
| 128 | 129 | command: BlockCommand::Static(""), |
| 129 | 130 | interval_secs: u64::MAX, |
| 130 | 131 | color: GRAY_LIGHT, |
| 132 | + underline: false, | |
| 131 | 133 | }, |
| 132 | 134 | BlockConfig { |
| 133 | - format: " {}", | |
| 135 | + format: " {}", | |
| 134 | 136 | command: BlockCommand::Shell("uname -r"), |
| 135 | 137 | interval_secs: u64::MAX, |
| 136 | 138 | color: RED, |
| 139 | + underline: true, | |
| 137 | 140 | }, |
| 138 | 141 | BlockConfig { |
| 139 | - format: " | ", | |
| 142 | + format: " | ", | |
| 140 | 143 | command: BlockCommand::Static(""), |
| 141 | 144 | interval_secs: u64::MAX, |
| 142 | 145 | color: GRAY_LIGHT, |
| 146 | + underline: false, | |
| 143 | 147 | }, |
| 144 | 148 | BlockConfig { |
| 145 | - format: " {}", | |
| 149 | + format: " {}", | |
| 146 | 150 | command: BlockCommand::DateTime("%a, %b %d - %-I:%M %P"), |
| 147 | 151 | interval_secs: 1, |
| 148 | 152 | color: CYAN, |
| 153 | + underline: true, | |
| 149 | 154 | }, |
| 150 | 155 | ]; |
| 151 | 156 |
+7 −8 src/main.rs
| @@ -6,18 +6,17 @@ mod layout; | ||
| 6 | 6 | mod window_manager; |
| 7 | 7 | |
| 8 | 8 | fn main() -> Result<()> { |
| 9 | - loop { | |
| 10 | - let mut window_manager = window_manager::WindowManager::new()?; | |
| 11 | - let should_restart = window_manager.run()?; | |
| 9 | + let args: Vec<String> = std::env::args().collect(); | |
| 12 | 10 | |
| 13 | - if !should_restart { | |
| 14 | - break; | |
| 15 | - } | |
| 11 | + let mut window_manager = window_manager::WindowManager::new()?; | |
| 12 | + let should_restart = window_manager.run()?; | |
| 16 | 13 | |
| 14 | + drop(window_manager); | |
| 15 | + | |
| 16 | + if should_restart { | |
| 17 | 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 | 19 | eprintln!("Failed to restart: {}", err); |
| 20 | - break; | |
| 21 | 20 | } |
| 22 | 21 | |
| 23 | 22 | Ok(()) |
+40 −7 src/window_manager.rs
| @@ -69,20 +69,53 @@ impl WindowManager { | ||
| 69 | 69 | fn scan_existing_windows(&mut self) -> Result<()> { |
| 70 | 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 | 76 | for &window in &tree.children { |
| 73 | - if let Ok(attrs) = self.connection.get_window_attributes(window)?.reply() { | |
| 74 | - if window != self.bar.window() | |
| 75 | - && attrs.map_state == MapState::VIEWABLE | |
| 76 | - && !attrs.override_redirect | |
| 77 | - { | |
| 78 | - self.windows.push(window); | |
| 79 | - self.window_tags.insert(window, self.selected_tags); | |
| 77 | + if window == self.bar.window() { | |
| 78 | + println!("Skipping bar window: {}", window); | |
| 79 | + continue; | |
| 80 | + } | |
| 81 | + | |
| 82 | + let attrs = match self.connection.get_window_attributes(window)?.reply() { | |
| 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 | 114 | if let Some(&first) = self.windows.first() { |
| 84 | 115 | self.set_focus(Some(first))?; |
| 85 | 116 | } |
| 117 | + | |
| 118 | + self.apply_layout()?; | |
| 86 | 119 | Ok(()) |
| 87 | 120 | } |
| 88 | 121 |