picom/bin/settrans

93 lines
2.0 KiB
Plaintext
Raw Normal View History

2011-12-08 02:35:22 +08:00
#!/bin/bash
# transset in a bash script
2012-04-01 12:54:42 +08:00
# Copyright (c) 2011-2012, Christopher Jeffrey
2011-12-08 02:35:22 +08:00
2012-04-01 12:54:42 +08:00
# Usage:
2011-12-08 02:35:22 +08:00
# by window id
2012-04-01 12:54:42 +08:00
# settrans -w "$WINDOWID" -o 75
2011-12-08 02:35:22 +08:00
# by name
2012-04-01 12:54:42 +08:00
# settrans -n "urxvt" -o 75
2011-12-08 02:35:22 +08:00
# by current window
2012-04-01 12:54:42 +08:00
# settrans -c -o 75
2011-12-08 02:35:22 +08:00
# by selection
2012-04-01 12:54:42 +08:00
# settrans -s -o 75
2011-12-22 03:28:55 +08:00
# increment current window 5%
2012-04-01 12:54:42 +08:00
# settrans -c -o +5
2011-12-08 02:35:22 +08:00
2012-04-01 12:54:42 +08:00
if test -z "$(which xprop)" -o -z "$(which xwininfo)"; then
2012-05-28 08:21:14 +08:00
echo "Please install x11-utils/xorg-xprop/xorg-xwininfo." >& 2
2011-12-22 03:28:55 +08:00
exit 1
fi
2011-12-08 02:35:22 +08:00
window=
opacity=
cur=
root=
parent=
active=
2012-05-28 08:21:14 +08:00
i=
2011-12-08 02:35:22 +08:00
2012-02-06 16:16:49 +08:00
while getopts "scn:w:o:" option; do
case "$option" in
2011-12-08 02:35:22 +08:00
s) window="" ;;
c)
2011-12-22 03:28:55 +08:00
active=$(xprop -root -notype "_NET_ACTIVE_WINDOW" \
2011-12-08 02:35:22 +08:00
| sed 's/^.*\(0x\S*\).*$/\1/')
window="-id $active"
;;
n) window="-name $OPTARG" ;;
w) window="-id $OPTARG" ;;
o) opacity="$OPTARG" ;;
esac
done
root=$(xwininfo -all -root \
| grep "Root window id" \
| sed 's/^.*\(0x\S*\).*$/\1/')
2011-12-22 03:28:55 +08:00
parent=$window
2012-04-01 12:54:42 +08:00
i=0
while true; do
2011-12-22 03:28:55 +08:00
parent=$(xwininfo -all $parent \
| grep Parent \
| sed 's/^.*\(0x\S*\).*$/\1/')
2012-04-01 12:54:42 +08:00
2012-05-28 08:21:14 +08:00
if test "$parent" = "$root"; then
2011-12-22 03:28:55 +08:00
break
fi
2012-04-01 12:54:42 +08:00
2011-12-22 03:28:55 +08:00
parent="-id $parent"
window=$parent
2012-04-01 12:54:42 +08:00
i=$((i+1))
if test $i -ge 1000; then
2012-05-28 08:21:14 +08:00
echo "An error occurred while traversing up the window tree." >& 2
echo "Please report this to https://github.com/chjj/compton/issues." >& 2
echo "Please mention your WM and versions of xwininfo/xprop." >& 2
2012-04-01 12:54:42 +08:00
exit 1
fi
2011-12-22 03:28:55 +08:00
done
2011-12-08 02:35:22 +08:00
inc=$(echo "$opacity" | sed 's/^\(+\|-\).*$\|^.*$/\1/')
2012-04-01 12:54:42 +08:00
if test -n "$inc"; then
2011-12-08 02:35:22 +08:00
cur=$(xprop $window -notype "_NET_WM_WINDOW_OPACITY" \
2011-12-22 03:28:55 +08:00
| sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/')
2012-04-01 12:54:42 +08:00
test -z "$cur" && cur=$((0xffffffff))
2011-12-08 02:35:22 +08:00
cur=$((cur*100/0xffffffff))
opacity=$(echo "$opacity" | sed 's/\(\+\|\-\)//')
2012-04-01 12:54:42 +08:00
if test "$inc" = "+"; then
2011-12-08 02:35:22 +08:00
opacity=$((cur+opacity))
else
opacity=$((cur-opacity))
fi
fi
2012-04-01 12:54:42 +08:00
if test -n "$opacity" -a -n "$window"; then
test $opacity -lt 0 && opacity=0
test $opacity -gt 100 && opacity=100
2011-12-08 02:35:22 +08:00
opacity=$((opacity*0xffffffff/100))
xprop $window -f _NET_WM_WINDOW_OPACITY 32c \
-set _NET_WM_WINDOW_OPACITY "$opacity"
fi