SwayWM script to undo container reparenting and restore original layout.
Warning
This project will be rewritten in Rust.
Base State:
Rickroll | |||
Neovim | wf-recorder | Ranger | terminal |
Nautilus |
- Neovim, Rickroll, Ranger - Move to another workspace then undo state once.
- Move Rickroll to the right.
- Swap Nautilus with Ranger.
- Undo state once.
- Move ranger to another workspace.
- Swap neovim with wf-recorder (terminal).
- Undo state 3 times.
Note
This script isn't polished and may or may not work on your setup. It may also fall in and out of my priorities. Regardless, feel free to open issues or pull requests.
- Copy/Download the script into
$HOME/bin
. - Start the daemon by adding this to sway config:
exec sway-anchor daemon start
Note
This will only start the daemon on sway startup, not on config reload.
- Set keybindings:
bindsym $mod+Control+u exec sway-anchor state undo
- If you have keybinds to directionally swap containers (example), replace them with the script swap commands so the daemon can track their state. Currently, only directional swaps are supported.
bindsym $mod+Control+$left exec sway-anchor swap left
bindsym $mod+Control+$down exec sway-anchor swap down
bindsym $mod+Control+$up exec sway-anchor swap up
bindsym $mod+Control+$right exec sway-anchor swap right
- See
sway-anchor -h
andsway-anchor [command] -h
for more info.
- Get state of currently focused window.
- When moved or swapped:
- Anchor focused window to another window which will serve as a reference for layout restoration.
- Store the two windows' state.
- On undo, move anchored window of the most recently tracked state to its anchor.
- If necessary, move window up, down, left, or right, until original layout is restored.
- Repeat
I wanted to "fullscreen" a window while still having window gaps and a status bar. This essentially is just moving it to another workspace as a solo container. The problem was that when moving it back to it's original workspace, the layout wasn't restored. This was not easily fixable with builtin sway commands.
Through sway-anchor, it's now doable with this simple bash script (sway-fullscreen-gaps):
#!/bin/sh
active_ws=$(swaymsg -t get_workspaces -r \
| jq -r '.[] | select(.focused==true).name')
if [ "$active_ws" != "fullscreen-gaps" ]; then
swaymsg move container to workspace fullscreen-gaps
swaymsg workspace fullscreen-gaps
else
sway-anchor state undo
fi
Then add this to your sway config:
bindsym $mod+f exec sway-fullscreen-gaps
Besides error handling not being implemented yet, this script isn't supposed to handle all edge cases. Specific edge case
support will only be supported if enough people need it. Using sway-autotiling with --limit 2
, this
script works perfectly.
No plans as of yet. Although it's a fairly simple feature to add, I personally think having too much ways to navigate a system can be prone to decision paralysis. If enough people voice their need for it, it will be supported.
- Error handling
- Refactoring
- Debug mode
- Tests (maybe)