]> git.sur5r.net Git - i3/i3.github.io/blob - docs/user-contributed/swapping-workspaces.html
Fix swapping workspaces script colon issue
[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 IFS=:
27 i3-msg -t get_outputs | jq -r '.[]|"\(.name):\(.current_workspace)"' | grep -v '^null:null$' | \
28 while read -r name current_workspace; do
29     echo "moving ${current_workspace} right..."
30     i3-msg workspace "${current_workspace}"
31     i3-msg move workspace to output right   
32 done</tt></pre>
33
34 <p>
35 To use this script, I recommend binding it to a keyboard shortcut in your i3 config:
36 </p>
37 <pre><tt>bindsym $mod+Shift+s exec /path/to/your/script/i3-display-swap.sh</tt></pre>
38 <p>
39 Now restart i3 in place. The next time you press mod+Shift+s, your workspaces will be swapped among your monitors.
40 </p>
41
42 <p>Source: <a href="https://gist.github.com/fbrinker/df9cfbc84511d807f45041737ff3ea02">Github</a></p>