Files
Arch_Hyprland_dots/.config/blacklayer/event-driven.sh
T
2026-01-18 16:03:05 +03:00

25 lines
731 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Kullanım: event-driven.sh <MONITOR_NAME> <POLL_INTERVAL>
MONITOR="$1"
POLL_INTERVAL="${2:-3}" # default 3s
[ -z "$MONITOR" ] && { echo "Monitor arg missing"; exit 1; }
BASE_DIR="$HOME/.config/blacklayer"
BLACKLAYER_BIN="$BASE_DIR/blacklayer"
STATE_DIR="$BASE_DIR/.blacklayer_state"
STATE_FILE="$STATE_DIR/$MONITOR"
while true; do
sleep "$POLL_INTERVAL"
JSON="$(hyprctl -j monitors 2>/dev/null)"
echo "$JSON" | jq empty >/dev/null 2>&1 || continue
FOCUSED=$(echo "$JSON" | jq -r ".[] | select(.name==\"$MONITOR\") | .focused")
if [ "$FOCUSED" = "true" ]; then
pkill -f "$BLACKLAYER_BIN $MONITOR" >/dev/null 2>&1
echo "false" > "$STATE_FILE"
exit 0
fi
done