Created
November 15, 2016 21:38
-
-
Save jersey99/d6d11991546ea37839bd960ad27f433b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Swaps the workspace (ws) being displayed with it's adjacent ws | |
# DEPENDS: https://github.com/ziberna/i3-py | |
# ADD the following lines to i3 config file: ~/.i3/config | |
# bindsym $mod+less exec python /path/to/i3_move_ws.py left | |
# bindsym $mod+greater exec python /path/to/i3_move_ws.py right | |
import i3 | |
def move_ws(direction): | |
d = 1 if direction == 'right' else -1 | |
outputs = filter(lambda output: output['active'], i3.get_outputs()) | |
# Prevent erratic behavior in the case of multiple monitors | |
if len(outputs) != 1: return 254 | |
c = outputs[0]['current_workspace'] | |
workspaces = i3.get_workspaces() | |
total_workspaces = len(workspaces) | |
for i, w in enumerate(workspaces): | |
if w['name'] == c: | |
if (i + d) < 0 or (i + d) >= total_workspaces: | |
return 255 | |
s = workspaces[(i + d) % total_workspaces]['name'] | |
TEMP = "TEMP_SDLKFHJSJKLDFHJKLSDHGJKLSDH" | |
i3.command('rename', 'workspace %s to %s'%(c, TEMP)) | |
i3.command('rename', 'workspace %s to %s'%(s, c)) | |
i3.command('rename', 'workspace %s to %s'%(TEMP, s)) | |
return 0 | |
if __name__ == '__main__': | |
import sys | |
if len(sys.argv) != 2: | |
exit(1) | |
else: | |
exit(move_ws(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment