1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-11-18 13:55:36 -05:00

compton-trans: more consistency.

This commit is contained in:
Christopher Jeffrey 2013-05-04 13:34:34 -05:00
parent 9a4d202f5d
commit 054d343622

View file

@ -21,7 +21,7 @@
# "command" is a shell built-in, faster than "which" # "command" is a shell built-in, faster than "which"
if test -z "$(command -v xprop)" -o -z "$(command -v xwininfo)"; then if test -z "$(command -v xprop)" -o -z "$(command -v xwininfo)"; then
echo "Please install x11-utils/xorg-xprop/xorg-xwininfo." >& 2 echo 'Please install x11-utils/xorg-xprop/xorg-xwininfo.' >& 2
exit 1 exit 1
fi fi
@ -31,11 +31,11 @@ cur=
i= i=
# Read options # Read options
while getopts "scn:w:o:" option; do while getopts 'scn:w:o:' option; do
case "$option" in case "$option" in
s) wprefix=''; window='' ;; s) wprefix=''; window='' ;;
c) c)
active=$(xprop -root -notype "_NET_ACTIVE_WINDOW" \ active=$(xprop -root -notype _NET_ACTIVE_WINDOW \
| sed 's/^.*\(0x\S*\).*$/\1/') | sed 's/^.*\(0x\S*\).*$/\1/')
wprefix='-id'; window=$active wprefix='-id'; window=$active
;; ;;
@ -52,16 +52,16 @@ test -n "$1" && opacity=$1
# Validate opacity value # Validate opacity value
if test -z "$opacity"; then if test -z "$opacity"; then
echo "No opacity specified." echo 'No opacity specified.'
exit 1 exit 1
fi fi
opacity=$(echo "$opacity" \ # clean up opacity. xargs == a poor man's trim.
| sed 's/%//g' \ opacity=$(echo "$opacity" | sed 's/%//g' | xargs)
| sed -rn 's/^[[:space:]]*([+-]?[[:digit:]]+)[[:space:]]*$/\1/p') #opacity=$(echo "$opacity" | sed 's/%//g' | sed 's/^ \+\| \+$//g')
if test -z "$opacity"; then if test -z "$opacity"; then
echo "Invalid opacity value." echo 'Invalid opacity value.'
exit 1 exit 1
fi fi
@ -75,25 +75,25 @@ fi
wid=$(echo "$treeout" | sed -n 's/^xwininfo:.*: \(0x[[:xdigit:]]*\).*$/\1/p') wid=$(echo "$treeout" | sed -n 's/^xwininfo:.*: \(0x[[:xdigit:]]*\).*$/\1/p')
if test -z "$wid"; then if test -z "$wid"; then
echo "Failed to find window." echo 'Failed to find window.'
exit 1 exit 1
fi fi
# Make sure it's not root window # Make sure it's not root window
if echo "$treeout" | fgrep "Parent window id: 0x0" > /dev/null; then if echo "$treeout" | fgrep 'Parent window id: 0x0' > /dev/null; then
echo "Cannot set opacity on root window." echo 'Cannot set opacity on root window.'
exit 1 exit 1
fi fi
# If it's already the topmost window # If it's already the topmost window
if echo "$treeout" | grep "Parent window id: 0x[[:xdigit:]]* (the root window)" > /dev/null; then if echo "$treeout" | grep 'Parent window id: 0x[[:xdigit:]]* (the root window)' > /dev/null; then
topmost=$wid topmost=$wid
else else
# Get the whole window tree # Get the whole window tree
treeout=$(xwininfo -root -tree) treeout=$(xwininfo -root -tree)
if test -z "$treeout"; then if test -z "$treeout"; then
echo "Failed to get root window tree." echo 'Failed to get root window tree.'
exit 1 exit 1
fi fi
@ -101,25 +101,26 @@ else
lineno=$(echo -n "$treeout" | grep -nw "$wid" | head -n1 | cut -d ':' -f 1) lineno=$(echo -n "$treeout" | grep -nw "$wid" | head -n1 | cut -d ':' -f 1)
if test -z "$lineno"; then if test -z "$lineno"; then
echo "Failed to find window in window tree." echo 'Failed to find window in window tree.'
exit 1 exit 1
fi fi
# Find the highest ancestor of the target window below # Find the highest ancestor of the target window below
topmost=$(echo -n "$treeout" \ topmost=$(echo -n "$treeout" \
| head -n $(($lineno + 1)) \ | head -n $(($lineno + 1)) \
| sed -n 's/^ \(0x[[:xdigit:]]*\).*/\1/p' | tail -n1) | sed -n 's/^ \(0x[[:xdigit:]]*\).*/\1/p' \
| tail -n 1)
fi fi
if test -z "$topmost"; then if test -z "$topmost"; then
echo "Failed to find the highest parent window below root of the" \ echo 'Failed to find the highest parent window below root of the' \
"selected window." 'selected window.'
exit 1 exit 1
fi fi
# Calculate the desired opacity # Calculate the desired opacity
if echo "$opacity" | grep '^[+-]' > /dev/null; then if echo "$opacity" | grep '^[+-]' > /dev/null; then
cur=$(xprop -id "$topmost" -notype "_NET_WM_WINDOW_OPACITY" \ cur=$(xprop -id "$topmost" -notype _NET_WM_WINDOW_OPACITY \
| sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/') | sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/')
test -z "$cur" && cur=0xffffffff test -z "$cur" && cur=0xffffffff
cur=$((cur * 100 / 0xffffffff)) cur=$((cur * 100 / 0xffffffff))