diff --git a/src/main.rs b/src/main.rs index 84a3240..0b25a53 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,13 +100,14 @@ fn check_success(stream: &UnixStream) { }; } -fn get_outputs(stream: &UnixStream) -> Vec { +fn get_active_outputs(stream: &UnixStream) -> Vec { send_msg(&stream, GET_OUTPUTS, ""); let o = match read_msg(&stream) { Ok(msg) => msg, Err(_) => panic!("Unable to get outputs"), }; - serde_json::from_str(&o).unwrap() + let outputs: Vec = serde_json::from_str(&o).unwrap(); + outputs.into_iter().filter(|x| x["active"] == serde_json::Value::Bool(true)).collect() } fn get_workspaces(stream: &UnixStream) -> Vec { @@ -119,7 +120,7 @@ fn get_workspaces(stream: &UnixStream) -> Vec { } fn get_current_output_name(stream: &UnixStream) -> String { - let outputs = get_outputs(&stream); + let outputs = get_active_outputs(&stream); let focused_output_index = match outputs.iter().position(|x| x["focused"] == serde_json::Value::Bool(true)) { Some(i) => i, @@ -158,7 +159,7 @@ fn move_container_to_prev_output(stream: &UnixStream) { } fn move_container_to_next_or_prev_output(stream: &UnixStream, go_to_prev: bool) { - let outputs = get_outputs(&stream); + let outputs = get_active_outputs(&stream); let focused_output_index = match outputs.iter().position(|x| x["focused"] == serde_json::Value::Bool(true)) { Some(i) => i, None => panic!("WTF! No focused output???"), @@ -190,7 +191,7 @@ fn move_container_to_next_or_prev_output(stream: &UnixStream, go_to_prev: bool) } fn init_workspaces(stream: &UnixStream) { - let outputs = get_outputs(&stream); + let outputs = get_active_outputs(&stream); let cmd_prefix: String = "focus output ".to_string(); for output in outputs.iter().rev() {