6 <div id="content" class="usergen">
7 <h1>User-contributed article: Swapping workspaces</h1>
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. Here's how:
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.
24 The script uses i3's <a href="http://i3wm.org/docs/ipc.html">IPC</a> via the
25 <a href="https://github.com/ziberna/i3-py">i3-py Python bindings</a>.
28 <pre><tt>#!/usr/bin/python2.7
31 # retrieve only active outputs
32 outputs = filter(lambda output: output['active'], i3.get_outputs())
34 # set current workspace to output 0
35 i3.workspace(outputs[0]['current_workspace'])
37 # ..and move it to the other output.
38 # outputs wrap, so the right of the right is left ;)
39 i3.command('move', 'workspace to output right')
42 i3.workspace(outputs[1]['current_workspace'])
43 i3.command('move', 'workspace to output right')</tt></pre>
46 A very simple way to use this script is as follows: Put the script in a file,
47 named for example switch.py, and put switch.py and i3.py (downloaded from the
48 <a href="https://github.com/ziberna/i3-py">Python bindings site</a>) in the
49 same folder. I typically put it in $HOME/.i3/, the same directory which
50 contains i3's config file. Next, put a keybinding like
52 <pre><tt>bindsym $mod+Shift+s exec /home/username/.i3/switch.py</tt></pre>
54 in i3's config file and restart i3 in place. The next time you press
55 mod+Shift+s, your workspaces will be swapped among your monitors.
58 <p>Author: Sagar Behere</p>