mirror of https://github.com/artizirk/dotfiles
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.
39 lines
907 B
39 lines
907 B
#!/usr/bin/python3 |
|
# source https://gitlab.com/snippets/1832968 |
|
|
|
import json |
|
from subprocess import Popen, PIPE, run |
|
|
|
|
|
def get_tree(): |
|
proc = run(['swaymsg', '-t', 'get_tree'], capture_output=True) |
|
return json.loads(proc.stdout) |
|
|
|
|
|
def traverse(data, out): |
|
if 'nodes' not in data: |
|
return |
|
|
|
if data['type'] == 'con' and 'window_properties' in data: |
|
props = data['window_properties'] |
|
out.append((f'{props["class"]}: {props["title"]}')) |
|
|
|
for node in data['nodes']: |
|
if 'nodes' in node: |
|
traverse(node, out) |
|
|
|
|
|
def main(): |
|
apps = [] |
|
traverse(get_tree(), apps) |
|
in_data = '\n'.join(apps).encode() |
|
|
|
with Popen(['fzf'], stdout=PIPE, stdin=PIPE) as proc: |
|
stdout, _ = proc.communicate(in_data) |
|
app = stdout.decode().split(':')[1].strip() |
|
|
|
run(['swaymsg', f'[title="{app}"] focus']) |
|
|
|
|
|
if __name__ == '__main__': |
|
main()
|
|
|