improvements to trans script

This commit is contained in:
Christopher Jeffrey 2011-12-21 13:28:55 -06:00
parent 1e2bb55744
commit 5206eaba74
1 changed files with 19 additions and 15 deletions

34
trans
View File

@ -12,9 +12,13 @@
#trans -c -o 75 #trans -c -o 75
# by selection # by selection
#trans -s -o 75 #trans -s -o 75
# increment current window 5%
#trans -c -o +5
[ -z "$(which xprop)" ] && \ if [ -z "$(which xprop)" -o -z "$(which xwininfo)" ]; then
echo "Please install x11-utils/xorg-xprop." echo "Please install x11-utils/xorg-xprop/xorg-xwininfo." >&2
exit 1
fi
window= window=
opacity= opacity=
@ -27,8 +31,7 @@ while getopts "scn:w:o:" OPTION; do
case "$OPTION" in case "$OPTION" in
s) window="" ;; s) window="" ;;
c) c)
active=$(xprop -root -notype \ active=$(xprop -root -notype "_NET_ACTIVE_WINDOW" \
| grep "_NET_ACTIVE_WINDOW:" \
| sed 's/^.*\(0x\S*\).*$/\1/') | sed 's/^.*\(0x\S*\).*$/\1/')
window="-id $active" window="-id $active"
;; ;;
@ -38,25 +41,26 @@ while getopts "scn:w:o:" OPTION; do
esac esac
done done
# should probably use a while loop
# to get the toplevel window
parent=$(xwininfo -all $window \
| grep Parent \
| sed 's/^.*\(0x\S*\).*$/\1/')
root=$(xwininfo -all -root \ root=$(xwininfo -all -root \
| grep "Root window id" \ | grep "Root window id" \
| sed 's/^.*\(0x\S*\).*$/\1/') | sed 's/^.*\(0x\S*\).*$/\1/')
if [ "$parent" != "$root" ]; then parent=$window
window="-id $parent" while [ true ]; do
fi parent=$(xwininfo -all $parent \
| grep Parent \
| sed 's/^.*\(0x\S*\).*$/\1/')
if [ "$parent" = "$root" ]; then
break
fi
parent="-id $parent"
window=$parent
done
inc=$(echo "$opacity" | sed 's/^\(+\|-\).*$\|^.*$/\1/') inc=$(echo "$opacity" | sed 's/^\(+\|-\).*$\|^.*$/\1/')
if [ -n "$inc" ]; then if [ -n "$inc" ]; then
cur=$(xprop $window -notype "_NET_WM_WINDOW_OPACITY" \ cur=$(xprop $window -notype "_NET_WM_WINDOW_OPACITY" \
| sed 's/^.*\([0-9]\+\).*$\|^.*$/\1/') | sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/')
[ -z "$cur" ] && cur=$((0xffffffff)) [ -z "$cur" ] && cur=$((0xffffffff))
cur=$((cur*100/0xffffffff)) cur=$((cur*100/0xffffffff))
opacity=$(echo "$opacity" | sed 's/\(\+\|\-\)//') opacity=$(echo "$opacity" | sed 's/\(\+\|\-\)//')