Diff
diff --git a/src/bar/bar.rs b/src/bar/bar.rs
index 8a356a7..64acd03 100644
--- a/src/bar/bar.rs
+++ b/src/bar/bar.rs
@@ -23,6 +23,7 @@ pub struct Bar {
blocks: Vec<Box<dyn Block>>,
block_last_updates: Vec<Instant>,
+ block_underlines: Vec<bool>,
status_text: String,
}
@@ -89,12 +90,12 @@ impl Bar {
.map(|config| config.to_block())
.collect();
+ let block_underlines: Vec<bool> = STATUS_BLOCKS
+ .iter()
+ .map(|config| config.underline)
+ .collect();
+
let block_last_updates = vec![Instant::now(); blocks.len()];
- // let blocks: Vec<Box<dyn Block>> = vec![
- // Box::new(Uname::new(UNAME_PREFIX, UNAME_COLOR)),
- // Box::new(Sep::new(SEPARATOR, SEP_COLOR)),
- // Box::new(Clock::new(CLOCK_FORMAT, CLOCK_COLOR)),
- // ];
Ok(Bar {
window,
@@ -108,6 +109,7 @@ impl Bar {
needs_redraw: true,
blocks,
block_last_updates,
+ block_underlines,
status_text: String::new(),
})
}
@@ -237,7 +239,7 @@ impl Bar {
let padding = 10;
let mut x_position = self.width as i16 - padding;
- for block in self.blocks.iter_mut().rev() {
+ for (i, block) in self.blocks.iter_mut().enumerate().rev() {
if let Ok(text) = block.content() {
let text_width = self.font.text_width(&text);
x_position -= text_width as i16;
@@ -247,6 +249,33 @@ impl Bar {
self.font_draw
.draw_text(&self.font, block.color(), x_position, text_y, &text);
+
+ if self.block_underlines[i] {
+ let font_height = self.font.height();
+ let underline_height = font_height / 8;
+ let bottom_gap = 3;
+ let underline_y = self.height as i16 - underline_height as i16 - bottom_gap;
+
+ let underline_padding = 8;
+ let underline_width = text_width + underline_padding;
+ let underline_x = x_position - (underline_padding / 2) as i16;
+
+ connection.change_gc(
+ self.graphics_context,
+ &ChangeGCAux::new().foreground(block.color()),
+ )?;
+
+ connection.poly_fill_rectangle(
+ self.window,
+ self.graphics_context,
+ &[Rectangle {
+ x: underline_x,
+ y: underline_y,
+ width: underline_width,
+ height: underline_height,
+ }],
+ )?;
+ }
}
}
}
@@ -273,6 +302,7 @@ impl Bar {
}
None
}
+
pub fn needs_redraw(&self) -> bool {
self.needs_redraw
}
diff --git a/src/bar/blocks/mod.rs b/src/bar/blocks/mod.rs
index 6c9ccc3..0a9986a 100644
--- a/src/bar/blocks/mod.rs
+++ b/src/bar/blocks/mod.rs
@@ -20,6 +20,7 @@ pub struct BlockConfig {
pub command: BlockCommand,
pub interval_secs: u64,
pub color: u32,
+ pub underline: bool,
}
pub enum BlockCommand {
diff --git a/src/config.rs b/src/config.rs
index 2f8e292..cef7770 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -116,36 +116,41 @@ pub const STATUS_BLOCKS: &[BlockConfig] = &[
BlockConfig {
format: "",
command: BlockCommand::Battery {
- format_charging: " Bat: {}%",
- format_discharging: " Bat:{}%",
- format_full: " Bat: {}%",
+ format_charging: " Bat: {}%",
+ format_discharging: " Bat:{}%",
+ format_full: " Bat: {}%",
},
interval_secs: 30,
color: BLUE,
+ underline: true,
},
BlockConfig {
- format: " | ",
+ format: " | ",
command: BlockCommand::Static(""),
interval_secs: u64::MAX,
color: GRAY_LIGHT,
+ underline: false,
},
BlockConfig {
- format: " {}",
+ format: " {}",
command: BlockCommand::Shell("uname -r"),
interval_secs: u64::MAX,
color: RED,
+ underline: true,
},
BlockConfig {
- format: " | ",
+ format: " | ",
command: BlockCommand::Static(""),
interval_secs: u64::MAX,
color: GRAY_LIGHT,
+ underline: false,
},
BlockConfig {
- format: " {}",
+ format: " {}",
command: BlockCommand::DateTime("%a, %b %d - %-I:%M %P"),
interval_secs: 1,
color: CYAN,
+ underline: true,
},
];
diff --git a/src/main.rs b/src/main.rs
index 121bf64..2e3a92e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,18 +6,17 @@ mod layout;
mod window_manager;
fn main() -> Result<()> {
- loop {
- let mut window_manager = window_manager::WindowManager::new()?;
- let should_restart = window_manager.run()?;
+ let args: Vec<String> = std::env::args().collect();
- if !should_restart {
- break;
- }
+ let mut window_manager = window_manager::WindowManager::new()?;
+ let should_restart = window_manager.run()?;
+ drop(window_manager);
+
+ if should_restart {
use std::os::unix::process::CommandExt;
- let err = std::process::Command::new(config::WM_BINARY).exec();
+ let err = std::process::Command::new(&args[0]).args(&args[1..]).exec();
eprintln!("Failed to restart: {}", err);
- break;
}
Ok(())
diff --git a/src/window_manager.rs b/src/window_manager.rs
index 3d4f08a..329ba42 100644
--- a/src/window_manager.rs
+++ b/src/window_manager.rs
@@ -69,20 +69,53 @@ impl WindowManager {
fn scan_existing_windows(&mut self) -> Result<()> {
let tree = self.connection.query_tree(self.root)?.reply()?;
+ println!("=== Scanning existing windows ===");
+ println!("Total children: {}", tree.children.len());
+ println!("Current selected_tags: {:b}", self.selected_tags);
+
for &window in &tree.children {
- if let Ok(attrs) = self.connection.get_window_attributes(window)?.reply() {
- if window != self.bar.window()
- && attrs.map_state == MapState::VIEWABLE
- && !attrs.override_redirect
- {
- self.windows.push(window);
- self.window_tags.insert(window, self.selected_tags);
+ if window == self.bar.window() {
+ println!("Skipping bar window: {}", window);
+ continue;
+ }
+
+ let attrs = match self.connection.get_window_attributes(window)?.reply() {
+ Ok(attrs) => attrs,
+ Err(_) => {
+ println!("Failed to get attributes for window: {}", window);
+ continue;
}
+ };
+
+ println!(
+ "Window {}: override_redirect={}, map_state={:?}",
+ window, attrs.override_redirect, attrs.map_state
+ );
+
+ if attrs.override_redirect {
+ println!(" -> Skipped (override_redirect)");
+ continue;
+ }
+
+ if attrs.map_state == MapState::VIEWABLE || attrs.map_state == MapState::UNMAPPED {
+ println!(
+ " -> Managing window, tagging with {:b}",
+ self.selected_tags
+ );
+ self.windows.push(window);
+ self.window_tags.insert(window, self.selected_tags);
+ } else {
+ println!(" -> Skipped (map_state={:?})", attrs.map_state);
}
}
+
+ println!("Total managed windows: {}", self.windows.len());
+
if let Some(&first) = self.windows.first() {
self.set_focus(Some(first))?;
}
+
+ self.apply_layout()?;
Ok(())
}