compton-trans: add a 'get' option.

This commit is contained in:
Christopher Jeffrey 2013-05-04 16:37:52 -05:00
parent 86b20e0a08
commit ad23872801
1 changed files with 18 additions and 9 deletions

View File

@ -32,7 +32,7 @@ wprefix=
window= window=
opacity= opacity=
cur= cur=
delete= action=
treeout= treeout=
wid= wid=
topmost= topmost=
@ -48,7 +48,7 @@ while test $# -gt 0; do
LASTIND=1 LASTIND=1
# Read options # Read options
while getopts ':scdn:w:o:' option "$@"; do while getopts ':scdgn:w:o:' option "$@"; do
case "$option" in case "$option" in
s) wprefix=''; window='' ;; s) wprefix=''; window='' ;;
c) c)
@ -56,7 +56,8 @@ while test $# -gt 0; do
| sed 's/^.*\(0x\S*\).*$/\1/') | sed 's/^.*\(0x\S*\).*$/\1/')
wprefix='-id'; window=$active wprefix='-id'; window=$active
;; ;;
d) delete=1 ;; d) action='delete' ;;
g) action='get' ;;
n) wprefix='-name'; window=$OPTARG ;; n) wprefix='-name'; window=$OPTARG ;;
w) wprefix='-id'; window=$OPTARG ;; w) wprefix='-id'; window=$OPTARG ;;
o) opacity=$OPTARG ;; o) opacity=$OPTARG ;;
@ -81,7 +82,7 @@ done
opacity=$(echo "$opacity" | sed 's/%//g' | xargs) opacity=$(echo "$opacity" | sed 's/%//g' | xargs)
# Validate opacity value # 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." echo "Invalid opacity specified: $opacity."
exit 1 exit 1
fi fi
@ -140,17 +141,25 @@ if test -z "$topmost"; then
fi fi
# Remove the opacity property. # Remove the opacity property.
if test -n "$delete"; then if test x"$action" = x'delete'; then
xprop -id "$topmost" -remove _NET_WM_WINDOW_OPACITY xprop -id "$topmost" -remove _NET_WM_WINDOW_OPACITY
exit 0 exit 0
fi 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 # Calculate the desired opacity
if echo "$opacity" | grep -q '^[+-]'; then 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)) opacity=$(($cur + $opacity))
fi fi