mirror of
https://github.com/artizirk/dotfiles.git
synced 2024-12-25 04:40:16 +02:00
Enable rofi based window switcher
This commit is contained in:
parent
006494eae8
commit
6284af1707
47
.bin/switch_window.py
Executable file
47
.bin/switch_window.py
Executable file
@ -0,0 +1,47 @@
|
||||
#!/bin/env python3
|
||||
# src: https://github.com/varesa/dotfiles/blob/master/.config/sway/switch_window.py
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
|
||||
def handle_container(con):
|
||||
"""
|
||||
Recursively find all windows
|
||||
"""
|
||||
|
||||
windows = []
|
||||
|
||||
if 'app_id' in con.keys():
|
||||
app_id = con['id']
|
||||
app_name = con['app_id'] if con['app_id'] else con['window_properties']['class']
|
||||
app_title = con['name']
|
||||
|
||||
windows.append((app_id, app_name, app_title,))
|
||||
|
||||
for child in con['nodes']:
|
||||
windows = windows + handle_container(child)
|
||||
|
||||
return windows
|
||||
|
||||
|
||||
tree = json.loads(subprocess.check_output(['swaymsg', '-t', 'get_tree']))
|
||||
windows = []
|
||||
|
||||
# Find all workspaces and the windows in them
|
||||
for output in tree['nodes']:
|
||||
for workspace in output['nodes']:
|
||||
if 'nodes' not in workspace.keys():
|
||||
continue
|
||||
|
||||
for container in workspace['nodes']:
|
||||
windows = windows + handle_container(container)
|
||||
for container in workspace['floating_nodes']:
|
||||
windows = windows + handle_container(container)
|
||||
|
||||
# Format the list of windows for dmenu/rofi
|
||||
windows_string = '\n'.join([f"<{app_id}> {app_name} --- {app_title}" for app_id, app_name, app_title in windows])
|
||||
|
||||
# Call rofi and move focus to the selected window
|
||||
selection = subprocess.check_output(['rofi', '-dmenu', '-i', '-p', 'window', '-normal-window', '-font', 'xos4 Terminus 12'], input=windows_string, universal_newlines=True)
|
||||
window_id = selection.split(' ')[0][1:-1]
|
||||
subprocess.call(['swaymsg', f"[con_id=\"{window_id}\"]", 'focus'])
|
@ -71,7 +71,7 @@ exec ~/code/dropbox-filesystem-fix/dropbox_start.py
|
||||
# load xresources
|
||||
exec xrdb -load ~/.Xresources
|
||||
|
||||
#bindsym Alt+Tab exec gnome-terminal --title=swayapplauncher -- ~/.bin/sway-apps.py
|
||||
bindsym Alt+Tab exec ~/.bin/switch_window.py
|
||||
|
||||
### Input configuration
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user