first commit
This commit is contained in:
47
waybar/scripts/workspaces_icons.py
Executable file
47
waybar/scripts/workspaces_icons.py
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
icons = {
|
||||
"firefox": "",
|
||||
"kitty": "",
|
||||
"code": "",
|
||||
"nemo": "",
|
||||
"discord": "",
|
||||
"spotify": "",
|
||||
}
|
||||
|
||||
def get_windows():
|
||||
result = subprocess.run(["hyprctl", "clients", "-j"], stdout=subprocess.PIPE)
|
||||
return json.loads(result.stdout)
|
||||
|
||||
def get_workspaces():
|
||||
result = subprocess.run(["hyprctl", "workspaces", "-j"], stdout=subprocess.PIPE)
|
||||
return json.loads(result.stdout)
|
||||
|
||||
def main():
|
||||
windows = get_windows()
|
||||
workspaces = get_workspaces()
|
||||
|
||||
ws_icons = {}
|
||||
|
||||
for ws in workspaces:
|
||||
ws_id = ws["id"]
|
||||
ws_icons[ws_id] = []
|
||||
|
||||
for win in windows:
|
||||
app = win["class"].lower()
|
||||
ws_id = win["workspace"]["id"]
|
||||
icon = icons.get(app, "?")
|
||||
if icon not in ws_icons[ws_id]:
|
||||
ws_icons[ws_id].append(icon)
|
||||
|
||||
output = " ".join(
|
||||
f"{ws}:{''.join(ws_icons[ws])}" for ws in sorted(ws_icons.keys())
|
||||
)
|
||||
|
||||
print(output)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user