feat: automatic zawarudo window freeze/unfreeze on unfocus/focus

This commit is contained in:
2025-07-12 01:29:33 +03:00
parent 0fb10b7842
commit 4905eaa447
2 changed files with 72 additions and 1 deletions

View File

@@ -495,7 +495,7 @@ bind = $mainMod CTRL, W, exec, ~/.config/hypr/scripts/close_marked.sh
bind = $mainMod, Y, exec, ~/.config/hypr/scripts/move_marked.sh
# Freeze window
bind = $mainMod SHIFT, F, exec, hyprfreeze -a -s
bind = $mainMod SHIFT, T, exec, hyprfreeze -a -s
bind = $mainMod SHIFT, F, tagwindow, zawarudo
# Lock screen

71
hypr/scripts/autofreezer.sh Executable file
View File

@@ -0,0 +1,71 @@
#!/usr/bin/env bash
# Variable to store the last focused window address
last_focused_window=""
current_window=""
function handle {
if [[ ${1:0:14} == "activewindowv2" ]]; then
new_window="${1:16}"
# Update window tracking
last_focused_window="${current_window}"
current_window="${new_window}"
# Get all window information once
window_info=$(hyprctl clients)
# Process last focused window (unfocused)
if [[ -n "$last_focused_window" ]]; then
# Extract tags
tags=$(echo "$window_info" | awk -v addr="$last_focused_window" '
$0 ~ "Window " addr {found=1}
found && /tags:/ {print $0; found=0; exit}
' | sed 's/.*tags: //;s/)//')
# Extract PID
pid=$(echo "$window_info" | awk -v addr="$last_focused_window" '
$0 ~ "Window " addr {found=1}
found && /pid:/ {print $2; found=0; exit}
')
echo tags are $tags and pid is $pid
# Process if window has zawarudo tag
echo "qualify 4 freeze: $tags and $pid"
if [[ -n "$tags" && -n "$pid" ]]; then
if [[ "$tags" == *"zawarudo"* ]]; then
echo freeze $current_pid
kill -STOP $pid 2>/dev/null
fi
fi
fi
# Process current focused window
if [[ -n "$current_window" ]]; then
# Extract tags
current_tags=$(echo "$window_info" | awk -v addr="$current_window" '
$0 ~ "Window " addr {found=1}
found && /tags:/ {print $0; found=0; exit}
' | sed 's/.*tags: //;s/)//')
# Extract PID
current_pid=$(echo "$window_info" | awk -v addr="$current_window" '
$0 ~ "Window " addr {found=1}
found && /pid:/ {print $2; found=0; exit}
')
# Process if window has zawarudo tag
echo "qualify 2 unfreeze: $current_tags and $current_pid"
if [[ -n "$current_tags" && -n "$current_pid" ]]; then
if [[ "$current_tags" == *"zawarudo"* ]]; then
echo unfreeze $current_pid
kill -CONT $current_pid 2>/dev/null
fi
fi
fi
fi
}
# Listen for events
socat - "UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" | while read -r line; do handle "$line"; done