mirror of
https://gitlab.com/hyask/swaysome.git
synced 2025-12-10 07:44:43 +01:00
Merge branch 'rearrange_workspaces' into 'master'
Rearrange workspaces Based of the args parser rework, I added a feature to rearrange the missplaced workspaces. It is useful when you unplug a screen, create a workspace then plug the screen back. In this scenario, the screen won't move back to the correct screen when the screen is plugged back. I don't know if there could be a way to fix this behavior instead of creating a feature to repair it each time. Let me know what you think See merge request hyask/swaysome!4
This commit is contained in:
commit
dfb6e79a3a
2 changed files with 53 additions and 11 deletions
26
README.md
26
README.md
|
|
@ -67,6 +67,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"
|
||||
|
||||
|
|
@ -93,10 +105,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
|
||||
|
||||
|
|
|
|||
38
src/main.rs
38
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)]
|
||||
|
|
@ -46,24 +46,27 @@ enum Command {
|
|||
|
||||
#[clap(about = "Move the focused container to the previous output")]
|
||||
PrevOutput,
|
||||
|
||||
#[clap(about = "Rearrange already opened workspaces")]
|
||||
RearrangeWorkspaces,
|
||||
}
|
||||
|
||||
#[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 {
|
||||
|
|
@ -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<Output> {
|
|||
outputs
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct Workspace {
|
||||
num: u32,
|
||||
output: String,
|
||||
|
|
@ -297,6 +300,26 @@ fn init_workspaces(stream: &UnixStream, workspace_name: &String) {
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
let stream = get_stream();
|
||||
|
|
@ -320,5 +343,8 @@ fn main() {
|
|||
Command::PrevOutput => {
|
||||
move_container_to_prev_output(&stream);
|
||||
}
|
||||
Command::RearrangeWorkspaces => {
|
||||
rearrange_workspaces(&stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue