From b39b51ad5852319f1a9ae4589572e240c2c8f98a Mon Sep 17 00:00:00 2001 From: Nabos Date: Wed, 3 Aug 2022 15:59:41 +0200 Subject: [PATCH 1/4] Added a rearrange workspaces feature --- src/main.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index c37e600..90510b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,9 @@ enum Command { #[clap(about = "Move the focused container to the previous output")] PrevOutput, + + #[clap(about = "Rearrange already opened workspaces")] + RearrangeWorkspaces, } #[derive(Args, Debug)] @@ -151,7 +154,7 @@ fn check_success(stream: &UnixStream) { }; } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] struct Output { name: String, #[serde(default)] @@ -170,7 +173,7 @@ fn get_outputs(stream: &UnixStream) -> Vec { outputs } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] struct Workspace { num: u32, output: String, @@ -292,11 +295,30 @@ fn init_workspaces(stream: &UnixStream, workspace_name: &String) { for output in outputs.iter().filter(|x| x.active).rev() { let mut cmd = cmd_prefix.clone(); cmd.push_str(output.name.as_str()); + println!("{:?}", cmd.clone()); send_command(stream, &cmd); 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() { let cli = Cli::parse(); let stream = get_stream(); @@ -320,5 +342,8 @@ fn main() { Command::PrevOutput => { move_container_to_prev_output(&stream); } + Command::RearrangeWorkspaces => { + rearrange_workspaces(&stream); + } } } From 6fe7ca7bc3ebca3c172b763650855b2e681c14e8 Mon Sep 17 00:00:00 2001 From: Nabos Date: Fri, 5 Aug 2022 12:56:00 +0200 Subject: [PATCH 2/4] Check for screen number --- src/main.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 90510b5..1c2c75d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ const GET_OUTPUTS: u32 = 3; #[clap(propagate_version = true)] struct Cli { #[clap(subcommand)] - command: Command + command: Command, } #[derive(Subcommand, Debug)] @@ -54,19 +54,19 @@ enum Command { #[derive(Args, Debug)] struct InitAction { #[clap(value_name = "index", help = "The index to initialize with")] - name: String + name: String, } #[derive(Args, Debug)] struct FocusAction { #[clap(value_name = "index", help = "The index to focus on")] - name: String + name: String, } #[derive(Args, Debug)] struct MoveAction { #[clap(value_name = "index", help = "The index to move the container to")] - name: String + name: String, } fn get_stream() -> UnixStream { @@ -313,9 +313,11 @@ fn rearrange_workspaces(stream: &UnixStream) { 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); + if output_index < outputs.len() { + let mut move_cmd = move_cmd_prefix.clone(); + move_cmd.push_str(&outputs[output_index].name); + send_command(stream, &move_cmd); + } } } From a0dc360e376223e54a9bb23f1f2ea78b5d80d820 Mon Sep 17 00:00:00 2001 From: Nabos Date: Fri, 23 Dec 2022 09:10:58 +0100 Subject: [PATCH 3/4] Removed debug print --- src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 1c2c75d..467ef19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -295,7 +295,6 @@ fn init_workspaces(stream: &UnixStream, workspace_name: &String) { for output in outputs.iter().filter(|x| x.active).rev() { let mut cmd = cmd_prefix.clone(); cmd.push_str(output.name.as_str()); - println!("{:?}", cmd.clone()); send_command(stream, &cmd); focus_to_workspace(stream, workspace_name); } From 1334bde4bd23df2c47a6b4506221f201e1ac0c39 Mon Sep 17 00:00:00 2001 From: Nabos Date: Fri, 23 Dec 2022 09:25:13 +0100 Subject: [PATCH 4/4] Updated Readme --- README.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index eb3179c..94247b5 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,18 @@ bindsym $mod+Shift+8 exec "swaysome move 8" bindsym $mod+Shift+9 exec "swaysome move 9" bindsym $mod+Shift+0 exec "swaysome move 0" +# Focus workspace groups +bindcode --to-code $mod+Ctrl+1 exec "swaysome focus-group 1" +bindcode --to-code $mod+Ctrl+2 exec "swaysome focus-group 2" +bindcode --to-code $mod+Ctrl+3 exec "swaysome focus-group 3" +bindcode --to-code $mod+Ctrl+4 exec "swaysome focus-group 4" +bindcode --to-code $mod+Ctrl+5 exec "swaysome focus-group 5" +bindcode --to-code $mod+Ctrl+6 exec "swaysome focus-group 6" +bindcode --to-code $mod+Ctrl+7 exec "swaysome focus-group 7" +bindcode --to-code $mod+Ctrl+8 exec "swaysome focus-group 8" +bindcode --to-code $mod+Ctrl+9 exec "swaysome focus-group 9" +bindcode --to-code $mod+Ctrl+0 exec "swaysome focus-group 0" + # Move focused container to next output bindsym $mod+o exec "swaysome next_output" @@ -89,10 +101,14 @@ as usual. ## Exhaustive swaysome commands list -* `move [name]`: move the focused container to `[name]` -* `next_output`: move the focused container to the next output -* `prev_output`: move the focused container to the previous output -* `focus [name]`: change focus to `[name]` -* `focus_all_outputs [name]`: change all outputs focus to `[name]` +* `move [name]`: move the focused container to `[name]` on the same group +* `next-output`: move the focused container to the next output +* `prev-output`: move the focused container to the previous output +* `focus [name]`: change focus to `[name]` on the same group +* `focus-all-outputs [name]`: change all outputs focus to `[name]` +* `focus-group [id]`: change focus to group `[id]` +* `next-group`: change focus to the next workspace group +* `previous-group`: change focus to the previous workspace group * `init [name]`: cycle all outputs to create a default workspace with name `[name]` +* `rearrange-workspaces` Rearrange already opened workspaces to the correct outputs