tony / oxwm

updating padding Browse files
tonybanters committed 2025-10-03 parent 7572793 commit 6dfb18c26fdeeab242ecc5423cbf7d0bc2313428
Showing 2 changed files with 29 additions and 14 deletions. UnifiedSplit
+24 −9 src/bar/bar.rs
@@ -1,5 +1,5 @@
1 1 use super::font::{Font, FontDraw};
2 -use crate::config::{BAR_HEIGHT, FONT, SCHEME_NORMAL, SCHEME_SELECTED, TAGS};
2 +use crate::config::{BAR_HEIGHT, FONT, SCHEME_NORMAL, SCHEME_OCCUPIED, SCHEME_SELECTED, TAGS};
3 3 use anyhow::Result;
4 4 use x11rb::COPY_DEPTH_FROM_PARENT;
5 5 use x11rb::connection::Connection;
@@ -68,7 +68,15 @@ impl Bar {
68 68
69 69 let font_draw = FontDraw::new(display, window as x11::xlib::Drawable, visual, colormap)?;
70 70
71 - let tag_widths = TAGS.iter().map(|tag| font.text_width(tag) + 20).collect();
71 + let tag_widths = TAGS
72 + .iter()
73 + .map(|tag| {
74 + let text_width = font.text_width(tag);
75 + let left_padding = 10;
76 + let right_padding = 10;
77 + text_width + left_padding + right_padding
78 + })
79 + .collect();
72 80
73 81 Ok(Bar {
74 82 window,
@@ -129,25 +137,32 @@ impl Bar {
129 137
130 138 let tag_width = self.tag_widths[tag_index];
131 139
132 - let scheme = if is_selected || is_occupied {
140 + let scheme = if is_selected {
133 141 &SCHEME_SELECTED
142 + } else if is_occupied {
143 + &SCHEME_OCCUPIED
134 144 } else {
135 145 &SCHEME_NORMAL
136 146 };
137 147
148 + let text_width = self.font.text_width(tag);
149 + let left_padding = (tag_width - text_width) / 2;
150 + let text_x = x_position + left_padding as i16;
151 +
138 152 let text_height = self.font.height();
139 - let top_margin = (self.height as i16 - text_height as i16) / 4; // Smaller top margin
153 + let top_margin = (self.height as i16 - text_height as i16) / 4;
140 154 let text_y = top_margin + self.font.ascent();
141 155
142 156 self.font_draw
143 - .draw_text(&self.font, scheme.foreground, x_position + 5, text_y, tag);
157 + .draw_text(&self.font, scheme.foreground, text_x, text_y, tag);
144 158
145 159 if is_selected {
146 160 let underline_height = 3;
147 161 let bottom_margin = 4;
148 162 let underline_y = self.height as i16 - underline_height as i16 - bottom_margin;
149 163
150 - let text_width = self.font.text_width(tag);
164 + let underline_padding = 4;
165 + let underline_width = tag_width - underline_padding;
151 166
152 167 connection.change_gc(
153 168 self.graphics_context,
@@ -157,16 +172,16 @@ impl Bar {
157 172 self.window,
158 173 self.graphics_context,
159 174 &[Rectangle {
160 - x: x_position + 5,
175 + x: x_position + (underline_padding / 2) as i16,
161 176 y: underline_y,
162 - width: text_width,
177 + width: underline_width,
163 178 height: underline_height,
164 179 }],
165 180 )?;
166 181 }
182 +
167 183 x_position += tag_width as i16;
168 184 }
169 -
170 185 connection.flush()?;
171 186
172 187 unsafe {
+5 −5 src/config.rs
@@ -41,11 +41,11 @@ pub const SCHEME_NORMAL: ColorScheme = ColorScheme {
41 41 border: GRAY_MID,
42 42 };
43 43
44 -// pub const SCHEME_OCCUPIED: ColorScheme = ColorScheme {
45 -// foreground: CYAN,
46 -// background: GRAY_DARK,
47 -// border: CYAN,
48 -// };
44 +pub const SCHEME_OCCUPIED: ColorScheme = ColorScheme {
45 + foreground: CYAN,
46 + background: GRAY_DARK,
47 + border: CYAN,
48 +};
49 49
50 50 pub const SCHEME_SELECTED: ColorScheme = ColorScheme {
51 51 foreground: CYAN,