use std::process::Output;
pub mod desktop;
pub mod utils;
mod state;
mod transformation;
mod window;
pub use state::Action;
pub use state::Property;
pub use state::State;
pub use transformation::Transformation;
pub use window::Window;
use utils::wmctrl;
pub fn help() -> Output {
wmctrl("-h")
}
pub fn get_windows() -> Vec<Window> {
let output_table = String::from_utf8(wmctrl("-l -G").stdout).unwrap();
let mut windows = Vec::new();
for row in output_table.lines() {
windows.push(parse_row(row))
}
windows
}
pub fn show_wm_information() -> Output {
wmctrl("-m")
}
fn parse_row(row: &str) -> Window {
let columns = row
.split(' ')
.filter(|e| !e.is_empty())
.collect::<Vec<&str>>();
let (x, y, w, h) = (
columns[2].parse::<u16>().unwrap(),
columns[3].parse::<u16>().unwrap(),
columns[4].parse::<u16>().unwrap(),
columns[5].parse::<u16>().unwrap(),
);
let t = Transformation::new(x, y, w, h);
let (id, desktop, client_machine) = (
columns[0].to_owned(),
columns[1].to_owned(),
columns[6].to_owned(),
);
let mut title = String::from("");
let title_substrings: Vec<&str> = columns[7..].to_vec();
title_substrings
.into_iter()
.for_each(|e| title += format!("{} ", e).as_str());
title.pop();
Window::new(id, desktop, client_machine, title, t)
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}