Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- from subprocess import check_output
- from json import loads
- from re import findall, DOTALL, MULTILINE
- def find_focused(tree):
- if tree["focused"] == True:
- return tree["pid"]
- elif 'nodes' in tree:
- for n in tree['nodes']:
- pid = find_focused(n)
- if pid: return pid
- inputs = findall(r'.*?index: (\d+).*?sink: (\d+).*?application\.process\.id = "(\d+)"',
- check_output(['pacmd', 'list-sink-inputs']).decode("utf-8"), DOTALL|MULTILINE)
- sinks = findall(r'index: (\d+)', check_output(['pacmd', 'list-sinks']).decode("utf-8"))
- tree = loads(check_output(['swaymsg', '-t', 'get_tree']))
- focused_pid = find_focused(tree)
- for app in inputs:
- if app[2] == str(focused_pid):
- # find new sink index
- index = 0
- for i in range(len(sinks)):
- if sinks[i] == app[1]:
- index = (i + 1) % len(sinks) # rotation
- break
- check_output(['pacmd', 'move-sink-input', app[0], sinks[index] ])
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement