i3-split-smartly 629 B

1234567891011121314151617181920212223
  1. #!/usr/bin/env python
  2. from json import loads
  3. from os import popen
  4. from sys import argv
  5. def ipcQuery(req="command", msg=""):
  6. ans = popen("i3-msg -t " + req + " " + msg).readlines()[0]
  7. return loads(ans)
  8. def ipcCurrentWindowSize():
  9. id = popen("xdotool getwindowfocus").readlines()[0].rstrip()
  10. answer = popen("xwininfo -id "+id+" | grep -E '(Width|Height)'").readlines()
  11. width=int(answer[0].rstrip().split()[1])
  12. height=int(answer[1].rstrip().split()[1])
  13. return (width, height)
  14. (width, height) = ipcCurrentWindowSize()
  15. if width > height:
  16. ipcQuery(msg="split h")
  17. else:
  18. ipcQuery(msg="split v")