From 0d216d3d9d7f79ab0f31b26607b37c486c779b71 Mon Sep 17 00:00:00 2001 From: Nikolai Papin Date: Sat, 12 Jul 2025 03:58:44 +0300 Subject: [PATCH] fix: freezing two windows with the same pid --- hypr/scripts/autofreezer.sh | 47 +++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/hypr/scripts/autofreezer.sh b/hypr/scripts/autofreezer.sh index c65796b..5822c43 100755 --- a/hypr/scripts/autofreezer.sh +++ b/hypr/scripts/autofreezer.sh @@ -15,30 +15,8 @@ function handle { # 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} - ') - - # Process if window has zawarudo tag - 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 + current_pid="" if [[ -n "$current_window" ]]; then # Extract tags current_tags=$(echo "$window_info" | awk -v addr="$current_window" ' @@ -60,6 +38,29 @@ function handle { fi fi fi + + # 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} + ') + + # Process if window has zawarudo tag + if [[ -n "$tags" && -n "$pid" && "$pid" != "$current_pid" ]]; then + if [[ "$tags" == *"zawarudo"* ]]; then + echo freeze $current_pid + kill -STOP $pid 2>/dev/null + fi + fi + fi fi }