4 <%inherit file="_templates/i3.mako" />
5 <div id="content" class="usergen">
6 <h1>User-contributed article: Swapping workspaces</h1>
9 If you have workspace 1 on one monitor and workspace 2 on another monitor and
10 want to quickly swap the workspaces among the monitors, you can use i3's IPC
11 mechanisms to do it. Here's how:
15 i3 already includes a way to move an individual workspace from one monitor to
16 another. But what we want to achieve is the <strong>simultaneous</strong>
17 movement of workspaces between the monitors. To do this, we can write a script
18 that detects the currently active workspace on each monitor and then moves that
19 workspace to the other monitor.
23 The script uses i3's <a href="http://i3wm.org/docs/ipc.html">IPC</a> via the
24 <a href="https://github.com/ziberna/i3-py">i3-py Python bindings</a>.
27 <pre><tt>#!/usr/bin/python2.7
30 outputs = i3.get_outputs()
32 # set current workspace to output 0
33 i3.workspace(outputs[0]['current_workspace'])
35 # ..and move it to the other output.
36 # outputs wrap, so the right of the right is left ;)
37 i3.move__workspace__to__output__right()
40 i3.workspace(outputs[1]['current_workspace'])
41 i3.move__workspace__to__output__right()</tt></pre>
44 A very simple way to use this script is as follows: Put the script in a file,
45 named for example switch.py, and put switch.py and i3.py (downloaded from the
46 <a href="https://github.com/ziberna/i3-py">Python bindings site</a>) in the
47 same folder. I typically put it in $HOME/.i3/, the same directory which
48 contains i3's config file. Next, put a keybinding like
50 <pre><tt>bindsym $mod+Shift+s exec /home/username/.i3/switch.py</tt></pre>
52 in i3's config file and restart i3 in place. The next time you press
53 mod+Shift+s, your workspaces will be swapped among your monitors.
56 <p>Author: Sagar Behere</p>