tony / oxwm

updating padding Browse files
tonybanters committed 2025-10-03 parent c55f819 commit 9c46346da72cdd346c59dd6529a19fb5710d8c84
Showing 1 changed file with 10 additions and 11 deletions. UnifiedSplit
+10 −11 src/bar/bar.rs
@@ -32,7 +32,6 @@ impl Bar {
32 anyhow::bail!("Failed to open X11 display for XFT"); 32 anyhow::bail!("Failed to open X11 display for XFT");
33 } 33 }
34 let font = Font::new(display, screen_num as i32, FONT)?; 34 let font = Font::new(display, screen_num as i32, FONT)?;
35 -
36 let height = font.height() + 4; 35 let height = font.height() + 4;
37 36
38 connection.create_window( 37 connection.create_window(
@@ -68,13 +67,13 @@ impl Bar {
68 67
69 let font_draw = FontDraw::new(display, window as x11::xlib::Drawable, visual, colormap)?; 68 let font_draw = FontDraw::new(display, window as x11::xlib::Drawable, visual, colormap)?;
70 69
70 + let horizontal_padding = (font.height() as f32 * 0.6) as u16;
71 +
71 let tag_widths = TAGS 72 let tag_widths = TAGS
72 .iter() 73 .iter()
73 .map(|tag| { 74 .map(|tag| {
74 let text_width = font.text_width(tag); 75 let text_width = font.text_width(tag);
75 - let left_padding = 10; 76 + text_width + (horizontal_padding * 2)
76 - let right_padding = 10;
77 - text_width + left_padding + right_padding
78 }) 77 })
79 .collect(); 78 .collect();
80 79
@@ -145,9 +144,9 @@ impl Bar {
145 &SCHEME_NORMAL 144 &SCHEME_NORMAL
146 }; 145 };
147 146
147 + // Center text horizontally in tag box
148 let text_width = self.font.text_width(tag); 148 let text_width = self.font.text_width(tag);
149 - let left_padding = (tag_width - text_width) / 2; 149 + let text_x = x_position + ((tag_width - text_width) / 2) as i16;
150 - let text_x = x_position + left_padding as i16;
151 150
152 let text_height = self.font.height(); 151 let text_height = self.font.height();
153 let top_margin = (self.height as i16 - text_height as i16) / 4; 152 let top_margin = (self.height as i16 - text_height as i16) / 4;
@@ -157,13 +156,13 @@ impl Bar {
157 .draw_text(&self.font, scheme.foreground, text_x, text_y, tag); 156 .draw_text(&self.font, scheme.foreground, text_x, text_y, tag);
158 157
159 if is_selected { 158 if is_selected {
160 - let underline_height = 3; 159 + // Scale underline thickness with font size (roughly 1/8 of font height)
160 + let underline_height = (self.font.height() / 8).max(2) as u16;
161 let bottom_margin = 4; 161 let bottom_margin = 4;
162 let underline_y = self.height as i16 - underline_height as i16 - bottom_margin; 162 let underline_y = self.height as i16 - underline_height as i16 - bottom_margin;
163 163
164 - let text_width = self.font.text_width(tag); 164 + // Make underline same width and position as text
165 - let underline_width = text_width + 4; 165 + let underline_x = text_x;
166 - let underline_x = x_position + ((tag_width - underline_width) / 2) as i16;
167 166
168 connection.change_gc( 167 connection.change_gc(
169 self.graphics_context, 168 self.graphics_context,
@@ -175,7 +174,7 @@ impl Bar {
175 &[Rectangle { 174 &[Rectangle {
176 x: underline_x, 175 x: underline_x,
177 y: underline_y, 176 y: underline_y,
178 - width: underline_width, 177 + width: text_width,
179 height: underline_height, 178 height: underline_height,
180 }], 179 }],
181 )?; 180 )?;