extern crate xcb; extern crate mpd; extern crate simple_signal; extern crate freetype; extern crate fontconfig_sys; mod sensors; mod config; mod ui; mod widgets; use simple_signal::Signal; use std::env; use std::process; use std::sync::mpsc; use std::thread; use std::time; use ui::x11; use widgets::Message; fn main() { let config_path = env::args().nth(1).unwrap_or("./panel.toml".to_string()); let cfg = config::load(&config_path); if let Some(conn) = x11::Connection::new() { let (tx, rx) = mpsc::channel(); { let tx = tx.clone(); simple_signal::set_handler(&[Signal::Int, Signal::Term], move |_signals| { tx.send(Message::Quit).expect("Failed to send quit"); }); } { let tx = tx.clone(); let conn = conn.clone_connection(); thread::spawn(move || { loop { match conn.wait_for_event() { Some(event) => { let message = Message::XcbEvent(event); tx.send(message).expect("Failed to send xcb event"); }, None => { break; } } } }); } let mut panel = ui::panel::Panel::new(conn, &cfg); let left_widgets = vec![ widgets::bspwm(tx.clone(), panel.make_draw_context()), widgets::spacer(panel.make_draw_context(), 4, 0x6666, 0x6666, 0x6666, 0xFFFF), widgets::title(panel.conn.clone(), panel.make_draw_context()) ]; let mut right_widgets = vec![ widgets::mpd(tx.clone(), panel.make_draw_context()), widgets::sensors(panel.make_draw_context(), &cfg), widgets::tray(tx.clone(), panel.conn.clone(), panel.window) ]; right_widgets.reverse(); for widget in left_widgets { panel.add_left_widget(widget); } for widget in right_widgets { panel.add_right_widget(widget); } panel.create(); { let tx = tx.clone(); thread::spawn(move || { loop { tx.send(Message::Update).expect("Failed to send update"); thread::sleep(time::Duration::from_secs(1)); } }); } loop { let event = rx.recv(); if panel.handle_event(event.unwrap()) { println!("Exiting"); break; } } } process::exit(0); }