Skip to content

Instantly share code, notes, and snippets.

@gorsheninmv
Last active August 30, 2020 06:45
Show Gist options
  • Save gorsheninmv/7288193786a2f1344367ed5171983e47 to your computer and use it in GitHub Desktop.
Save gorsheninmv/7288193786a2f1344367ed5171983e47 to your computer and use it in GitHub Desktop.
This script is used in swaywm and swaps two containers.
#!/usr/bin/python
'''
DESCRIPTION:
This script is used in swaywm and swaps two containers.
USAGE EXAMPLE:
Put 'bindsym $mod+g exec /path/to/script/win_swap.py' in the config file.
Get some container focused and press $mod+g. Get another container focused
and press $mod+g again. The two windows are going to be swapped.
DEPENDENCIES:
i3ipc-python
AUTHOR:
Misha Gorshenin, [email protected]
LICENSE:
MIT
'''
import i3ipc
ipc = i3ipc.Connection()
tree = ipc.get_tree()
MARK = 'swapped'
marked = None
focused = tree.find_focused()
swapped = ipc.get_tree().find_marked(MARK)
if (len(swapped) > 0):
marked = swapped[0]
if marked is None:
focused.command(f'mark --toggle {MARK}')
else:
con_id = marked.id
marked.command(f'mark --toggle {MARK}')
ipc.command(f'swap container with con_id {con_id}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment