|
|
@@ -14,9 +14,7 @@ pub struct Bar { |
| 14 |
14 |
height: u16, |
| 15 |
15 |
graphics_context: Gcontext, |
| 16 |
16 |
|
| 17 |
|
- font: Font, |
| 18 |
17 |
font_draw: FontDraw, |
| 19 |
|
- display: *mut x11::xlib::Display, |
| 20 |
18 |
|
| 21 |
19 |
tag_widths: Vec<u16>, |
| 22 |
20 |
needs_redraw: bool, |
|
|
@@ -38,6 +36,8 @@ impl Bar { |
| 38 |
36 |
screen: &Screen, |
| 39 |
37 |
screen_num: usize, |
| 40 |
38 |
config: &Config, |
|
39 |
+ display: *mut x11::xlib::Display, |
|
40 |
+ font: &Font, |
| 41 |
41 |
x: i16, |
| 42 |
42 |
y: i16, |
| 43 |
43 |
width: u16, |
|
|
@@ -45,13 +45,6 @@ impl Bar { |
| 45 |
45 |
let window = connection.generate_id()?; |
| 46 |
46 |
let graphics_context = connection.generate_id()?; |
| 47 |
47 |
|
| 48 |
|
- let display = unsafe { x11::xlib::XOpenDisplay(std::ptr::null()) }; |
| 49 |
|
- if display.is_null() { |
| 50 |
|
- return Err(X11Error::DisplayOpenFailed.into()); |
| 51 |
|
- } |
| 52 |
|
- |
| 53 |
|
- let font = Font::new(display, screen_num as i32, &config.font)?; |
| 54 |
|
- |
| 55 |
48 |
let height = (font.height() as f32 * 1.4) as u16; |
| 56 |
49 |
|
| 57 |
50 |
connection.create_window( |
|
|
@@ -117,9 +110,7 @@ impl Bar { |
| 117 |
110 |
width, |
| 118 |
111 |
height, |
| 119 |
112 |
graphics_context, |
| 120 |
|
- font, |
| 121 |
113 |
font_draw, |
| 122 |
|
- display, |
| 123 |
114 |
tag_widths, |
| 124 |
115 |
needs_redraw: true, |
| 125 |
116 |
blocks, |
|
|
@@ -175,6 +166,8 @@ impl Bar { |
| 175 |
166 |
pub fn draw( |
| 176 |
167 |
&mut self, |
| 177 |
168 |
connection: &RustConnection, |
|
169 |
+ font: &Font, |
|
170 |
+ display: *mut x11::xlib::Display, |
| 178 |
171 |
current_tags: u32, |
| 179 |
172 |
occupied_tags: u32, |
| 180 |
173 |
draw_blocks: bool, |
|
|
@@ -215,17 +208,17 @@ impl Bar { |
| 215 |
208 |
&self.scheme_normal |
| 216 |
209 |
}; |
| 217 |
210 |
|
| 218 |
|
- let text_width = self.font.text_width(tag); |
|
211 |
+ let text_width = font.text_width(tag); |
| 219 |
212 |
let text_x = x_position + ((tag_width - text_width) / 2) as i16; |
| 220 |
213 |
|
| 221 |
214 |
let top_padding = 4; |
| 222 |
|
- let text_y = top_padding + self.font.ascent(); |
|
215 |
+ let text_y = top_padding + font.ascent(); |
| 223 |
216 |
|
| 224 |
217 |
self.font_draw |
| 225 |
|
- .draw_text(&self.font, scheme.foreground, text_x, text_y, tag); |
|
218 |
+ .draw_text(font, scheme.foreground, text_x, text_y, tag); |
| 226 |
219 |
|
| 227 |
220 |
if is_selected { |
| 228 |
|
- let font_height = self.font.height(); |
|
221 |
+ let font_height = font.height(); |
| 229 |
222 |
let underline_height = font_height / 8; |
| 230 |
223 |
let bottom_gap = 3; |
| 231 |
224 |
let underline_y = self.height as i16 - underline_height as i16 - bottom_gap; |
|
|
@@ -259,17 +252,17 @@ impl Bar { |
| 259 |
252 |
|
| 260 |
253 |
for (i, block) in self.blocks.iter_mut().enumerate().rev() { |
| 261 |
254 |
if let Ok(text) = block.content() { |
| 262 |
|
- let text_width = self.font.text_width(&text); |
|
255 |
+ let text_width = font.text_width(&text); |
| 263 |
256 |
x_position -= text_width as i16; |
| 264 |
257 |
|
| 265 |
258 |
let top_padding = 4; |
| 266 |
|
- let text_y = top_padding + self.font.ascent(); |
|
259 |
+ let text_y = top_padding + font.ascent(); |
| 267 |
260 |
|
| 268 |
261 |
self.font_draw |
| 269 |
|
- .draw_text(&self.font, block.color(), x_position, text_y, &text); |
|
262 |
+ .draw_text(font, block.color(), x_position, text_y, &text); |
| 270 |
263 |
|
| 271 |
264 |
if self.block_underlines[i] { |
| 272 |
|
- let font_height = self.font.height(); |
|
265 |
+ let font_height = font.height(); |
| 273 |
266 |
let underline_height = font_height / 8; |
| 274 |
267 |
let bottom_gap = 3; |
| 275 |
268 |
let underline_y = self.height as i16 - underline_height as i16 - bottom_gap; |
|
|
@@ -299,7 +292,7 @@ impl Bar { |
| 299 |
292 |
} |
| 300 |
293 |
connection.flush()?; |
| 301 |
294 |
unsafe { |
| 302 |
|
- x11::xlib::XFlush(self.display); |
|
295 |
+ x11::xlib::XFlush(display); |
| 303 |
296 |
} |
| 304 |
297 |
self.needs_redraw = false; |
| 305 |
298 |
|