From 3ccf1d6edaf90755bc6e0b4e80cd215cd01ccf5d Mon Sep 17 00:00:00 2001 From: Skia Date: Tue, 14 Nov 2023 18:28:16 +0100 Subject: [PATCH] Add WorkspaceGroup{Next,Prev}Output command --- README.md | 5 +++++ src/main.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/README.md b/README.md index 0b13d5c..f9a221d 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,11 @@ bindcode $mod+o exec "swaysome next-output" # Move focused container to previous output bindcode $mod+Shift+o exec "swaysome prev-output" +# Move focused workspace group to next output +bindcode $mod+Alt+o exec "swaysome workspace-group-next-output" +# Move focused workspace group to previous output +bindcode $mod+Alt+Shift+o exec "swaysome workspace-group-prev-output" + # Init workspaces for every screen exec "swaysome init 1" ``` diff --git a/src/main.rs b/src/main.rs index 04f24aa..4bb5381 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,6 +63,12 @@ enum Command { #[clap(about = "Move the focused container to the previous output")] PrevOutput, + #[clap(about = "Move the focused workspace group to the next output")] + WorkspaceGroupNextOutput, + + #[clap(about = "Move the focused workspace group to the previous output")] + WorkspaceGroupPrevOutput, + #[clap(about = "Move the focused container to the next group")] NextGroup, @@ -602,6 +608,37 @@ impl SwaySome { self.send_command(&cmd); } + fn move_workspace_group_to_next_output(&self) { + self.move_workspace_group_to_next_or_prev_output(false); + } + + fn move_workspace_group_to_prev_output(&self) { + self.move_workspace_group_to_next_or_prev_output(true); + } + + fn move_workspace_group_to_next_or_prev_output(&self, go_to_prev: bool) { + let focused_output_index = self.get_current_output_index(); + + let target_output = if go_to_prev { + &self.outputs[(focused_output_index + self.outputs.len() - 1) % self.outputs.len()] + } else { + &self.outputs[(focused_output_index + 1) % self.outputs.len()] + }; + let current_workspace = self.get_current_workspace_index(); + let current_group_index = (current_workspace / MAX_GROUP_WS) as usize; + for workspace in self.get_workspaces() { + let ws_index = workspace.num / MAX_GROUP_WS; + if ws_index == current_group_index { + let cmd: String = format!("workspace number {}", workspace.num); + self.send_command(&cmd); + let cmd: String = format!("move workspace to {}", target_output.name); + self.send_command(&cmd); + } + } + let cmd: String = format!("workspace number {}", current_workspace); + self.send_command(&cmd); + } + fn focus_container_to_next_group(&self) { self.focus_container_to_next_or_prev_group(false); } @@ -686,6 +723,12 @@ fn main() { Command::PrevOutput => { swaysome.move_container_to_prev_output(); } + Command::WorkspaceGroupNextOutput => { + swaysome.move_workspace_group_to_next_output(); + } + Command::WorkspaceGroupPrevOutput => { + swaysome.move_workspace_group_to_prev_output(); + } Command::NextGroup => { swaysome.focus_container_to_next_group(); }