mirror of
https://gitlab.com/hyask/swaysome.git
synced 2025-12-10 07:44:43 +01:00
Move 'get_outputs' to a separate function
This commit is contained in:
parent
38d685b252
commit
84820a07d0
1 changed files with 8 additions and 10 deletions
18
src/main.rs
18
src/main.rs
|
|
@ -146,20 +146,23 @@ fn check_success(stream: &UnixStream) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_current_output_name(stream: &UnixStream) -> String {
|
fn get_outputs(stream: &UnixStream) -> Vec<Output> {
|
||||||
send_msg(&stream, GET_OUTPUTS, "");
|
send_msg(&stream, GET_OUTPUTS, "");
|
||||||
let o = match read_msg(&stream) {
|
let o = match read_msg(&stream) {
|
||||||
Ok(msg) => msg,
|
Ok(msg) => msg,
|
||||||
Err(_) => panic!("Unable to get current workspace"),
|
Err(_) => panic!("Unable to get outputs"),
|
||||||
};
|
};
|
||||||
let outputs: Vec<Output> = serde_json::from_str(&o).unwrap();
|
serde_json::from_str(&o).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_current_output_name(stream: &UnixStream) -> String {
|
||||||
|
let outputs = get_outputs(&stream);
|
||||||
|
|
||||||
let focused_output_index = match outputs.iter().position(|x| x.focused) {
|
let focused_output_index = match outputs.iter().position(|x| x.focused) {
|
||||||
Some(i) => i,
|
Some(i) => i,
|
||||||
None => panic!("WTF! No focused output???"),
|
None => panic!("WTF! No focused output???"),
|
||||||
};
|
};
|
||||||
|
|
||||||
// outputs[focused_output_index].name.clone()
|
|
||||||
format!("{}", focused_output_index)
|
format!("{}", focused_output_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,12 +203,7 @@ fn focus_to_workspace(stream: &UnixStream, workspace_name: &String) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_workspaces(stream: &UnixStream) {
|
fn init_workspaces(stream: &UnixStream) {
|
||||||
send_msg(&stream, GET_OUTPUTS, "");
|
let outputs = get_outputs(&stream);
|
||||||
let o = match read_msg(&stream) {
|
|
||||||
Ok(msg) => msg,
|
|
||||||
Err(_) => panic!("Unable to get outputs"),
|
|
||||||
};
|
|
||||||
let outputs: Vec<Output> = serde_json::from_str(&o).unwrap();
|
|
||||||
|
|
||||||
let cmd_prefix: String = "focus output ".to_string();
|
let cmd_prefix: String = "focus output ".to_string();
|
||||||
for output in outputs.iter().rev() {
|
for output in outputs.iter().rev() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue