refactor settrans
This commit is contained in:
parent
24bf591bd7
commit
d52f7a06db
41
bin/settrans
41
bin/settrans
|
@ -1,21 +1,21 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# transset in a bash script
|
# transset in a bash script
|
||||||
# copyright (c) 2011-2012, christopher jeffrey
|
# Copyright (c) 2011-2012, Christopher Jeffrey
|
||||||
|
|
||||||
# usage:
|
# Usage:
|
||||||
# by window id
|
# by window id
|
||||||
#trans -w "$WINDOWID" -o 75
|
# settrans -w "$WINDOWID" -o 75
|
||||||
# by name
|
# by name
|
||||||
#trans -n "urxvt" -o 75
|
# settrans -n "urxvt" -o 75
|
||||||
# by current window
|
# by current window
|
||||||
#trans -c -o 75
|
# settrans -c -o 75
|
||||||
# by selection
|
# by selection
|
||||||
#trans -s -o 75
|
# settrans -s -o 75
|
||||||
# increment current window 5%
|
# increment current window 5%
|
||||||
#trans -c -o +5
|
# settrans -c -o +5
|
||||||
|
|
||||||
if [ -z "$(which xprop)" -o -z "$(which xwininfo)" ]; then
|
if test -z "$(which xprop)" -o -z "$(which xwininfo)"; then
|
||||||
echo "Please install x11-utils/xorg-xprop/xorg-xwininfo." >&2
|
echo "Please install x11-utils/xorg-xprop/xorg-xwininfo." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -46,34 +46,45 @@ root=$(xwininfo -all -root \
|
||||||
| sed 's/^.*\(0x\S*\).*$/\1/')
|
| sed 's/^.*\(0x\S*\).*$/\1/')
|
||||||
|
|
||||||
parent=$window
|
parent=$window
|
||||||
while [ true ]; do
|
i=0
|
||||||
|
while true; do
|
||||||
parent=$(xwininfo -all $parent \
|
parent=$(xwininfo -all $parent \
|
||||||
| grep Parent \
|
| grep Parent \
|
||||||
| sed 's/^.*\(0x\S*\).*$/\1/')
|
| sed 's/^.*\(0x\S*\).*$/\1/')
|
||||||
|
|
||||||
if [ "$parent" = "$root" ]; then
|
if [ "$parent" = "$root" ]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
parent="-id $parent"
|
parent="-id $parent"
|
||||||
window=$parent
|
window=$parent
|
||||||
|
|
||||||
|
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
|
||||||
done
|
done
|
||||||
|
|
||||||
inc=$(echo "$opacity" | sed 's/^\(+\|-\).*$\|^.*$/\1/')
|
inc=$(echo "$opacity" | sed 's/^\(+\|-\).*$\|^.*$/\1/')
|
||||||
if [ -n "$inc" ]; then
|
if test -n "$inc"; then
|
||||||
cur=$(xprop $window -notype "_NET_WM_WINDOW_OPACITY" \
|
cur=$(xprop $window -notype "_NET_WM_WINDOW_OPACITY" \
|
||||||
| sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/')
|
| sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/')
|
||||||
[ -z "$cur" ] && cur=$((0xffffffff))
|
test -z "$cur" && cur=$((0xffffffff))
|
||||||
cur=$((cur*100/0xffffffff))
|
cur=$((cur*100/0xffffffff))
|
||||||
opacity=$(echo "$opacity" | sed 's/\(\+\|\-\)//')
|
opacity=$(echo "$opacity" | sed 's/\(\+\|\-\)//')
|
||||||
if [ "$inc" = "+" ]; then
|
if test "$inc" = "+"; then
|
||||||
opacity=$((cur+opacity))
|
opacity=$((cur+opacity))
|
||||||
else
|
else
|
||||||
opacity=$((cur-opacity))
|
opacity=$((cur-opacity))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$opacity" ] && [ -n "$window" ]; then
|
if test -n "$opacity" -a -n "$window"; then
|
||||||
[ $opacity -le 0 ] && opacity=0
|
test $opacity -lt 0 && opacity=0
|
||||||
[ $opacity -ge 100 ] && opacity=100
|
test $opacity -gt 100 && opacity=100
|
||||||
opacity=$((opacity*0xffffffff/100))
|
opacity=$((opacity*0xffffffff/100))
|
||||||
xprop $window -f _NET_WM_WINDOW_OPACITY 32c \
|
xprop $window -f _NET_WM_WINDOW_OPACITY 32c \
|
||||||
-set _NET_WM_WINDOW_OPACITY "$opacity"
|
-set _NET_WM_WINDOW_OPACITY "$opacity"
|
||||||
|
|
Loading…
Reference in New Issue