]> git.sur5r.net Git - i3/i3.github.io/blob - docs/user-contributed/swapping-workspaces.html
Merge pull request #52 from fbrinker/swapping-workspaces
[i3/i3.github.io] / docs / user-contributed / swapping-workspaces.html
1 ---
2 layout: default
3 title: Docs
4 group: Docs
5 ---
6 <div id="content" class="usergen">
7 <h1>User-contributed article: Swapping workspaces</h1>
8
9 <p>
10 If you have workspace 1 on one monitor and workspace 2 on another monitor and
11 want to quickly swap the workspaces among the monitors, you can use i3's IPC
12 mechanisms to do it.
13 </p>
14
15 <p>
16 i3 already includes a way to move an individual workspace from one monitor to
17 another. But what we want to achieve is the <strong>simultaneous</strong>
18 movement of workspaces between the monitors. To do this, we can write a script
19 that detects the currently active workspace on each monitor and then moves that
20 workspace to the other monitor.
21 </p>
22
23 <pre><tt>#!/usr/bin/env bash
24 # requires jq
25
26 DISPLAY_CONFIG=($(i3-msg -t get_outputs | jq -r '.[]|"\(.name):\(.current_workspace)"'))
27
28 for ROW in "${DISPLAY_CONFIG[@]}"
29 do
30     IFS=':'
31     read -ra CONFIG <<< "${ROW}"
32     if [ "${CONFIG[0]}" != "null" ] && [ "${CONFIG[1]}" != "null" ]; then
33         echo "moving ${CONFIG[1]} right..."
34         i3-msg workspace "${CONFIG[1]}"
35         i3-msg move workspace to output right   
36     fi
37 done</tt></pre>
38
39 <p>
40 To use this script, I recommend binding it to a keyboard shortcut in your i3 config:
41 </p>
42 <pre><tt>bindsym $mod+Shift+s exec /path/to/your/script/i3-display-swap.sh</tt></pre>
43 <p>
44 Now restart i3 in place. The next time you press mod+Shift+s, your workspaces will be swapped among your monitors.
45 </p>
46
47 <p>Source: <a href="https://gist.github.com/fbrinker/df9cfbc84511d807f45041737ff3ea02">Github</a></p>