Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. from subprocess import check_output
  4. from json import loads
  5. from re import findall, DOTALL, MULTILINE
  6.  
  7. def find_focused(tree):
  8. if tree["focused"] == True:
  9. return tree["pid"]
  10. elif 'nodes' in tree:
  11. for n in tree['nodes']:
  12. pid = find_focused(n)
  13. if pid: return pid
  14.  
  15. inputs = findall(r'.*?index: (\d+).*?sink: (\d+).*?application\.process\.id = "(\d+)"',
  16. check_output(['pacmd', 'list-sink-inputs']).decode("utf-8"), DOTALL|MULTILINE)
  17. sinks = findall(r'index: (\d+)', check_output(['pacmd', 'list-sinks']).decode("utf-8"))
  18. tree = loads(check_output(['swaymsg', '-t', 'get_tree']))
  19.  
  20. focused_pid = find_focused(tree)
  21.  
  22. for app in inputs:
  23. if app[2] == str(focused_pid):
  24. # find new sink index
  25. index = 0
  26. for i in range(len(sinks)):
  27. if sinks[i] == app[1]:
  28. index = (i + 1) % len(sinks) # rotation
  29. break
  30. check_output(['pacmd', 'move-sink-input', app[0], sinks[index] ])
  31. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement