Files
dotfiles/eww/scripts/get-active-window.sh
2026-04-23 05:43:05 +02:00

33 lines
764 B
Bash
Executable File

#!/usr/bin/env bash
OUTPUT="${1:-DP-2}"
get_socket() {
local runtime="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
local sig
sig=$(ls "$runtime/hypr/" 2>/dev/null | head -n1)
echo "$runtime/hypr/$sig/.socket2.sock"
}
emit() {
local monitor_ws title
monitor_ws=$(hyprctl monitors -j 2>/dev/null \
| jq -r ".[] | select(.name==\"$OUTPUT\") | .activeWorkspace.id")
title=$(hyprctl clients -j 2>/dev/null \
| jq -r ".[] | select(.workspace.id==$monitor_ws and .focusHistoryID==0) | .title" \
| head -n1)
printf '%s\n' "${title:-}"
}
emit
SOCKET=$(get_socket)
socat -u "UNIX-CONNECT:$SOCKET" - \
| stdbuf -oL grep -E "^(activewindow|focusedmon|workspace|closewindow)>" \
| while IFS= read -r _; do
sleep 0.05
emit
done