| @@ -1,5 +1,5 @@ |
| 1 |
use super::font::{Font, FontDraw}; |
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 |
use anyhow::Result; |
3 |
use anyhow::Result; |
| 4 |
use x11rb::COPY_DEPTH_FROM_PARENT; |
4 |
use x11rb::COPY_DEPTH_FROM_PARENT; |
| 5 |
use x11rb::connection::Connection; |
5 |
use x11rb::connection::Connection; |
| @@ -68,7 +68,15 @@ impl Bar { |
| 68 |
|
68 |
|
| 69 |
let font_draw = FontDraw::new(display, window as x11::xlib::Drawable, visual, colormap)?; |
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 |
Ok(Bar { |
81 |
Ok(Bar { |
| 74 |
window, |
82 |
window, |
| @@ -129,25 +137,32 @@ impl Bar { |
| 129 |
|
137 |
|
| 130 |
let tag_width = self.tag_widths[tag_index]; |
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 |
&SCHEME_SELECTED |
141 |
&SCHEME_SELECTED |
|
|
142 |
+ } else if is_occupied { |
|
|
143 |
+ &SCHEME_OCCUPIED |
| 134 |
} else { |
144 |
} else { |
| 135 |
&SCHEME_NORMAL |
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 |
let text_height = self.font.height(); |
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 |
let text_y = top_margin + self.font.ascent(); |
154 |
let text_y = top_margin + self.font.ascent(); |
| 141 |
|
155 |
|
| 142 |
self.font_draw |
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 |
if is_selected { |
159 |
if is_selected { |
| 146 |
let underline_height = 3; |
160 |
let underline_height = 3; |
| 147 |
let bottom_margin = 4; |
161 |
let bottom_margin = 4; |
| 148 |
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; |
| 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 |
connection.change_gc( |
167 |
connection.change_gc( |
| 153 |
self.graphics_context, |
168 |
self.graphics_context, |
| @@ -157,16 +172,16 @@ impl Bar { |
| 157 |
self.window, |
172 |
self.window, |
| 158 |
self.graphics_context, |
173 |
self.graphics_context, |
| 159 |
&[Rectangle { |
174 |
&[Rectangle { |
| 160 |
- x: x_position + 5, |
175 |
+ x: x_position + (underline_padding / 2) as i16, |
| 161 |
y: underline_y, |
176 |
y: underline_y, |
| 162 |
- width: text_width, |
177 |
+ width: underline_width, |
| 163 |
height: underline_height, |
178 |
height: underline_height, |
| 164 |
}], |
179 |
}], |
| 165 |
)?; |
180 |
)?; |
| 166 |
} |
181 |
} |
|
|
182 |
+ |
| 167 |
x_position += tag_width as i16; |
183 |
x_position += tag_width as i16; |
| 168 |
} |
184 |
} |
| 169 |
- |
|
|
| 170 |
connection.flush()?; |
185 |
connection.flush()?; |
| 171 |
|
186 |
|
| 172 |
unsafe { |
187 |
unsafe { |