Created
February 19, 2014 10:39
-
-
Save carlesso/9089599 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
#!/usr/bin/env python | |
import sys | |
import i3 | |
def get_workspace(position = None): | |
mon = next(el for el in i3.get_workspaces() if el["focused"]) | |
current_output = next(output for output in i3.get_outputs() if (output["active"] and (output["name"] == mon["output"]))) | |
if position is None: | |
position = "current" | |
desktop_list = [workspace for workspace in i3.get_workspaces() if workspace["output"] == current_output["name"]] | |
for index, desktop in enumerate(desktop_list): | |
if desktop["focused"]: | |
# Current Desktop, need the second | |
if position == "current": | |
return desktop_list[index] | |
elif position == "prev": | |
prev_idx = (index - 1) % len(desktop_list) | |
return desktop_list[prev_idx] | |
elif position == "next": | |
next_idx = (index + 1) % len(desktop_list) | |
return desktop_list[next_idx] | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print("usage: %s prev|next" % sys.argv[0]) | |
exit(0) | |
if sys.argv[1] == "next": | |
i3.workspace(get_workspace("next")["name"]) | |
elif sys.argv[1] == "prev": | |
i3.workspace(get_workspace("prev")["name"]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment