瀏覽代碼

Switch to workspace and move to current output

Samuel W. Flint 8 年之前
父節點
當前提交
9f981c991b
共有 1 個文件被更改,包括 26 次插入0 次删除
  1. 26 0
      i3-switch-workspace

+ 26 - 0
i3-switch-workspace

@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+from json import loads
+from os import popen
+from sys import argv
+
+def ipc_query(req="command", msg=""):
+    ans = popen("i3-msg -t " + req + " " +  msg).readlines()[0]
+    return loads(ans)
+
+if __name__ == "__main__":
+    # Usage & checking args
+    if len(argv) != 2:
+        print "Usage: i3-switch-workspace name-of-workspace"
+        exit(-1)
+
+    newworkspace = argv[1]
+
+    # Retrieving active display
+    active_display = None
+    for w in ipc_query(req="get_workspaces"):
+        if w['focused']:
+            active_display = w['output']
+
+    # Moving workspace to active display
+    print ipc_query(msg="'workspace number " + newworkspace + "; move workspace to output " + active_display + "'")