From 132a9791192195274f57c8b685667c690241cae5 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 20 Apr 2020 13:18:36 +0100 Subject: [PATCH] bin/wakey.zsh: Implement the active-window check from Lange's version. This is actually rather annoying, because (unlike `xterm'), `pterm''s announced `WINDOWID' isn't its toplevel, so we have to go digging. In theory I should do a recursive walk, but, well, I don't yet. --- bin/wakey.zsh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bin/wakey.zsh b/bin/wakey.zsh index 41d518a..4d8b2e5 100644 --- a/bin/wakey.zsh +++ b/bin/wakey.zsh @@ -7,6 +7,7 @@ zmodload zsh/datetime __wakey_start=nil __wakey_cmd= : ${LONG_RUNNING_COMMAND_TIMEOUT=10}; export LONG_RUNNING_COMMAND_TIMEOUT +: ${IGNORE_WINDOW_CHECK=nil}; export IGNORE_WINDOW_CHECK : ${LONG_RUNNING_IGNORE_LIST=}; export LONG_RUNNING_IGNORE_LIST __wakey_preexec () { @@ -22,6 +23,7 @@ __wakey_preexec () { __wakey_precmd () { typeset icon head rc=$? cmd suppress=nil + typeset -i 10 win i typeset -F now=$EPOCHREALTIME case $__wakey_start in @@ -29,6 +31,23 @@ __wakey_precmd () { *) if (( now - __wakey_start < LONG_RUNNING_COMMAND_TIMEOUT )); then suppress=t + else + case $IGNORE_WINDOW_CHECK in + t) ;; + *) + win=$(xprop -root _NET_ACTIVE_WINDOW | sed 's/^.*# //') + if (( win == WINDOWID )); then + suppress=t + else + for i in $(xwininfo -children -id $win | + sed -n '/^ *[0-9]\+ child\(ren\)\?[.:]$/,$ { + /^ *\(0x[0-9a-f]\+\) (.*$/s//\1/p + }') + do + if (( i == WINDOWID )) then; suppress=t; break; fi + done + fi + esac fi case $suppress in t) ;; -- 2.11.0