My dotfiles for my Linux rice managed with stow and make
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

focus.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/python2.7
  2. import i3
  3. from subprocess import check_output
  4. import json
  5. def findWindow(container):
  6. if container['nodes'] == []:
  7. if container['focused'] == True:
  8. return container
  9. else: return None
  10. for con in container['nodes']:
  11. win = findWindow(con)
  12. if win != None: return win
  13. for con in container['floating_nodes']:
  14. win = findWindow(con)
  15. if win != None: return win
  16. def find_tmp(container):
  17. if container['nodes'] == []:
  18. if container['window'] == None and container['name'] == None:
  19. return container['id']
  20. else: return None
  21. for con in container['nodes']:
  22. tmp = find_tmp(con)
  23. if tmp != None: return tmp
  24. def create_tmp(current_id):
  25. i3.focus(con_id=current_id)
  26. i3.split('vertical')
  27. i3.open()
  28. def destroy_tmp(tmp_id):
  29. i3.kill(con_id=tmp_id)
  30. def make_float(current_id):
  31. i3.focus(con_id=current_id)
  32. i3.floating('enable')
  33. i3.resize('set 1500 800')
  34. i3.move('position center')
  35. def make_unfloat(current_id):
  36. i3.focus(con_id=current_id)
  37. i3.floating('disable')
  38. def main():
  39. tree = check_output(['i3-msg', '-t', 'get_tree']).decode('UTF-8').strip()
  40. root = json.loads(tree)
  41. current = findWindow(root)
  42. current_id = current['id']
  43. if "on" in current['floating']:
  44. tmp_id = find_tmp(root)
  45. if tmp_id != None:
  46. i3.focus(con_id=tmp_id)
  47. make_unfloat(current_id)
  48. destroy_tmp(tmp_id)
  49. else:
  50. if find_tmp(root) == None:
  51. create_tmp(current_id)
  52. make_float(current_id)
  53. main()