Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions overlay_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@ def get_active_pid():
global last_pid_error
global last_pid_error_time

session_type = os.environ.get("XDG_SESSION_TYPE", "")
current_desktop = os.environ.get("XDG_CURRENT_DESKTOP", "").lower()

# Wayland compositors
if session_type == "wayland":
match current_desktop:
case desktop if "hyprland" in desktop or os.environ.get("HYPRLAND_INSTANCE_SIGNATURE"):
try:
result = subprocess.check_output(
"hyprctl activewindow | grep -oP 'pid: \\K\\d+'",
shell=True,
stderr=subprocess.DEVNULL,
)
return int(result.strip())
except (subprocess.CalledProcessError, ValueError, FileNotFoundError) as exc:
now = time.time()
error_key = ("hyprctl", str(exc))
if last_pid_error != error_key or now - last_pid_error_time > 5:
safe_log_error(f"could not get active window from hyprctl: {exc}")
last_pid_error = error_key
last_pid_error_time = now
return None

case _:
if last_pid_error != "wayland_unsupported":
safe_log_error(f"Wayland compositor '{current_desktop}' not supported yet. Currently supported: Hyprland")
last_pid_error = "wayland_unsupported"
return None

# X11 fallback
try:
result = subprocess.check_output(
["xdotool", "getwindowfocus", "getwindowpid"],
Expand Down
9 changes: 6 additions & 3 deletions start_overlay.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ if [[ -x "$ROOT_DIR/venv/bin/python" ]]; then
PYTHON_BIN="$ROOT_DIR/venv/bin/python"
fi

if ! command -v xdotool >/dev/null 2>&1; then
echo "xdotool is required. Install it first and then run this script again." >&2
exit 1
# Only require xdotool on X11 (not on Wayland)
if [[ "${XDG_SESSION_TYPE:-}" != "wayland" ]]; then
if ! command -v xdotool >/dev/null 2>&1; then
echo "xdotool is required for X11. Install it first and then run this script again." >&2
exit 1
fi
fi

exec "$PYTHON_BIN" "$ROOT_DIR/overlay_design.py"