picom/bin/settrans

92 lines
2.0 KiB
Plaintext
Raw Normal View History

2011-12-07 18:35:22 +00:00
#!/bin/bash
# transset in a bash script
2012-04-01 04:54:42 +00:00
# Copyright (c) 2011-2012, Christopher Jeffrey
2011-12-07 18:35:22 +00:00
2012-04-01 04:54:42 +00:00
# Usage:
2011-12-07 18:35:22 +00:00
# by window id
2012-04-01 04:54:42 +00:00
# settrans -w "$WINDOWID" -o 75
2011-12-07 18:35:22 +00:00
# by name
2012-04-01 04:54:42 +00:00
# settrans -n "urxvt" -o 75
2011-12-07 18:35:22 +00:00
# by current window
2012-04-01 04:54:42 +00:00
# settrans -c -o 75
2011-12-07 18:35:22 +00:00
# by selection
2012-04-01 04:54:42 +00:00
# settrans -s -o 75
2011-12-21 19:28:55 +00:00
# increment current window 5%
2012-04-01 04:54:42 +00:00
# settrans -c -o +5
2011-12-07 18:35:22 +00:00
2012-04-01 04:54:42 +00:00
if test -z "$(which xprop)" -o -z "$(which xwininfo)"; then
2011-12-21 19:28:55 +00:00
echo "Please install x11-utils/xorg-xprop/xorg-xwininfo." >&2
exit 1
fi
2011-12-07 18:35:22 +00:00
window=
opacity=
cur=
root=
parent=
active=
2012-02-06 08:16:49 +00:00
while getopts "scn:w:o:" option; do
case "$option" in
2011-12-07 18:35:22 +00:00
s) window="" ;;
c)
2011-12-21 19:28:55 +00:00
active=$(xprop -root -notype "_NET_ACTIVE_WINDOW" \
2011-12-07 18:35:22 +00: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-21 19:28:55 +00:00
parent=$window
2012-04-01 04:54:42 +00:00
i=0
while true; do
2011-12-21 19:28:55 +00:00
parent=$(xwininfo -all $parent \
| grep Parent \
| sed 's/^.*\(0x\S*\).*$/\1/')
2012-04-01 04:54:42 +00:00
2011-12-21 19:28:55 +00:00
if [ "$parent" = "$root" ]; then
break
fi
2012-04-01 04:54:42 +00:00
2011-12-21 19:28:55 +00:00
parent="-id $parent"
window=$parent
2012-04-01 04:54:42 +00:00
i=$((i+1))
if test $i -ge 1000; then
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
exit 1
fi
2011-12-21 19:28:55 +00:00
done
2011-12-07 18:35:22 +00:00
inc=$(echo "$opacity" | sed 's/^\(+\|-\).*$\|^.*$/\1/')
2012-04-01 04:54:42 +00:00
if test -n "$inc"; then
2011-12-07 18:35:22 +00:00
cur=$(xprop $window -notype "_NET_WM_WINDOW_OPACITY" \
2011-12-21 19:28:55 +00:00
| sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/')
2012-04-01 04:54:42 +00:00
test -z "$cur" && cur=$((0xffffffff))
2011-12-07 18:35:22 +00:00
cur=$((cur*100/0xffffffff))
opacity=$(echo "$opacity" | sed 's/\(\+\|\-\)//')
2012-04-01 04:54:42 +00:00
if test "$inc" = "+"; then
2011-12-07 18:35:22 +00:00
opacity=$((cur+opacity))
else
opacity=$((cur-opacity))
fi
fi
2012-04-01 04:54:42 +00:00
if test -n "$opacity" -a -n "$window"; then
test $opacity -lt 0 && opacity=0
test $opacity -gt 100 && opacity=100
2011-12-07 18:35:22 +00:00
opacity=$((opacity*0xffffffff/100))
xprop $window -f _NET_WM_WINDOW_OPACITY 32c \
-set _NET_WM_WINDOW_OPACITY "$opacity"
fi