]> git.sur5r.net Git - i3/i3.github.io/blob - docs/4.13/user-contributed/swapping-workspaces.html
save docs for 4.13
[i3/i3.github.io] / docs / 4.13 / 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. Here's how:
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 <p>
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>.
26 </p>
27
28 <pre><tt>#!/usr/bin/python2.7
29
30 import i3
31 # retrieve only active outputs
32 outputs = filter(lambda output: output[&#39;active&#39;], i3.get_outputs())
33
34 # set current workspace to output 0
35 i3.workspace(outputs[0][&#39;current_workspace&#39;])
36
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')
40
41 # rinse and repeat
42 i3.workspace(outputs[1][&#39;current_workspace&#39;])
43 i3.command('move', 'workspace to output right')</tt></pre>
44
45 <p>
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
51 </p>
52 <pre><tt>bindsym $mod+Shift+s exec /home/username/.i3/switch.py</tt></pre>
53 <p>
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.
56 </p>
57
58 <p>Author: Sagar Behere</p>