]> git.sur5r.net Git - i3/i3.github.io/blob - docs/user-contributed/swapping-workspaces.html.mako
021f4583792980af02b619b288fd0bcdea6cdfa8
[i3/i3.github.io] / docs / user-contributed / swapping-workspaces.html.mako
1 <%!
2         section = "docs"
3 %>
4 <%inherit file="_templates/i3.mako" />
5 <div id="content" class="usergen">
6 <h1>User-contributed article: Swapping workspaces</h1>
7
8 <p>
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:
12 </p>
13
14 <p>
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.
20 </p>
21
22 <p>
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>.
25 </p>
26
27 <pre><tt>#!/usr/bin/python2.7
28
29 import i3
30 outputs = i3.get_outputs()
31
32 # set current workspace to output 0
33 i3.workspace(outputs[0][&#39;current_workspace&#39;])
34
35 # ..and move it to the other output.
36 # outputs wrap, so the right of the right is left ;)
37 i3.command('move', 'workspace to output right')
38
39 # rinse and repeat
40 i3.workspace(outputs[1][&#39;current_workspace&#39;])
41 i3.command('move', 'workspace to output right')</tt></pre>
42
43 <p>
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
49 </p>
50 <pre><tt>bindsym $mod+Shift+s exec /home/username/.i3/switch.py</tt></pre>
51 <p>
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.
54 </p>
55
56 <p>Author: Sagar Behere</p>