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

117 lines
2.8 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
# "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=
active=
2012-05-27 20:21:14 -04:00
i=
2011-12-07 13:35:22 -05:00
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/')
wprefix='-id '; window="$active"
2011-12-07 13:35:22 -05:00
;;
n) wprefix='-name '; window="$OPTARG" ;;
w) wprefix='-id '; window="$OPTARG" ;;
2011-12-07 13:35:22 -05:00
o) opacity="$OPTARG" ;;
esac
done
# Validate opacity value
if [ -z "$opacity" ]; then
echo "No opacity specified."
exit 1
fi
opacity="$(echo "$opacity" \
| sed -rn 's/^[[:space:]]*([+-]?[[:digit:]]+)[[:space:]]*$/\1/p')"
if [ -z "$opacity" ]; then
echo "Invalid opacity value."
exit 1
fi
# Get ID of the target window
wid=$(xwininfo $wprefix"$window" | sed -n 's/^xwininfo:.*: \(0x[[:xdigit:]]*\).*$/\1/p')
if [ -z "$wid" ]; then
echo "Failed to find window."
exit 1
fi
treeout="$(xwininfo -id "$wid" -children)"
# Make sure it's not root window
if echo "$treeout" | fgrep "Parent window id: 0x0" > /dev/null; then
echo "Cannot set opacity on root window."
exit 1
fi
# Get the whole window tree
treeout="$(xwininfo -root -tree)"
if [ -z "$treeout" ]; then
echo "Failed to get root window tree."
exit 1
fi
# 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)"
2011-12-07 13:35:22 -05:00
if [ -z "$lineno" ]; then
echo "Failed to find window in window tree."
exit 1
2011-12-07 13:35:22 -05:00
fi
# 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)
if [ -z "$topmost" ]; then
echo "Failed to find the highest parent window below root of the" \
"selected window."
exit 1
fi
# Calculate the desired opacity
if echo "$opacity" | grep '^[+-]' > /dev/null; then
sign=$(echo "$opacity" | cut -b1)
cur=$(xprop -id "$topmost" -notype "_NET_WM_WINDOW_OPACITY" \
| sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/')
[ -z "$cur" ] && cur=0xffffffff
cur=$((cur * 100 / 0xffffffff))
opacity="$(echo "$opacity" | sed 's/^[+-]//')"
opacity=$(($cur $sign $opacity))
2011-12-07 13:35:22 -05:00
fi
[ $opacity -lt 0 ] && opacity=0
[ $opacity -gt 100 ] && opacity=100
# Set opacity
opacity=$(($opacity * 0xffffffff / 100))
xprop -id "$topmost" -f _NET_WM_WINDOW_OPACITY 32c \
-set _NET_WM_WINDOW_OPACITY "$opacity"