compton-trans: consistency, better bash practices, refactor.
This commit is contained in:
parent
85e7d18803
commit
9a4d202f5d
|
@ -37,35 +37,36 @@ while getopts "scn:w:o:" option; do
|
||||||
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
|
||||||
;;
|
;;
|
||||||
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 ;;
|
||||||
\?) exit 1;;
|
\?) exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Read positional arguments
|
# Read positional arguments
|
||||||
shift $(($OPTIND - 1))
|
shift $(($OPTIND - 1))
|
||||||
[ -n "$1" ] && opacity="$1"
|
test -n "$1" && opacity=$1
|
||||||
|
|
||||||
# Validate opacity value
|
# Validate opacity value
|
||||||
if [ -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" \
|
opacity=$(echo "$opacity" \
|
||||||
| sed -rn 's/^[[:space:]]*([+-]?[[:digit:]]+)[[:space:]]*$/\1/p')"
|
| sed 's/%//g' \
|
||||||
|
| sed -rn 's/^[[:space:]]*([+-]?[[:digit:]]+)[[:space:]]*$/\1/p')
|
||||||
|
|
||||||
if [ -z "$opacity" ]; then
|
if test -z "$opacity"; then
|
||||||
echo "Invalid opacity value."
|
echo "Invalid opacity value."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get ID of the target window
|
# Get ID of the target window
|
||||||
if [ -z "$wprefix" ]; then
|
if test -z "$wprefix"; then
|
||||||
treeout=$(xwininfo -children -frame)
|
treeout=$(xwininfo -children -frame)
|
||||||
else
|
else
|
||||||
treeout=$(xwininfo -children $wprefix "$window")
|
treeout=$(xwininfo -children $wprefix "$window")
|
||||||
|
@ -73,7 +74,7 @@ fi
|
||||||
|
|
||||||
wid=$(echo "$treeout" | sed -n 's/^xwininfo:.*: \(0x[[:xdigit:]]*\).*$/\1/p')
|
wid=$(echo "$treeout" | sed -n 's/^xwininfo:.*: \(0x[[:xdigit:]]*\).*$/\1/p')
|
||||||
|
|
||||||
if [ -z "$wid" ]; then
|
if test -z "$wid"; then
|
||||||
echo "Failed to find window."
|
echo "Failed to find window."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -86,29 +87,31 @@ 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 [ -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
|
||||||
|
|
||||||
# Find the line number of the target window in the window tree
|
# Find the line number of the target window in the window tree
|
||||||
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 [ -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" | head -n $(($lineno + 1)) | sed -n 's/^ \(0x[[:xdigit:]]*\).*/\1/p' | tail -n1)
|
topmost=$(echo -n "$treeout" \
|
||||||
|
| head -n $(($lineno + 1)) \
|
||||||
|
| sed -n 's/^ \(0x[[:xdigit:]]*\).*/\1/p' | tail -n1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -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
|
||||||
|
@ -116,19 +119,17 @@ fi
|
||||||
|
|
||||||
# Calculate the desired opacity
|
# Calculate the desired opacity
|
||||||
if echo "$opacity" | grep '^[+-]' > /dev/null; then
|
if echo "$opacity" | grep '^[+-]' > /dev/null; then
|
||||||
sign=$(echo "$opacity" | cut -b1)
|
|
||||||
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/')
|
||||||
[ -z "$cur" ] && cur=0xffffffff
|
test -z "$cur" && cur=0xffffffff
|
||||||
cur=$((cur * 100 / 0xffffffff))
|
cur=$((cur * 100 / 0xffffffff))
|
||||||
opacity="$(echo "$opacity" | sed 's/^[+-]//')"
|
opacity=$(($cur + $opacity))
|
||||||
opacity=$(($cur $sign $opacity))
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ $opacity -lt 0 ] && opacity=0
|
test $opacity -lt 0 && opacity=0
|
||||||
[ $opacity -gt 100 ] && opacity=100
|
test $opacity -gt 100 && opacity=100
|
||||||
|
|
||||||
# Set opacity
|
# Set opacity
|
||||||
opacity=$(($opacity * 0xffffffff / 100))
|
opacity=$((opacity * 0xffffffff / 100))
|
||||||
xprop -id "$topmost" -f _NET_WM_WINDOW_OPACITY 32c \
|
xprop -id "$topmost" -f _NET_WM_WINDOW_OPACITY 32c \
|
||||||
-set _NET_WM_WINDOW_OPACITY "$opacity"
|
-set _NET_WM_WINDOW_OPACITY "$opacity"
|
||||||
|
|
Loading…
Reference in New Issue