Added a rearrange workspaces feature
This commit is contained in:
parent
90e1e46fb2
commit
b39b51ad58
1 changed files with 27 additions and 2 deletions
29
src/main.rs
29
src/main.rs
|
|
@ -46,6 +46,9 @@ enum Command {
|
||||||
|
|
||||||
#[clap(about = "Move the focused container to the previous output")]
|
#[clap(about = "Move the focused container to the previous output")]
|
||||||
PrevOutput,
|
PrevOutput,
|
||||||
|
|
||||||
|
#[clap(about = "Rearrange already opened workspaces")]
|
||||||
|
RearrangeWorkspaces,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Args, Debug)]
|
#[derive(Args, Debug)]
|
||||||
|
|
@ -151,7 +154,7 @@ fn check_success(stream: &UnixStream) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct Output {
|
struct Output {
|
||||||
name: String,
|
name: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
|
@ -170,7 +173,7 @@ fn get_outputs(stream: &UnixStream) -> Vec<Output> {
|
||||||
outputs
|
outputs
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct Workspace {
|
struct Workspace {
|
||||||
num: u32,
|
num: u32,
|
||||||
output: String,
|
output: String,
|
||||||
|
|
@ -292,11 +295,30 @@ fn init_workspaces(stream: &UnixStream, workspace_name: &String) {
|
||||||
for output in outputs.iter().filter(|x| x.active).rev() {
|
for output in outputs.iter().filter(|x| x.active).rev() {
|
||||||
let mut cmd = cmd_prefix.clone();
|
let mut cmd = cmd_prefix.clone();
|
||||||
cmd.push_str(output.name.as_str());
|
cmd.push_str(output.name.as_str());
|
||||||
|
println!("{:?}", cmd.clone());
|
||||||
send_command(stream, &cmd);
|
send_command(stream, &cmd);
|
||||||
focus_to_workspace(stream, workspace_name);
|
focus_to_workspace(stream, workspace_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rearrange_workspaces(stream: &UnixStream) {
|
||||||
|
let outputs = get_outputs(stream);
|
||||||
|
let workspaces = get_workspaces(stream);
|
||||||
|
|
||||||
|
let focus_cmd_prefix: String = "workspace number ".to_string();
|
||||||
|
let move_cmd_prefix: String = "move workspace to ".to_string();
|
||||||
|
for workspace in workspaces.iter() {
|
||||||
|
let mut focus_cmd = focus_cmd_prefix.clone();
|
||||||
|
focus_cmd.push_str(&workspace.num.to_string());
|
||||||
|
send_command(stream, &focus_cmd);
|
||||||
|
|
||||||
|
let output_index = (workspace.num / 10) as usize;
|
||||||
|
let mut move_cmd = move_cmd_prefix.clone();
|
||||||
|
move_cmd.push_str(&outputs[output_index].name);
|
||||||
|
send_command(stream, &move_cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
let stream = get_stream();
|
let stream = get_stream();
|
||||||
|
|
@ -320,5 +342,8 @@ fn main() {
|
||||||
Command::PrevOutput => {
|
Command::PrevOutput => {
|
||||||
move_container_to_prev_output(&stream);
|
move_container_to_prev_output(&stream);
|
||||||
}
|
}
|
||||||
|
Command::RearrangeWorkspaces => {
|
||||||
|
rearrange_workspaces(&stream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue