57 lines
1.7 KiB
Python
Executable File
57 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import json
|
|
import subprocess
|
|
import os
|
|
|
|
def get_wayland_windows():
|
|
"""
|
|
Since Wayland aggressively isolates window metadata from standard utilities,
|
|
and KWin DBus scripts are restricted on this machine, we check for common
|
|
running GUI applications via `ps` to label the composite pipewire sink.
|
|
"""
|
|
windows = []
|
|
|
|
# Try XWayland fallback first
|
|
try:
|
|
wmctrl_out = subprocess.run(['wmctrl', '-l'], capture_output=True, text=True, timeout=1).stdout
|
|
for line in wmctrl_out.splitlines():
|
|
parts = line.split(maxsplit=3)
|
|
if len(parts) >= 4:
|
|
windows.append({"title": parts[3]})
|
|
except Exception:
|
|
pass
|
|
|
|
# Process scraping for common GUI apps on Wayland
|
|
try:
|
|
ps_out = subprocess.run(['ps', '-eo', 'comm='], capture_output=True, text=True).stdout
|
|
running_procs = ps_out.lower().splitlines()
|
|
|
|
common_apps = {
|
|
'spotify': 'Spotify',
|
|
'discord': 'Discord',
|
|
'chrome': 'Google Chrome',
|
|
'chromium': 'Chromium',
|
|
'firefox': 'Firefox',
|
|
'code': 'VS Code',
|
|
'obsidian': 'Obsidian',
|
|
'telegram': 'Telegram',
|
|
'slack': 'Slack',
|
|
'steam': 'Steam'
|
|
}
|
|
|
|
for proc, name in common_apps.items():
|
|
if proc in running_procs and not any(name in w["title"] for w in windows):
|
|
windows.append({"title": name})
|
|
|
|
except Exception:
|
|
pass
|
|
|
|
# If we found absolutely nothing, provide a generic fallback
|
|
if not windows:
|
|
windows.append({"title": "Wayland Desktop / App"})
|
|
|
|
print(json.dumps(windows))
|
|
|
|
if __name__ == '__main__':
|
|
get_wayland_windows()
|