1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-11-25 14:06:08 -05:00
picom/bin/settrans

92 lines
2 KiB
Text
Raw Normal View History

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