mod.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. use std::sync::mpsc;
  2. use xcb;
  3. use mpd;
  4. use config::Config;
  5. use ui::context::Context;
  6. use ui::x11;
  7. mod title;
  8. mod tray;
  9. mod sensors;
  10. mod wm;
  11. mod spacer;
  12. mod music;
  13. pub use self::title::title;
  14. pub use self::tray::tray;
  15. pub use self::sensors::sensors;
  16. pub use self::spacer::spacer;
  17. pub use self::music::mpd;
  18. pub use self::wm::bspwm;
  19. pub type MessageSender = mpsc::Sender<Message>;
  20. pub enum Message {
  21. Update,
  22. Quit,
  23. MousePress(u16),
  24. BspwmEvent(String),
  25. MpdEvent(mpd::status::State, Option<mpd::song::Song>),
  26. XcbEvent(xcb::GenericEvent)
  27. }
  28. pub enum Update {
  29. Nothing,
  30. Rerender,
  31. Relayout,
  32. Quit
  33. }
  34. pub trait Widget {
  35. fn init(&mut self) {}
  36. fn render(&mut self, x: u16, width: u16);
  37. fn width(&mut self) -> u16;
  38. fn fit_width(&self) -> bool {
  39. false
  40. }
  41. fn handle_event(&mut self, _event: &Message) -> Update {
  42. Update::Nothing
  43. }
  44. fn finish(&mut self) {}
  45. }
  46. #[derive(Clone)]
  47. pub struct WidgetParams {
  48. pub id: String,
  49. pub context: Context,
  50. pub tx: MessageSender,
  51. pub config: Config
  52. }
  53. impl WidgetParams {
  54. fn conn(&self) -> x11::Connection {
  55. self.context.conn.clone()
  56. }
  57. fn window(&self) -> xcb::Window {
  58. self.context.window
  59. }
  60. }
  61. pub type WidgetConstructor = fn(WidgetParams) -> Box<Widget>;