|
@@ -1,6 +1,10 @@
|
|
|
+use mpd;
|
|
|
use xcb;
|
|
|
+use ui::ext;
|
|
|
+use ui::ext::ConnectionExt;
|
|
|
use ui::font;
|
|
|
|
|
|
+use std::cmp;
|
|
|
use std::rc::Rc;
|
|
|
use std::sync::Arc;
|
|
|
use std::sync::mpsc;
|
|
@@ -12,6 +16,7 @@ pub enum Message {
|
|
|
Update,
|
|
|
Quit,
|
|
|
BspwmEvent(String),
|
|
|
+ MpdEvent(mpd::status::State, String, String),
|
|
|
XcbEvent(xcb::GenericEvent)
|
|
|
}
|
|
|
|
|
@@ -27,14 +32,16 @@ pub trait Widget {
|
|
|
|
|
|
pub struct DrawContext {
|
|
|
conn: Arc<xcb::Connection>,
|
|
|
+ window: xcb::Window,
|
|
|
picture: xcb::render::Picture,
|
|
|
pen: xcb::render::Picture,
|
|
|
fonts: Rc<font::FontLoader>,
|
|
|
+ pen_color: xcb::render::Color,
|
|
|
bg_color: xcb::render::Color
|
|
|
}
|
|
|
|
|
|
impl DrawContext {
|
|
|
- pub fn new(conn: Arc<xcb::Connection>, picture: xcb::render::Picture, fonts: Rc<font::FontLoader>) -> DrawContext {
|
|
|
+ pub fn new(conn: Arc<xcb::Connection>, window: xcb::Window, picture: xcb::render::Picture, fonts: Rc<font::FontLoader>) -> DrawContext {
|
|
|
let pen = conn.generate_id();
|
|
|
let color = xcb::render::Color::new(0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
|
|
|
xcb::render::create_solid_fill(
|
|
@@ -45,9 +52,11 @@ impl DrawContext {
|
|
|
|
|
|
DrawContext {
|
|
|
conn: conn,
|
|
|
+ window: window,
|
|
|
picture: picture,
|
|
|
pen: pen,
|
|
|
fonts: fonts,
|
|
|
+ pen_color: color,
|
|
|
bg_color: xcb::render::Color::new(0, 0, 0, 0xFFFF)
|
|
|
}
|
|
|
}
|
|
@@ -79,4 +88,39 @@ impl DrawContext {
|
|
|
text.render(&self.conn, self.pen, self.picture, x, baseline as u16);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ pub fn draw_text_until(&self, name: &str, x: u16, width: u16) {
|
|
|
+ if !name.is_empty() {
|
|
|
+ let text = self.fonts.create_renderable_text(name);
|
|
|
+ let baseline = 20 - self.fonts.default_offset(20);
|
|
|
+
|
|
|
+ // weird things happen if you draw too little
|
|
|
+ let width = cmp::min(width, text.width);
|
|
|
+
|
|
|
+ let pixmap = self.conn.generate_id();
|
|
|
+ xcb::create_pixmap(&self.conn, 32, pixmap, self.window, x + width, 1);
|
|
|
+ let pen = self.conn.generate_id();
|
|
|
+ xcb::render::create_picture(
|
|
|
+ &self.conn,
|
|
|
+ pen,
|
|
|
+ pixmap,
|
|
|
+ self.conn.get_pict_format(ext::PictFormat::ARGB32),
|
|
|
+ &[]
|
|
|
+ );
|
|
|
+ xcb::render::fill_rectangles(
|
|
|
+ &self.conn,
|
|
|
+ xcb::render::PICT_OP_SRC as u8,
|
|
|
+ pen,
|
|
|
+ self.pen_color,
|
|
|
+ &[xcb::Rectangle::new(x as i16, 0, width, 1)]
|
|
|
+ );
|
|
|
+ text.render(&self.conn, pen, self.picture, x, baseline as u16);
|
|
|
+ xcb::render::free_picture(&self.conn, pen);
|
|
|
+ xcb::free_pixmap(&self.conn, pixmap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn flush(&self) {
|
|
|
+ self.conn.flush();
|
|
|
+ }
|
|
|
}
|