A simple Ruby script that restores windows and workspaces to their respective monitors when they are disconnected and reconnected.
Note: The "watch" mode only works per session. If you log out or power off your machine, the script will not automatically restore the latest state when you log back in.
- Ruby
- i3 window manager
- xrandr (for monitor management)
- Make the script executable:
chmod +x i3_rewind- Optionally:
sudo cp i3_rewind ~/./local/bin/Add to i3 config:
exec_always ~/.local/bin/i3_rewind -w &Create file at ~/.config/i3/i3_rewind_script.sh
#!/bin/bash
case "$I3_REWIND_TRANSITION" in
to_multi_monitor)
i3-msg mode "i3_rewind_multi_monitor"
;;
to_primary_monitor)
i3-msg mode "default"
;;
esacAdd to i3 config:
exec_always ~/.local/bin/i3_rewind -w -t ~/.config/i3/i3_rewind_script.sh &The script will try to active the mode i3_rewind_multi_monitor.
./i3_rewind --watchAutomatically saves and restores sessions when monitors are connected/disconnected.
./i3_rewind --saveSaves your current window layout and monitor configuration.
./i3_rewind --restoreRestores the previously saved session.
./i3_rewind --helpDEBUG=1 ./i3_rewind -wThe script saves:
- Window positions and workspaces
- Monitor configurations and layouts
- Session data to
~/.config/i3/i3_rewind.json
Perfect for laptop users who frequently connect/disconnect external monitors!