From ad23872801d6135e87234159e861d46667dbaee2 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 4 May 2013 16:37:52 -0500 Subject: [PATCH] compton-trans: add a 'get' option. --- bin/compton-trans | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/bin/compton-trans b/bin/compton-trans index c352128..baf99e4 100755 --- a/bin/compton-trans +++ b/bin/compton-trans @@ -32,7 +32,7 @@ wprefix= window= opacity= cur= -delete= +action= treeout= wid= topmost= @@ -48,7 +48,7 @@ while test $# -gt 0; do LASTIND=1 # Read options - while getopts ':scdn:w:o:' option "$@"; do + while getopts ':scdgn:w:o:' option "$@"; do case "$option" in s) wprefix=''; window='' ;; c) @@ -56,7 +56,8 @@ while test $# -gt 0; do | sed 's/^.*\(0x\S*\).*$/\1/') wprefix='-id'; window=$active ;; - d) delete=1 ;; + d) action='delete' ;; + g) action='get' ;; n) wprefix='-name'; window=$OPTARG ;; w) wprefix='-id'; window=$OPTARG ;; o) opacity=$OPTARG ;; @@ -81,7 +82,7 @@ done opacity=$(echo "$opacity" | sed 's/%//g' | xargs) # Validate opacity value -if test -z "$delete" && ! echo "$opacity" | grep -q '^[+-]\?[0-9]\+$'; then +if test -z "$action" && ! echo "$opacity" | grep -q '^[+-]\?[0-9]\+$'; then echo "Invalid opacity specified: $opacity." exit 1 fi @@ -140,17 +141,25 @@ if test -z "$topmost"; then fi # Remove the opacity property. -if test -n "$delete"; then +if test x"$action" = x'delete'; then xprop -id "$topmost" -remove _NET_WM_WINDOW_OPACITY exit 0 fi +# Get current opacity. +cur=$(xprop -id "$topmost" -notype _NET_WM_WINDOW_OPACITY \ + | sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/') +test -z "$cur" && cur=0xffffffff +cur=$((cur * 100 / 0xffffffff)) + +# Output current opacity. +if test x"$action" = x'get'; then + echo "$cur" + exit 0 +fi + # Calculate the desired opacity if echo "$opacity" | grep -q '^[+-]'; then - cur=$(xprop -id "$topmost" -notype _NET_WM_WINDOW_OPACITY \ - | sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/') - test -z "$cur" && cur=0xffffffff - cur=$((cur * 100 / 0xffffffff)) opacity=$(($cur + $opacity)) fi