From: Florian Brinker Date: Wed, 11 Apr 2018 12:47:54 +0000 (+0200) Subject: #49: Changed outdated py to bash script X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a303c3a5ed951eb3795cb4c08f2972a8bdf93605;p=i3%2Fi3.github.io #49: Changed outdated py to bash script --- diff --git a/docs/user-contributed/swapping-workspaces.html b/docs/user-contributed/swapping-workspaces.html index 4a3019e..75747f9 100644 --- a/docs/user-contributed/swapping-workspaces.html +++ b/docs/user-contributed/swapping-workspaces.html @@ -9,7 +9,7 @@ group: Docs

If you have workspace 1 on one monitor and workspace 2 on another monitor and want to quickly swap the workspaces among the monitors, you can use i3's IPC -mechanisms to do it. Here's how: +mechanisms to do it.

@@ -20,39 +20,28 @@ that detects the currently active workspace on each monitor and then moves that workspace to the other monitor.

-

-The script uses i3's IPC via the -i3-py Python bindings. -

- -
#!/usr/bin/python2.7
-
-import i3
-# retrieve only active outputs
-outputs = filter(lambda output: output['active'], i3.get_outputs())
-
-# set current workspace to output 0
-i3.workspace(outputs[0]['current_workspace'])
+
#!/usr/bin/env bash
+# requires jq
 
-# ..and move it to the other output.
-# outputs wrap, so the right of the right is left ;)
-i3.command('move', 'workspace to output right')
+DISPLAY_CONFIG=($(i3-msg -t get_outputs | jq -r '.[]|"\(.name):\(.current_workspace)"'))
 
-# rinse and repeat
-i3.workspace(outputs[1]['current_workspace'])
-i3.command('move', 'workspace to output right')
+for ROW in "${DISPLAY_CONFIG[@]}" +do + IFS=':' + read -ra CONFIG <<< "${ROW}" + if [ "${CONFIG[0]}" != "null" ] && [ "${CONFIG[1]}" != "null" ]; then + echo "moving ${CONFIG[1]} right..." + i3-msg workspace "${CONFIG[1]}" + i3-msg move workspace to output right + fi +done

-A very simple way to use this script is as follows: Put the script in a file, -named for example switch.py, and put switch.py and i3.py (downloaded from the -Python bindings site) in the -same folder. I typically put it in $HOME/.i3/, the same directory which -contains i3's config file. Next, put a keybinding like +To use this script, I recommend binding it to a keyboard shortcut in your i3 config:

-
bindsym $mod+Shift+s exec /home/username/.i3/switch.py
+
bindsym $mod+Shift+s exec /path/to/your/script/i3-display-swap.sh

-in i3's config file and restart i3 in place. The next time you press -mod+Shift+s, your workspaces will be swapped among your monitors. +Now restart i3 in place. The next time you press mod+Shift+s, your workspaces will be swapped among your monitors.

-

Author: Sagar Behere

+

Source: Github