2013-01-28 11:31:16 -05:00
|
|
|
#!/bin/sh
|
2011-12-07 13:35:22 -05:00
|
|
|
|
2012-11-08 09:30:42 -05:00
|
|
|
#
|
|
|
|
# compton-trans
|
2011-12-07 13:35:22 -05:00
|
|
|
# transset in a bash script
|
2012-04-01 00:54:42 -04:00
|
|
|
# Copyright (c) 2011-2012, Christopher Jeffrey
|
2012-11-08 09:30:42 -05:00
|
|
|
#
|
2011-12-07 13:35:22 -05:00
|
|
|
|
2012-04-01 00:54:42 -04:00
|
|
|
# Usage:
|
2012-11-08 09:30:42 -05:00
|
|
|
# By window id
|
|
|
|
# $ compton-trans -w "$WINDOWID" 75
|
|
|
|
# By name
|
|
|
|
# $ compton-trans -n "urxvt" 75
|
|
|
|
# By current window
|
|
|
|
# $ compton-trans -c 75
|
|
|
|
# By selection
|
|
|
|
# $ compton-trans 75
|
|
|
|
# $ compton-trans -s 75
|
|
|
|
# Increment current window 5%
|
|
|
|
# $ compton-trans -c +5
|
2011-12-07 13:35:22 -05:00
|
|
|
|
2012-11-08 09:34:53 -05:00
|
|
|
# "command" is a shell built-in, faster than "which"
|
|
|
|
if test -z "$(command -v xprop)" -o -z "$(command -v xwininfo)"; then
|
2012-05-27 20:21:14 -04:00
|
|
|
echo "Please install x11-utils/xorg-xprop/xorg-xwininfo." >& 2
|
2011-12-21 14:28:55 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
2011-12-07 13:35:22 -05:00
|
|
|
|
|
|
|
window=
|
|
|
|
opacity=
|
|
|
|
cur=
|
2012-05-27 20:21:14 -04:00
|
|
|
i=
|
2011-12-07 13:35:22 -05:00
|
|
|
|
2012-11-14 05:04:55 -05:00
|
|
|
# Read options
|
2012-02-06 03:16:49 -05:00
|
|
|
while getopts "scn:w:o:" option; do
|
|
|
|
case "$option" in
|
2012-11-11 00:02:14 -05:00
|
|
|
s) wprefix=''; window='' ;;
|
2011-12-07 13:35:22 -05:00
|
|
|
c)
|
2011-12-21 14:28:55 -05:00
|
|
|
active=$(xprop -root -notype "_NET_ACTIVE_WINDOW" \
|
2011-12-07 13:35:22 -05:00
|
|
|
| sed 's/^.*\(0x\S*\).*$/\1/')
|
2013-05-04 14:18:04 -04:00
|
|
|
wprefix='-id'; window=$active
|
2011-12-07 13:35:22 -05:00
|
|
|
;;
|
2013-05-04 14:18:04 -04:00
|
|
|
n) wprefix='-name'; window=$OPTARG ;;
|
|
|
|
w) wprefix='-id'; window=$OPTARG ;;
|
|
|
|
o) opacity=$OPTARG ;;
|
2012-11-14 05:04:55 -05:00
|
|
|
\?) exit 1;;
|
2011-12-07 13:35:22 -05:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2012-11-14 05:04:55 -05:00
|
|
|
# Read positional arguments
|
|
|
|
shift $(($OPTIND - 1))
|
2013-05-04 14:18:04 -04:00
|
|
|
test -n "$1" && opacity=$1
|
2012-11-14 05:04:55 -05:00
|
|
|
|
2012-11-08 09:34:53 -05:00
|
|
|
# Validate opacity value
|
2013-05-04 14:18:04 -04:00
|
|
|
if test -z "$opacity"; then
|
2012-11-14 05:42:09 -05:00
|
|
|
echo "No opacity specified."
|
|
|
|
exit 1
|
2012-11-08 09:34:53 -05:00
|
|
|
fi
|
|
|
|
|
2013-05-04 14:18:04 -04:00
|
|
|
opacity=$(echo "$opacity" \
|
|
|
|
| sed 's/%//g' \
|
|
|
|
| sed -rn 's/^[[:space:]]*([+-]?[[:digit:]]+)[[:space:]]*$/\1/p')
|
2012-11-08 09:34:53 -05:00
|
|
|
|
2013-05-04 14:18:04 -04:00
|
|
|
if test -z "$opacity"; then
|
2012-11-14 05:42:09 -05:00
|
|
|
echo "Invalid opacity value."
|
|
|
|
exit 1
|
2012-11-08 09:34:53 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Get ID of the target window
|
2013-05-04 14:18:04 -04:00
|
|
|
if test -z "$wprefix"; then
|
2012-11-14 05:42:09 -05:00
|
|
|
treeout=$(xwininfo -children -frame)
|
2012-11-08 11:03:22 -05:00
|
|
|
else
|
2013-05-04 14:18:04 -04:00
|
|
|
treeout=$(xwininfo -children $wprefix "$window")
|
2012-11-08 11:03:22 -05:00
|
|
|
fi
|
2012-11-08 09:34:53 -05:00
|
|
|
|
2012-11-11 00:02:14 -05:00
|
|
|
wid=$(echo "$treeout" | sed -n 's/^xwininfo:.*: \(0x[[:xdigit:]]*\).*$/\1/p')
|
|
|
|
|
2013-05-04 14:18:04 -04:00
|
|
|
if test -z "$wid"; then
|
2012-11-14 05:42:09 -05:00
|
|
|
echo "Failed to find window."
|
|
|
|
exit 1
|
2012-11-08 09:34:53 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Make sure it's not root window
|
|
|
|
if echo "$treeout" | fgrep "Parent window id: 0x0" > /dev/null; then
|
2012-11-14 05:42:09 -05:00
|
|
|
echo "Cannot set opacity on root window."
|
|
|
|
exit 1
|
2012-11-08 09:34:53 -05:00
|
|
|
fi
|
|
|
|
|
2012-11-11 00:02:14 -05:00
|
|
|
# If it's already the topmost window
|
|
|
|
if echo "$treeout" | grep "Parent window id: 0x[[:xdigit:]]* (the root window)" > /dev/null; then
|
2013-05-04 14:18:04 -04:00
|
|
|
topmost=$wid
|
2012-11-11 00:02:14 -05:00
|
|
|
else
|
2012-11-14 05:42:09 -05:00
|
|
|
# Get the whole window tree
|
2013-05-04 14:18:04 -04:00
|
|
|
treeout=$(xwininfo -root -tree)
|
2012-11-08 09:34:53 -05:00
|
|
|
|
2013-05-04 14:18:04 -04:00
|
|
|
if test -z "$treeout"; then
|
2012-11-14 05:42:09 -05:00
|
|
|
echo "Failed to get root window tree."
|
2012-04-01 00:54:42 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
2012-11-08 09:34:53 -05:00
|
|
|
|
2012-11-14 05:42:09 -05:00
|
|
|
# Find the line number of the target window in the window tree
|
2013-05-04 14:18:04 -04:00
|
|
|
lineno=$(echo -n "$treeout" | grep -nw "$wid" | head -n1 | cut -d ':' -f 1)
|
2011-12-07 13:35:22 -05:00
|
|
|
|
2013-05-04 14:18:04 -04:00
|
|
|
if test -z "$lineno"; then
|
2012-11-14 05:42:09 -05:00
|
|
|
echo "Failed to find window in window tree."
|
|
|
|
exit 1
|
|
|
|
fi
|
2011-12-07 13:35:22 -05:00
|
|
|
|
2012-11-14 05:42:09 -05:00
|
|
|
# Find the highest ancestor of the target window below
|
2013-05-04 14:18:04 -04:00
|
|
|
topmost=$(echo -n "$treeout" \
|
|
|
|
| head -n $(($lineno + 1)) \
|
|
|
|
| sed -n 's/^ \(0x[[:xdigit:]]*\).*/\1/p' | tail -n1)
|
2012-11-11 00:02:14 -05:00
|
|
|
fi
|
2012-11-08 09:34:53 -05:00
|
|
|
|
2013-05-04 14:18:04 -04:00
|
|
|
if test -z "$topmost"; then
|
2012-11-14 05:42:09 -05:00
|
|
|
echo "Failed to find the highest parent window below root of the" \
|
|
|
|
"selected window."
|
2012-11-08 09:30:42 -05:00
|
|
|
exit 1
|
2012-11-08 09:34:53 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Calculate the desired opacity
|
|
|
|
if echo "$opacity" | grep '^[+-]' > /dev/null; then
|
2012-11-14 05:42:09 -05:00
|
|
|
cur=$(xprop -id "$topmost" -notype "_NET_WM_WINDOW_OPACITY" \
|
2011-12-21 14:28:55 -05:00
|
|
|
| sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/')
|
2013-05-04 14:18:04 -04:00
|
|
|
test -z "$cur" && cur=0xffffffff
|
2012-11-08 09:30:42 -05:00
|
|
|
cur=$((cur * 100 / 0xffffffff))
|
2013-05-04 14:18:04 -04:00
|
|
|
opacity=$(($cur + $opacity))
|
2011-12-07 13:35:22 -05:00
|
|
|
fi
|
2012-11-08 09:34:53 -05:00
|
|
|
|
2013-05-04 14:18:04 -04:00
|
|
|
test $opacity -lt 0 && opacity=0
|
|
|
|
test $opacity -gt 100 && opacity=100
|
2012-11-08 09:34:53 -05:00
|
|
|
|
|
|
|
# Set opacity
|
2013-05-04 14:18:04 -04:00
|
|
|
opacity=$((opacity * 0xffffffff / 100))
|
2012-11-08 09:34:53 -05:00
|
|
|
xprop -id "$topmost" -f _NET_WM_WINDOW_OPACITY 32c \
|
2012-11-14 05:42:09 -05:00
|
|
|
-set _NET_WM_WINDOW_OPACITY "$opacity"
|