summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/xwin_find.sh
diff options
context:
space:
mode:
authorBritney Fransen <brfransen@gmail.com>2013-09-14 21:41:47 (GMT)
committerBritney Fransen <brfransen@gmail.com>2013-09-14 21:41:47 (GMT)
commit3c36d806034f2c63d48bf0d7c577969be4155fb7 (patch)
treef30ff13460e4191261642ca94d7dd84d0a5c931d /abs/core/LinHES-system/xwin_find.sh
parentb96431e7ef2e564879dc1de554d9e36c48f42584 (diff)
downloadlinhes_pkgbuild-3c36d806034f2c63d48bf0d7c577969be4155fb7.zip
linhes_pkgbuild-3c36d806034f2c63d48bf0d7c577969be4155fb7.tar.gz
linhes_pkgbuild-3c36d806034f2c63d48bf0d7c577969be4155fb7.tar.bz2
LinHES-system, linhes-scripts: move idle.sh and xwin_find.sh to LinHES-system.
LinHES-system: add gnu-netcat as dep for idle.sh.
Diffstat (limited to 'abs/core/LinHES-system/xwin_find.sh')
-rw-r--r--abs/core/LinHES-system/xwin_find.sh72
1 files changed, 72 insertions, 0 deletions
diff --git a/abs/core/LinHES-system/xwin_find.sh b/abs/core/LinHES-system/xwin_find.sh
new file mode 100644
index 0000000..35309dd
--- /dev/null
+++ b/abs/core/LinHES-system/xwin_find.sh
@@ -0,0 +1,72 @@
+#!/bin/sh
+#
+# xwin_find [-v|-q] [timeout] window_name_regex
+#
+# Look for a window of the windows full name given by a awk regular
+# expression, and print the windows xwindow ID.
+#
+# If a timeout is given (in seconds)continue to look for the windows ID
+# for this amount of time before returning. (EG default a single search)
+#
+# If no such window is found output nothing, just exit
+#
+# OPTIONS
+# -v verbose, print the full matching xwininfo line on stderr
+# -q do not print windows ID on stdout
+#
+####
+# Anthony Thyssen September 2005
+#
+PROGNAME=`type $0 | awk '{print $3}'` # search for executable on path
+PROGDIR=`dirname $PROGNAME` # extract directory of program
+PROGNAME=`basename $PROGNAME` # base name of program
+Usage() {
+ echo >&2 "$PROGNAME:" "$@"
+ sed >&2 -n '/^###/q; s/^#$/# /; 3s/^#/# Usage:/; 3,$s/^# //p;' \
+ "$PROGDIR/$PROGNAME"
+ exit 10;
+}
+
+timeout=0
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+ [0-9]*) timeout=`date +%s`
+ timeout=`expr $timeout + $1 + 1` || Usage
+ ;;
+ -q) QUIET=true ;; # don't print the final window ID, just status
+ -v) VERBOSE=true ;; # output the full xwininfo line on stderr
+
+ --) shift; break ;; # end of user options
+ -*) Usage "Unknown option \"$1\"" ;;
+ *) break ;; # end of user options
+ esac
+ shift # next option
+done
+
+[ $# -lt 1 ] && Usage "Missing window search regex"
+[ $# -gt 1 ] && Usage "Too many arguments."
+
+
+find_win() {
+ # nice added to let it give way to starting processes
+ if [ "$VERBOSE" ]; then
+ line=`nice xwininfo -root -tree | awk '/"'"$1"'":/ {print; exit}'`
+ echo >&2 $line # VERBOSE - xwininfo output
+ echo "$line" | sed 's/ .*//'
+ else
+ nice xwininfo -root -tree | awk '/"'"$1"'":/ {print $1; exit}'
+ fi
+}
+
+while :; do
+ id=`find_win "$1"`
+ if [ "$id" ]; then
+ [ -z "$QUIET" ] && echo $id # the window ID found
+ exit 0;
+ fi
+ [ `date +%s` -ge $timeout ] && break
+done
+
+exit 1 # window was not found
+