Skip to content

berezowski/swaymsg_workspace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

49 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

swaymsg_workspace: A Better Way to Manage Sway Workspaces

This tool improves workspace management in Sway by making workspace switching, reordering, and renaming easierโ€”especially when using multiple monitors.


๐Ÿ”ง What It Does

  • Switch workspaces (like workspace next) but stays on the focused monitor
  • Reorder workspaces left/rightโ€”just like browser tabs
  • Rename workspaces without losing their numbers
  • Integrates with Rofi for quick workspace selection and renaming

๐Ÿ’ก Why Use It?

Problem with Default Sway Behavior

When using multiple monitors, Swayโ€™s built-in workspace next jumps to a different monitor. Or even cycles backwards through Workspaces. Thatโ€™s confusing!

Comparison to Sway stock behaviour:
Default Sway (moves across monitors) swaymsg_workspace (stays on current monitor)
ย ย ย 
Monitor1 Monitor2
โ–ช 6 work โ–ซ 8 messages โ–ซ 7 music

next

โ–ซ 6 work โ–ซ 8 messages โ–ช 7 music

next

โ–ซ 6 work โ–ช 8 messages โ–ซ 7 music

next

โ–ช 6 work โ–ซ 8 messages โ–ซ 7 music

ย ย ย 

ย ย ย 
Monitor1 Monitor2
โ–ช 6 work โ–ซ 8 messages โ–ซ 7 music

next

โ–ซ 6 work โ–ช 8 messages โ–ซ 7 music

next

โ–ช 6 work โ–ซ 8 messages โ–ซ 7 music

next

โ–ซ 6 work โ–ช 8 messages โ–ซ 7 music

ย ย ย 


โœจ Features Overview

General Commands

Limited to current Output

Feature What it does
next, prev Go to next/previous workspace on the same monitor
swap_with_next, swap_with_prev Reorder current workspace left/right on the same monitor
increase, decrease Reassign workspace to next/previous number
rename_to <name> Rename a workspace but keep its number
number <n> Go to workspace <n> on the same monitor
move_container_to_workspace_number <n> Move focused window to workspace <n> on same monitor

Rofi integration Commands

Across all Outputs

Feature What it does
rofi_select_workspace Print unique names of all workspaces
rofi_select_workspace <unique name> Select workspace by unique name
select <unique name> Alias for rofi_select_workspace <unique name>
rofi_move_window Print unique names of all workspaces
rofi_move_window <unique name> Move container to workspace idetified by unique name
Select workspace
~/.cargo/bin/swaymsg_workspace next
block-beta
  columns 3
  block:a:3
    A["5 music"]
    B["6 work"]
    C["8 messages"]
  end
  space:3
  block:b:3
    D["5 music"]
    E["6 work"]
    F["8 messages"]
  end
  space:3
  block:c:3
    G["5 music"]
    H["6 work"]
    I["8 messages"]
  end
  a -- "next" --> b
  b -- "next" --> c
  style B stroke:#288,stroke-width:4px
  style F stroke:#288,stroke-width:4px
  style G stroke:#288,stroke-width:4px
Loading
~/.cargo/bin/swaymsg_workspace prev
block-beta
  columns 3
  block:a:3
    A["5 music"]
    B["6 work"]
    C["8 messages"]
  end
  space:3
  block:b:3
    D["5 music"]
    E["6 work"]
    F["8 messages"]
  end
  a -- "prev" --> b
  style B stroke:#288,stroke-width:4px
  style D stroke:#288,stroke-width:4px

Loading
Swap workspace
~/.cargo/bin/swaymsg_workspace swap_with_next
block-beta
  columns 3
  block:a:3
    A["5 music"]
    B["6 work"]
    C["8 messages"]
  end
  space:3
  block:b:3
    D["5 music"]
    E["6 messages"]
    F["8 work"]
  end
  space:3
  block:c:3
    G["5 work"]
    H["6 messages"]
    I["8 music"]
  end
  a -- "swap_with_next"--> b
  b -- "swap_with_next"--> c
  style B stroke:#288,stroke-width:4px
  style F stroke:#288,stroke-width:4px
  style G stroke:#288,stroke-width:4px
Loading
~/.cargo/bin/swaymsg_workspace swap_with_prev
block-beta
  columns 3
  block:a:3
    A["5 music"]
    B["6 work"]
    C["8 messages"]
  end
  space:3
  block:b:3
    D["5 work"]
    E["6 music"]
    F["8 messages"]
  end
  a -- "swap_with_prev" --> b
  style B stroke:#288,stroke-width:4px
  style D stroke:#288,stroke-width:4px
Loading
Index workspace
~/.cargo/bin/swaymsg_workspace increase
block-beta
  columns 3
  block:a:3
    A["5 music"]
    B["6 work"]
    C["8 messages"]
  end
  space:3
  block:b:3
    D["5 music"]
    E["7 work"]
    F["8 messages"]
  end
  space:3
  block:c:3
    G["5 music"]
    H["7 messages"]
    I["8 work"]
  end
  a -- "increase"--> b
  b -- "increase"--> c
  style B stroke:#288,stroke-width:4px
  style E stroke:#288,stroke-width:4px
  style I stroke:#288,stroke-width:4px
Loading
~/.cargo/bin/swaymsg_workspace decrease
block-beta
  columns 3
  block:a:3
    A["5 music"]
    B["7 work"]
    C["8 messages"]
  end
  space:3
  block:b:3
    D["5 music"]
    E["6 work"]
    F["8 messages"]
  end
  a -- "decrease"--> b
  style B stroke:#288,stroke-width:4px
  style E stroke:#288,stroke-width:4px

Loading
Rename workspace
~/.cargo/bin/swaymsg_workspace rename_to movies
block-beta
  columns 3
  block:a:3
    A["5 music"]
    B["6 work"]
    C["8 messages"]
  end
  space:3
  block:b:3
    D["5 movies"]
    E["6 work"]
    F["8 messages"]
  end
  a -- "rename_to movies"--> b
  style A stroke:#288,stroke-width:4px
  style D stroke:#288,stroke-width:4px
Loading
Select workspace while multiple monitors are connected
~/.cargo/bin/swaymsg_workspace number 5
block-beta
  columns 2
    block:a1["Monitor 1"]:1
      columns 3
      A1["6 work"]
      B1["8 messages"]
      space:6
    end
    block:a2["Monitor 2"]:1
      columns 3
      A2["5"]
      space:6    
    end
  space:2
    block:b1["Monitor 1"]:1
      columns 3
      C1["5"]
      D1["6 work"]
      E1["8 messages"]
      space:6
    end
    block:b2["Monitor 2"]:1
      columns 3
      B2["5"]
      space:6    
    end
  a1 -- "number 5" --> b1
  style B1 stroke:#288,stroke-width:4px
  style C1 stroke:#288,stroke-width:4px
Loading
Move window to workspace number while multiple monitors are connected
~/.cargo/bin/swaymsg_workspace move_container_to_workspace_number 5
block-beta
  columns 2
    block:a1["Monitor 1"]:1
      columns 3
      A1["6 work"]
      B1["8 messages"]
      space:6
    end
    block:a2["Monitor 2"]:1
      columns 3
      A2["5"]
      space:6    
    end
  space:2
    block:b1["Monitor 1"]:1
      columns 3
      C1["5"]
      D1["6 work"]
      E1["8 messages"]
      space:6
    end
    block:b2["Monitor 2"]:1
      columns 3
      B2["5"]
      space:6    
    end
  a1 -- "move_container_to_workspace_number 5" --> b1
  style B1 stroke:#288,stroke-width:4px
  style E1 stroke:#288,stroke-width:4px
Loading

๐Ÿš€ Quick Start

1. install Rust

Visit: https://www.rust-lang.org/tools/install

Rust includes cargo and rustup.

2. Use Rust Nightly

rustup override set nightly

3. Install the Tool

cargo install --git https://github.com/berezowski/swaymsg_workspace

Binary will be at: ~/.cargo/bin/swaymsg_workspace

โš™๏ธ Sway Config Example

Add these bindings to your ~/.config/sway/config:

### swaymsg_workspace select previous / next
bindsym Mod1+Ctrl+n exec ~/.cargo/bin/swaymsg_workspace next
bindsym Mod1+Ctrl+p exec ~/.cargo/bin/swaymsg_workspace prev

### swaymsg_workspace move workspace left / right
bindsym Mod1+Ctrl+Shift+n exec ~/.cargo/bin/swaymsg_workspace swap_with_next
bindsym Mod1+Ctrl+Shift+p exec ~/.cargo/bin/swaymsg_workspace swap_with_prev

### swaymsg_workspace increase / decrease number
bindsym Mod1+Ctrl+v exec ~/.cargo/bin/swaymsg_workspace decrease
bindsym Mod1+Ctrl+Shift+v exec ~/.cargo/bin/swaymsg_workspace increase

### swaymsg_workspace select by number
bindsym Mod1+Ctrl+0 exec ~/.cargo/bin/swaymsg_workspace number 10
bindsym Mod1+Ctrl+1 exec ~/.cargo/bin/swaymsg_workspace number 1
bindsym Mod1+Ctrl+2 exec ~/.cargo/bin/swaymsg_workspace number 2
bindsym Mod1+Ctrl+3 exec ~/.cargo/bin/swaymsg_workspace number 3
bindsym Mod1+Ctrl+4 exec ~/.cargo/bin/swaymsg_workspace number 4
bindsym Mod1+Ctrl+5 exec ~/.cargo/bin/swaymsg_workspace number 5
bindsym Mod1+Ctrl+6 exec ~/.cargo/bin/swaymsg_workspace number 6
bindsym Mod1+Ctrl+7 exec ~/.cargo/bin/swaymsg_workspace number 7
bindsym Mod1+Ctrl+8 exec ~/.cargo/bin/swaymsg_workspace number 8
bindsym Mod1+Ctrl+9 exec ~/.cargo/bin/swaymsg_workspace number 9

### swaymsg_workspace move container to workspace number
bindsym Mod1+Ctrl+Shift+0 exec ~/.cargo/bin/swaymsg_workspace move_container_to_workspace_number 10
bindsym Mod1+Ctrl+Shift+1 exec ~/.cargo/bin/swaymsg_workspace move_container_to_workspace_number 1
bindsym Mod1+Ctrl+Shift+2 exec ~/.cargo/bin/swaymsg_workspace move_container_to_workspace_number 2
bindsym Mod1+Ctrl+Shift+3 exec ~/.cargo/bin/swaymsg_workspace move_container_to_workspace_number 3
bindsym Mod1+Ctrl+Shift+4 exec ~/.cargo/bin/swaymsg_workspace move_container_to_workspace_number 4
bindsym Mod1+Ctrl+Shift+5 exec ~/.cargo/bin/swaymsg_workspace move_container_to_workspace_number 5
bindsym Mod1+Ctrl+Shift+6 exec ~/.cargo/bin/swaymsg_workspace move_container_to_workspace_number 6
bindsym Mod1+Ctrl+Shift+7 exec ~/.cargo/bin/swaymsg_workspace move_container_to_workspace_number 7
bindsym Mod1+Ctrl+Shift+8 exec ~/.cargo/bin/swaymsg_workspace move_container_to_workspace_number 8
bindsym Mod1+Ctrl+Shift+9 exec ~/.cargo/bin/swaymsg_workspace move_container_to_workspace_number 9

๐Ÿง  Rofi Integration

Use rofi to rename or select workspaces:

Sway Config

~/.config/sway/config:

bindsym --release Mod1+Ctrl+space exec /usr/bin/rofi -show combi
bindsym Mod1+Ctrl+r exec ~/.cargo/bin/swaymsg_workspace rename_to $(rofi -dmenu -l 0 -P "rename workspace $(~/.cargo/bin/swaymsg_workspace print_focused_name) to")

Rofi Config

~/.config/rofi/config.rasi:

configuration {
  modi: "combi,move to workspace:~/.cargo/bin/swaymsg_workspace rofi_move_window";
  font: "M+CodeLat60 Nerd Font Mono 12";
  combi-modi: "workspaces:~/.cargo/bin/swaymsg_workspace rofi_select_workspace,window,drun,ssh";
  kb-mode-next: "Control+Alt+space";
}

๐Ÿ–ฑ๏ธ useful in this context: focusing monitors

~/.config/sway/config:

bindsym Mod1+Ctrl+m focus output right, focus child
bindsym Mod1+Ctrl+m+Shift move workspace to output right

bindsym Mod1+Ctrl+u focus output up, focus child
bindsym Mod1+Ctrl+u+Shift move workspace to output up

bindsym Mod1+Ctrl+Mod4+h move workspace to output left
bindsym Mod1+Ctrl+Mod4+j move workspace to output down
bindsym Mod1+Ctrl+Mod4+k move workspace to output up
bindsym Mod1+Ctrl+Mod4+l move workspace to output right

๐Ÿ“บ Demo

out.mp4

About

reordering, renaming, alternative switching of sway workspaces

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published