mirror of
https://gitlab.com/hyask/swaysome.git
synced 2025-12-10 07:44:43 +01:00
Add 'focus_all_outputs_to_workspace'
This commit is contained in:
parent
50ed528df7
commit
7af07db165
1 changed files with 36 additions and 0 deletions
36
src/main.rs
36
src/main.rs
|
|
@ -129,6 +129,17 @@ fn get_current_output_index(stream: &UnixStream) -> String {
|
||||||
format!("{}", focused_output_index)
|
format!("{}", focused_output_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_current_output_name(stream: &UnixStream) -> String {
|
||||||
|
let outputs = get_outputs(&stream);
|
||||||
|
|
||||||
|
let focused_output_index = match outputs.iter().find(|x| x["focused"] == serde_json::Value::Bool(true)) {
|
||||||
|
Some(i) => i["name"].as_str().unwrap(),
|
||||||
|
None => panic!("WTF! No focused output???"),
|
||||||
|
};
|
||||||
|
|
||||||
|
format!("{}", focused_output_index)
|
||||||
|
}
|
||||||
|
|
||||||
fn move_container_to_workspace(stream: &UnixStream, workspace_name: &String) {
|
fn move_container_to_workspace(stream: &UnixStream, workspace_name: &String) {
|
||||||
let mut cmd: String = "move container to workspace ".to_string();
|
let mut cmd: String = "move container to workspace ".to_string();
|
||||||
let output = get_current_output_index(stream);
|
let output = get_current_output_index(stream);
|
||||||
|
|
@ -149,6 +160,30 @@ fn focus_to_workspace(stream: &UnixStream, workspace_name: &String) {
|
||||||
check_success(&stream);
|
check_success(&stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn focus_all_outputs_to_workspace(stream: &UnixStream, workspace_name: &String) {
|
||||||
|
let current_output = get_current_output_name(stream);
|
||||||
|
println!("Current output name: {}", current_output);
|
||||||
|
|
||||||
|
// Iterate on all outputs to focus on the given workspace
|
||||||
|
let outputs = get_outputs(&stream);
|
||||||
|
for (i, output) in outputs.iter().enumerate() {
|
||||||
|
let mut cmd: String = "focus output ".to_string();
|
||||||
|
cmd.push_str(&output["name"].as_str().unwrap());
|
||||||
|
println!("Sending command: '{}'", &cmd);
|
||||||
|
send_msg(&stream, RUN_COMMAND, &cmd);
|
||||||
|
check_success(&stream);
|
||||||
|
|
||||||
|
focus_to_workspace(&stream, &workspace_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get back to currently focused output
|
||||||
|
let mut cmd: String = "focus output ".to_string();
|
||||||
|
cmd.push_str(¤t_output);
|
||||||
|
println!("Sending command: '{}'", &cmd);
|
||||||
|
send_msg(&stream, RUN_COMMAND, &cmd);
|
||||||
|
check_success(&stream);
|
||||||
|
}
|
||||||
|
|
||||||
fn move_container_to_next_output(stream: &UnixStream) {
|
fn move_container_to_next_output(stream: &UnixStream) {
|
||||||
move_container_to_next_or_prev_output(&stream, false);
|
move_container_to_next_or_prev_output(&stream, false);
|
||||||
}
|
}
|
||||||
|
|
@ -214,6 +249,7 @@ fn main() {
|
||||||
"init" => init_workspaces(&stream),
|
"init" => init_workspaces(&stream),
|
||||||
"move" => move_container_to_workspace(&stream, &args[2]),
|
"move" => move_container_to_workspace(&stream, &args[2]),
|
||||||
"focus" => focus_to_workspace(&stream, &args[2]),
|
"focus" => focus_to_workspace(&stream, &args[2]),
|
||||||
|
"focus_all_outputs" => focus_all_outputs_to_workspace(&stream, &args[2]),
|
||||||
"next_output" => move_container_to_next_output(&stream),
|
"next_output" => move_container_to_next_output(&stream),
|
||||||
"prev_output" => move_container_to_prev_output(&stream),
|
"prev_output" => move_container_to_prev_output(&stream),
|
||||||
_ => {},
|
_ => {},
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue