extern crate rwmstatus;
use rwmstatus::*;
extern crate x11;
use std::ffi::CString;
use x11::xlib::{Display, XDefaultRootWindow, XOpenDisplay, XStoreName, XSync};
mod config;
fn main() {
let display: *mut Display;
unsafe {
display = XOpenDisplay(std::ptr::null());
}
if display.is_null() {
eprintln!("rwmstatus: cannot open display.");
std::process::exit(1);
}
let rwmstatus = RwmStatus::new(&config::TZS[..]);
let mut stats = vec![];
loop {
if let Some(temps) = rwmstatus.get_temperatures() {
stats.push(format!("T:{}", temps));
}
let avgs = rwmstatus.get_load_avgs();
stats.push(format!("L:{}", avgs));
if let Some(batts) = rwmstatus.get_batteries() {
stats.push(format!("B:{}", batts));
}
let times = rwmstatus.get_times();
stats.push(times);
let status = CString::new(stats.join(" ")).expect("Failed to create status CString.");
unsafe {
XStoreName(display, XDefaultRootWindow(display), status.as_ptr());
XSync(display, false as i32);
}
std::thread::sleep(std::time::Duration::from_secs(60));
stats.clear();
}
}