Skip to content

Commit

Permalink
compton-trans: add a 'get' option.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed May 4, 2013
1 parent 86b20e0 commit ad23872
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions bin/compton-trans
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ wprefix=
window=
opacity=
cur=
delete=
action=
treeout=
wid=
topmost=
Expand All @@ -48,15 +48,16 @@ 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)
active=$(xprop -root -notype _NET_ACTIVE_WINDOW \
| 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 ;;
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ad23872

Please sign in to comment.