diff --git a/README.md b/README.md index de4469b..4bf0d47 100644 --- a/README.md +++ b/README.md @@ -31,66 +31,98 @@ to check that everything works before fixing your `$PATH` issue. Then create the file (and the directory if needed) `~/.config/sway/config.d/swaysome.conf` and paste this inside: ``` # Change focus between workspaces -unbindsym $mod+1 -unbindsym $mod+2 -unbindsym $mod+3 -unbindsym $mod+4 -unbindsym $mod+5 -unbindsym $mod+6 -unbindsym $mod+7 -unbindsym $mod+8 -unbindsym $mod+9 -unbindsym $mod+0 -bindsym $mod+1 exec "swaysome focus 1" -bindsym $mod+2 exec "swaysome focus 2" -bindsym $mod+3 exec "swaysome focus 3" -bindsym $mod+4 exec "swaysome focus 4" -bindsym $mod+5 exec "swaysome focus 5" -bindsym $mod+6 exec "swaysome focus 6" -bindsym $mod+7 exec "swaysome focus 7" -bindsym $mod+8 exec "swaysome focus 8" -bindsym $mod+9 exec "swaysome focus 9" -bindsym $mod+0 exec "swaysome focus 0" +unbindcode $mod+10 +unbindcode $mod+11 +unbindcode $mod+12 +unbindcode $mod+13 +unbindcode $mod+14 +unbindcode $mod+15 +unbindcode $mod+16 +unbindcode $mod+17 +unbindcode $mod+18 +unbindcode $mod+19 +bindcode $mod+10 exec "swaysome focus 1" +bindcode $mod+11 exec "swaysome focus 2" +bindcode $mod+12 exec "swaysome focus 3" +bindcode $mod+13 exec "swaysome focus 4" +bindcode $mod+14 exec "swaysome focus 5" +bindcode $mod+15 exec "swaysome focus 6" +bindcode $mod+16 exec "swaysome focus 7" +bindcode $mod+17 exec "swaysome focus 8" +bindcode $mod+18 exec "swaysome focus 9" +bindcode $mod+19 exec "swaysome focus 0" # Move containers between workspaces -unbindsym $mod+Shift+1 -unbindsym $mod+Shift+2 -unbindsym $mod+Shift+3 -unbindsym $mod+Shift+4 -unbindsym $mod+Shift+5 -unbindsym $mod+Shift+6 -unbindsym $mod+Shift+7 -unbindsym $mod+Shift+8 -unbindsym $mod+Shift+9 -unbindsym $mod+Shift+0 -bindsym $mod+Shift+1 exec "swaysome move 1" -bindsym $mod+Shift+2 exec "swaysome move 2" -bindsym $mod+Shift+3 exec "swaysome move 3" -bindsym $mod+Shift+4 exec "swaysome move 4" -bindsym $mod+Shift+5 exec "swaysome move 5" -bindsym $mod+Shift+6 exec "swaysome move 6" -bindsym $mod+Shift+7 exec "swaysome move 7" -bindsym $mod+Shift+8 exec "swaysome move 8" -bindsym $mod+Shift+9 exec "swaysome move 9" -bindsym $mod+Shift+0 exec "swaysome move 0" +unbindcode $mod+Shift+10 +unbindcode $mod+Shift+11 +unbindcode $mod+Shift+12 +unbindcode $mod+Shift+13 +unbindcode $mod+Shift+14 +unbindcode $mod+Shift+15 +unbindcode $mod+Shift+16 +unbindcode $mod+Shift+17 +unbindcode $mod+Shift+18 +unbindcode $mod+Shift+19 +bindcode $mod+Shift+10 exec "swaysome move 1" +bindcode $mod+Shift+11 exec "swaysome move 2" +bindcode $mod+Shift+12 exec "swaysome move 3" +bindcode $mod+Shift+13 exec "swaysome move 4" +bindcode $mod+Shift+14 exec "swaysome move 5" +bindcode $mod+Shift+15 exec "swaysome move 6" +bindcode $mod+Shift+16 exec "swaysome move 7" +bindcode $mod+Shift+17 exec "swaysome move 8" +bindcode $mod+Shift+18 exec "swaysome move 9" +bindcode $mod+Shift+19 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" +unbindcode $mod+Ctrl+10 +unbindcode $mod+Ctrl+11 +unbindcode $mod+Ctrl+12 +unbindcode $mod+Ctrl+13 +unbindcode $mod+Ctrl+14 +unbindcode $mod+Ctrl+15 +unbindcode $mod+Ctrl+16 +unbindcode $mod+Ctrl+17 +unbindcode $mod+Ctrl+18 +unbindcode $mod+Ctrl+19 +bindcode $mod+Ctrl+10 exec "swaysome focus-group 1" +bindcode $mod+Ctrl+11 exec "swaysome focus-group 2" +bindcode $mod+Ctrl+12 exec "swaysome focus-group 3" +bindcode $mod+Ctrl+13 exec "swaysome focus-group 4" +bindcode $mod+Ctrl+14 exec "swaysome focus-group 5" +bindcode $mod+Ctrl+15 exec "swaysome focus-group 6" +bindcode $mod+Ctrl+16 exec "swaysome focus-group 7" +bindcode $mod+Ctrl+17 exec "swaysome focus-group 8" +bindcode $mod+Ctrl+18 exec "swaysome focus-group 9" +bindcode $mod+Ctrl+19 exec "swaysome focus-group 0" + +# Move containers to other workspace groups +unbindcode $mod+Ctrl+Shift+10 +unbindcode $mod+Ctrl+Shift+11 +unbindcode $mod+Ctrl+Shift+12 +unbindcode $mod+Ctrl+Shift+13 +unbindcode $mod+Ctrl+Shift+14 +unbindcode $mod+Ctrl+Shift+15 +unbindcode $mod+Ctrl+Shift+16 +unbindcode $mod+Ctrl+Shift+17 +unbindcode $mod+Ctrl+Shift+18 +unbindcode $mod+Ctrl+Shift+19 +bindcode $mod+Ctrl+Shift+10 exec "swaysome move-to-group 1" +bindcode $mod+Ctrl+Shift+11 exec "swaysome move-to-group 2" +bindcode $mod+Ctrl+Shift+12 exec "swaysome move-to-group 3" +bindcode $mod+Ctrl+Shift+13 exec "swaysome move-to-group 4" +bindcode $mod+Ctrl+Shift+14 exec "swaysome move-to-group 5" +bindcode $mod+Ctrl+Shift+15 exec "swaysome move-to-group 6" +bindcode $mod+Ctrl+Shift+16 exec "swaysome move-to-group 7" +bindcode $mod+Ctrl+Shift+17 exec "swaysome move-to-group 8" +bindcode $mod+Ctrl+Shift+18 exec "swaysome move-to-group 9" +bindcode $mod+Ctrl+Shift+19 exec "swaysome move-to-group 0" # Move focused container to next output -bindsym $mod+o exec "swaysome next-output" +bindcode $mod+o exec "swaysome next-output" # Move focused container to previous output -bindsym $mod+Shift+o exec "swaysome prev-output" +bindcode $mod+Shift+o exec "swaysome prev-output" # Init workspaces for every screen exec "swaysome init 1" @@ -113,6 +145,7 @@ as usual. ## Exhaustive swaysome commands list * `move [name]`: move the focused container to `[name]` on the same group +* `move-to-group [id]`: move the focused container to the same relative workspace on the `[id]` workspace 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 diff --git a/src/main.rs b/src/main.rs index 9929bcf..abef34a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,11 @@ enum Command { #[clap(about = "Move the focused container to another workspace on the same workspace group")] Move(MoveAction), + #[clap( + about = "Move the focused container to the same workspace index on another workspace group" + )] + MoveToGroup(MoveAction), + #[clap(about = "Focus to another workspace on the same workspace group")] Focus(FocusAction), @@ -238,16 +243,26 @@ fn move_container_to_workspace(stream: &UnixStream, workspace_index: usize) { } } +fn move_container_to_workspace_group(stream: &UnixStream, target_group: usize) { + let current_workspace_index = get_current_workspace(stream).num; + let current_workspace_index_relative = (current_workspace_index % 10) as usize; + move_container_to_workspace_absolute( + stream, + current_workspace_index_relative + target_group * 10, + ); +} + fn move_container_to_workspace_absolute(stream: &UnixStream, workspace_index: usize) { - let output_index = (workspace_index / 10) as usize; + let group_index = (workspace_index / 10) as usize; let outputs = get_outputs(stream); let workspaces = get_workspaces(stream); + let full_ws_name = format!("{}{}", group_index, workspace_index % 10); // If the workspace already exists match workspaces.iter().find(|w| w.num == workspace_index) { Some(_) => { let mut focus_cmd: String = "move container to workspace number ".to_string(); - focus_cmd.push_str(&workspace_index.to_string()); + focus_cmd.push_str(&full_ws_name); send_command(stream, &focus_cmd); } None => { @@ -264,8 +279,8 @@ fn move_container_to_workspace_absolute(stream: &UnixStream, workspace_index: us ), None => { // Or if the targeted output is currently connected - if output_index < outputs.len() { - Some(output_index) + if group_index < outputs.len() { + Some(group_index) } else { None } @@ -273,46 +288,52 @@ fn move_container_to_workspace_absolute(stream: &UnixStream, workspace_index: us }; match target_screen_index { - // If we have to send it to another screen Some(target_screen_index) => { - let target_output = &outputs[target_screen_index - 1]; + let target_output = &outputs[target_screen_index]; let current_output_name = get_current_output_name(stream); - let mut focus_cmd: String = "focus output ".to_string(); - focus_cmd.push_str(&target_output.name); - send_command(stream, &focus_cmd); + if target_output.name == current_output_name { + let mut focus_cmd: String = "move container to workspace ".to_string(); + focus_cmd.push_str(&full_ws_name); + send_command(stream, &focus_cmd); + } else { + // If we have to send it to another screen + let mut focus_cmd: String = "focus output ".to_string(); + focus_cmd.push_str(&target_output.name); + send_command(stream, &focus_cmd); - let focused_workspace_index = get_current_workspace(stream).num; + let focused_workspace_index = get_current_workspace(stream).num; - let mut focus_cmd: String = "workspace ".to_string(); - focus_cmd.push_str(&workspace_index.to_string()); - send_command(stream, &focus_cmd); + let mut focus_cmd: String = "workspace ".to_string(); + focus_cmd.push_str(&full_ws_name); + send_command(stream, &focus_cmd); - let mut focus_cmd: String = "focus output ".to_string(); - focus_cmd.push_str(¤t_output_name); - send_command(stream, &focus_cmd); + let mut focus_cmd: String = "focus output ".to_string(); + focus_cmd.push_str(¤t_output_name); + send_command(stream, &focus_cmd); - let mut focus_cmd: String = "move container to workspace ".to_string(); - focus_cmd.push_str(&workspace_index.to_string()); - send_command(stream, &focus_cmd); + let mut focus_cmd: String = "move container to workspace ".to_string(); + focus_cmd.push_str(&full_ws_name); + send_command(stream, &focus_cmd); - let mut focus_cmd: String = "focus output ".to_string(); - focus_cmd.push_str(&target_output.name); - send_command(stream, &focus_cmd); + let mut focus_cmd: String = "focus output ".to_string(); + focus_cmd.push_str(&target_output.name); + send_command(stream, &focus_cmd); - let mut focus_cmd: String = "workspace ".to_string(); - focus_cmd.push_str(&focused_workspace_index.to_string()); - send_command(stream, &focus_cmd); + let mut focus_cmd: String = "workspace ".to_string(); + focus_cmd.push_str(&focused_workspace_index.to_string()); + send_command(stream, &focus_cmd); - let mut focus_cmd: String = "focus output ".to_string(); - focus_cmd.push_str(¤t_output_name); - send_command(stream, &focus_cmd); + let mut focus_cmd: String = "focus output ".to_string(); + focus_cmd.push_str(¤t_output_name); + send_command(stream, &focus_cmd); + } } None => { // Else, we send the container on the current output let mut focus_cmd: String = "move container to workspace ".to_string(); - focus_cmd.push_str(&workspace_index.to_string()); + focus_cmd.push_str(&full_ws_name); send_command(stream, &focus_cmd); } }; @@ -325,10 +346,8 @@ fn move_container_to_workspace_relative(stream: &UnixStream, workspace_index: us let focused_output_index = current_workspace_index / 10; let mut cmd: String = "move container to workspace number ".to_string(); - let full_ws_name = format!("{}{}", focused_output_index, workspace_index) - .parse::() - .unwrap(); - cmd.push_str(&full_ws_name.to_string()); + let full_ws_name = format!("{}{}", focused_output_index, workspace_index); + cmd.push_str(&full_ws_name); send_command(stream, &cmd); } @@ -398,10 +417,8 @@ fn focus_to_workspace_relative(stream: &UnixStream, workspace_index: usize) { let focused_output_index = current_workspace_index / 10; let mut cmd: String = "workspace number ".to_string(); - let full_ws_name = format!("{}{}", focused_output_index, &workspace_index) - .parse::() - .unwrap(); - cmd.push_str(&full_ws_name.to_string()); + let full_ws_name = format!("{}{}", focused_output_index, &workspace_index); + cmd.push_str(&full_ws_name); send_command(stream, &cmd); } @@ -410,17 +427,16 @@ fn focus_to_group(stream: &UnixStream, group_index: usize) { let workspaces = get_workspaces(stream); let current_workspace_index: usize = get_current_workspace(stream).num; - let contextual_target_workspace_index = - current_workspace_index - (current_workspace_index / 10) * 10; + let target_workspace_relative_index = current_workspace_index % 10; - let target_workspace_index = group_index * 10 + contextual_target_workspace_index; - println!("{target_workspace_index}"); + let target_workspace_index = group_index * 10 + target_workspace_relative_index; + let full_ws_name = format!("{}{}", group_index, target_workspace_relative_index); // If the workspace already exists match workspaces.iter().find(|w| w.num == target_workspace_index) { Some(_) => { let mut focus_cmd: String = "workspace number ".to_string(); - focus_cmd.push_str(&target_workspace_index.to_string()); + focus_cmd.push_str(&full_ws_name); send_command(stream, &focus_cmd); } None => { @@ -506,10 +522,12 @@ fn move_container_to_next_or_prev_output(stream: &UnixStream, go_to_prev: bool) .iter() .find(|x| x.output == target_output.name && x.visible) .unwrap(); + let group_index = (target_workspace.num / 10) as usize; + let full_ws_name = format!("{}{}", group_index, target_workspace.num % 10); // Move container to target workspace let mut cmd: String = "move container to workspace number ".to_string(); - cmd.push_str(&target_workspace.num.to_string()); + cmd.push_str(&full_ws_name); send_command(stream, &cmd); // Focus that workspace to follow the container @@ -551,10 +569,8 @@ fn init_workspaces(stream: &UnixStream, workspace_index: usize) { "{}{}", get_current_output_index(stream) + 1, &workspace_index - ) - .parse::() - .unwrap(); - cmd.push_str(&full_ws_name.to_string()); + ); + cmd.push_str(&full_ws_name); send_command(stream, &cmd); } } @@ -570,10 +586,10 @@ fn rearrange_workspaces(stream: &UnixStream) { focus_cmd.push_str(&workspace.num.to_string()); send_command(stream, &focus_cmd); - let output_index = workspace.num / 10; - if output_index <= outputs.len() - 1 { + let group_index = workspace.num / 10; + if group_index <= outputs.len() - 1 { let mut move_cmd = move_cmd_prefix.clone(); - move_cmd.push_str(&outputs[output_index.max(1) - 1].name); + move_cmd.push_str(&outputs[group_index.max(1) - 1].name); send_command(stream, &move_cmd); } } @@ -590,6 +606,9 @@ fn main() { Command::Move(action) => { move_container_to_workspace(&stream, action.index); } + Command::MoveToGroup(action) => { + move_container_to_workspace_group(&stream, action.index); + } Command::Focus(action) => { focus_to_workspace(&stream, action.index); }