From 4905eaa44794297585116d22341a79527f122a09 Mon Sep 17 00:00:00 2001 From: Nikolai Papin Date: Sat, 12 Jul 2025 01:29:33 +0300 Subject: [PATCH] feat: automatic zawarudo window freeze/unfreeze on unfocus/focus --- hypr/hyprland.conf | 2 +- hypr/scripts/autofreezer.sh | 71 +++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100755 hypr/scripts/autofreezer.sh diff --git a/hypr/hyprland.conf b/hypr/hyprland.conf index 44215d3..8e1a434 100644 --- a/hypr/hyprland.conf +++ b/hypr/hyprland.conf @@ -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 diff --git a/hypr/scripts/autofreezer.sh b/hypr/scripts/autofreezer.sh new file mode 100755 index 0000000..3fc9084 --- /dev/null +++ b/hypr/scripts/autofreezer.sh @@ -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