C has good C interop
Browse files
+19 −7 src/bar/bar.rs
| @@ -76,7 +76,6 @@ impl Bar { | |||
| 76 | .background(config.scheme_normal.background), | 76 | .background(config.scheme_normal.background), |
| 77 | )?; | 77 | )?; |
| 78 | 78 | ||
| 79 | - // Set cursor using xlib after window creation | ||
| 80 | unsafe { | 79 | unsafe { |
| 81 | x11::xlib::XDefineCursor(display, window as u64, cursor as u64); | 80 | x11::xlib::XDefineCursor(display, window as u64, cursor as u64); |
| 82 | } | 81 | } |
| @@ -266,7 +265,12 @@ impl Bar { | |||
| 266 | let underline_x = x_position + (underline_padding / 2) as i16; | 265 | let underline_x = x_position + (underline_padding / 2) as i16; |
| 267 | 266 | ||
| 268 | unsafe { | 267 | unsafe { |
| 269 | - let gc = x11::xlib::XCreateGC(display, self.surface.pixmap(), 0, std::ptr::null_mut()); | 268 | + let gc = x11::xlib::XCreateGC( |
| 269 | + display, | ||
| 270 | + self.surface.pixmap(), | ||
| 271 | + 0, | ||
| 272 | + std::ptr::null_mut(), | ||
| 273 | + ); | ||
| 270 | x11::xlib::XSetForeground(display, gc, scheme.underline as u64); | 274 | x11::xlib::XSetForeground(display, gc, scheme.underline as u64); |
| 271 | x11::xlib::XFillRectangle( | 275 | x11::xlib::XFillRectangle( |
| 272 | display, | 276 | display, |
| @@ -327,9 +331,13 @@ impl Bar { | |||
| 327 | let top_padding = 4; | 331 | let top_padding = 4; |
| 328 | let text_y = top_padding + font.ascent(); | 332 | let text_y = top_padding + font.ascent(); |
| 329 | 333 | ||
| 330 | - self.surface | 334 | + self.surface.font_draw().draw_text( |
| 331 | - .font_draw() | 335 | + font, |
| 332 | - .draw_text(font, block.color(), x_position, text_y, &text); | 336 | + block.color(), |
| 337 | + x_position, | ||
| 338 | + text_y, | ||
| 339 | + &text, | ||
| 340 | + ); | ||
| 333 | 341 | ||
| 334 | if self.block_underlines[i] { | 342 | if self.block_underlines[i] { |
| 335 | let font_height = font.height(); | 343 | let font_height = font.height(); |
| @@ -342,8 +350,12 @@ impl Bar { | |||
| 342 | let underline_x = x_position - (underline_padding / 2) as i16; | 350 | let underline_x = x_position - (underline_padding / 2) as i16; |
| 343 | 351 | ||
| 344 | unsafe { | 352 | unsafe { |
| 345 | - let gc = | 353 | + let gc = x11::xlib::XCreateGC( |
| 346 | - x11::xlib::XCreateGC(display, self.surface.pixmap(), 0, std::ptr::null_mut()); | 354 | + display, |
| 355 | + self.surface.pixmap(), | ||
| 356 | + 0, | ||
| 357 | + std::ptr::null_mut(), | ||
| 358 | + ); | ||
| 347 | x11::xlib::XSetForeground(display, gc, block.color() as u64); | 359 | x11::xlib::XSetForeground(display, gc, block.color() as u64); |
| 348 | x11::xlib::XFillRectangle( | 360 | x11::xlib::XFillRectangle( |
| 349 | display, | 361 | display, |
+15 −7 src/tab_bar.rs
| @@ -64,7 +64,6 @@ impl TabBar { | |||
| 64 | .background(scheme_normal.background), | 64 | .background(scheme_normal.background), |
| 65 | )?; | 65 | )?; |
| 66 | 66 | ||
| 67 | - // Set cursor using xlib after window creation | ||
| 68 | unsafe { | 67 | unsafe { |
| 69 | x11::xlib::XDefineCursor(display, window as u64, cursor as u64); | 68 | x11::xlib::XDefineCursor(display, window as u64, cursor as u64); |
| 70 | } | 69 | } |
| @@ -116,7 +115,8 @@ impl TabBar { | |||
| 116 | connection.flush()?; | 115 | connection.flush()?; |
| 117 | 116 | ||
| 118 | unsafe { | 117 | unsafe { |
| 119 | - let gc = x11::xlib::XCreateGC(self.display, self.surface.pixmap(), 0, std::ptr::null_mut()); | 118 | + let gc = |
| 119 | + x11::xlib::XCreateGC(self.display, self.surface.pixmap(), 0, std::ptr::null_mut()); | ||
| 120 | x11::xlib::XSetForeground(self.display, gc, self.scheme_normal.background as u64); | 120 | x11::xlib::XSetForeground(self.display, gc, self.scheme_normal.background as u64); |
| 121 | x11::xlib::XFillRectangle( | 121 | x11::xlib::XFillRectangle( |
| 122 | self.display, | 122 | self.display, |
| @@ -158,17 +158,25 @@ impl TabBar { | |||
| 158 | let top_padding = 6; | 158 | let top_padding = 6; |
| 159 | let text_y = top_padding + font.ascent(); | 159 | let text_y = top_padding + font.ascent(); |
| 160 | 160 | ||
| 161 | - self.surface | 161 | + self.surface.font_draw().draw_text( |
| 162 | - .font_draw() | 162 | + font, |
| 163 | - .draw_text(font, scheme.foreground, text_x, text_y, &display_title); | 163 | + scheme.foreground, |
| 164 | + text_x, | ||
| 165 | + text_y, | ||
| 166 | + &display_title, | ||
| 167 | + ); | ||
| 164 | 168 | ||
| 165 | if is_focused { | 169 | if is_focused { |
| 166 | let underline_height = 3; | 170 | let underline_height = 3; |
| 167 | let underline_y = self.height as i16 - underline_height; | 171 | let underline_y = self.height as i16 - underline_height; |
| 168 | 172 | ||
| 169 | unsafe { | 173 | unsafe { |
| 170 | - let gc = | 174 | + let gc = x11::xlib::XCreateGC( |
| 171 | - x11::xlib::XCreateGC(self.display, self.surface.pixmap(), 0, std::ptr::null_mut()); | 175 | + self.display, |
| 176 | + self.surface.pixmap(), | ||
| 177 | + 0, | ||
| 178 | + std::ptr::null_mut(), | ||
| 179 | + ); | ||
| 172 | x11::xlib::XSetForeground(self.display, gc, scheme.underline as u64); | 180 | x11::xlib::XSetForeground(self.display, gc, scheme.underline as u64); |
| 173 | x11::xlib::XFillRectangle( | 181 | x11::xlib::XFillRectangle( |
| 174 | self.display, | 182 | self.display, |