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