lib: add get_tree, useful for testing

This commit is contained in:
Skia 2024-11-04 17:58:24 +01:00
parent ab32878de5
commit ffc73fd832

View file

@ -21,6 +21,7 @@ const RUN_COMMAND: u32 = 0;
const GET_WORKSPACES: u32 = 1; const GET_WORKSPACES: u32 = 1;
// const SUBSCRIBE: u32 = 2; // const SUBSCRIBE: u32 = 2;
const GET_OUTPUTS: u32 = 3; const GET_OUTPUTS: u32 = 3;
const GET_TREE: u32 = 4;
pub struct SwaySome { pub struct SwaySome {
socket: Cell<Option<UnixStream>>, socket: Cell<Option<UnixStream>>,
@ -171,6 +172,17 @@ impl SwaySome {
}; };
} }
/*
* Only used in tests
*/
pub fn get_tree(&self) -> serde_json::Value {
self.send_msg(GET_TREE, "");
match self.read_msg() {
Ok(msg) => serde_json::from_str(&msg).expect("Failed to parse JSON for get_tree"),
Err(_) => panic!("Unable to get current workspace"),
}
}
fn get_outputs(&self) -> Vec<Output> { fn get_outputs(&self) -> Vec<Output> {
self.send_msg(GET_OUTPUTS, ""); self.send_msg(GET_OUTPUTS, "");
let o = match self.read_msg() { let o = match self.read_msg() {