--- layout: default title: Docs group: Docs ---

User-contributed article: Swapping workspaces

If you have workspace 1 on one monitor and workspace 2 on another monitor and want to quickly swap the workspaces among the monitors, you can use i3's IPC mechanisms to do it.

i3 already includes a way to move an individual workspace from one monitor to another. But what we want to achieve is the simultaneous movement of workspaces between the monitors. To do this, we can write a script that detects the currently active workspace on each monitor and then moves that workspace to the other monitor.

#!/usr/bin/env bash
# requires jq

IFS=:
i3-msg -t get_outputs | jq -r '.[]|"\(.name):\(.current_workspace)"' | grep -v '^null:null$' | \
while read -r name current_workspace; do
    echo "moving ${current_workspace} right..."
    i3-msg workspace "${current_workspace}"
    i3-msg move workspace to output right   
done

To use this script, I recommend binding it to a keyboard shortcut in your i3 config:

bindsym $mod+Shift+s exec /path/to/your/script/i3-display-swap.sh

Now restart i3 in place. The next time you press mod+Shift+s, your workspaces will be swapped among your monitors.

Source: Github