2011-12-08 02:35:22 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2012-11-08 22:30:42 +08:00
|
|
|
#
|
|
|
|
# compton-trans
|
2011-12-08 02:35:22 +08:00
|
|
|
# transset in a bash script
|
2012-04-01 12:54:42 +08:00
|
|
|
# Copyright (c) 2011-2012, Christopher Jeffrey
|
2012-11-08 22:30:42 +08:00
|
|
|
#
|
2011-12-08 02:35:22 +08:00
|
|
|
|
2012-04-01 12:54:42 +08:00
|
|
|
# Usage:
|
2012-11-08 22:30:42 +08:00
|
|
|
# By window id
|
|
|
|
# $ compton-trans -w "$WINDOWID" 75
|
|
|
|
# By name
|
|
|
|
# $ compton-trans -n "urxvt" 75
|
|
|
|
# By current window
|
|
|
|
# $ compton-trans -c 75
|
|
|
|
# By selection
|
|
|
|
# $ compton-trans 75
|
|
|
|
# $ compton-trans -s 75
|
|
|
|
# Increment current window 5%
|
|
|
|
# $ compton-trans -c +5
|
|
|
|
# Remove opacity property of current window
|
|
|
|
# $ compton-trans -c none
|
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=
|
2012-05-28 08:21:14 +08:00
|
|
|
i=
|
2011-12-08 02:35:22 +08:00
|
|
|
|
2012-11-08 22:30:42 +08:00
|
|
|
#
|
|
|
|
# Options
|
|
|
|
#
|
|
|
|
|
|
|
|
arg=
|
|
|
|
val=
|
|
|
|
active=
|
|
|
|
select=
|
|
|
|
|
|
|
|
while test $# -gt 0; do
|
|
|
|
arg="$1"
|
|
|
|
shift
|
|
|
|
case "$arg" in
|
|
|
|
-s | -select | --select) ;;
|
|
|
|
-c | -current | --current)
|
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"
|
|
|
|
;;
|
2012-11-08 22:30:42 +08:00
|
|
|
-n | -name | --name)
|
|
|
|
val="$1"
|
|
|
|
shift
|
|
|
|
window="-name $val"
|
|
|
|
;;
|
|
|
|
-w | -window | --window)
|
|
|
|
val="$1"
|
|
|
|
shift
|
|
|
|
window="-id $val"
|
|
|
|
;;
|
|
|
|
-o | -opacity | --opacity)
|
|
|
|
val="$1"
|
|
|
|
shift
|
|
|
|
opacity="$val"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
opacity="$arg"
|
|
|
|
;;
|
2011-12-08 02:35:22 +08:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2012-11-08 22:30:42 +08:00
|
|
|
if test -z "$window"; then
|
|
|
|
select=$(xwininfo | grep 'Window id:' | sed 's/^.*\(0x\S*\).*$/\1/')
|
|
|
|
window="-id $select"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Find Window
|
|
|
|
#
|
|
|
|
|
2011-12-08 02:35:22 +08:00
|
|
|
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
|
2012-11-08 22:30:42 +08:00
|
|
|
|
2012-04-01 12:54:42 +08:00
|
|
|
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-11-08 22:30:42 +08:00
|
|
|
if test -z "$parent"; then
|
|
|
|
echo "Window not found." >& 2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
2012-11-08 22:30:42 +08:00
|
|
|
i=$((i + 1))
|
2012-04-01 12:54:42 +08:00
|
|
|
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
|
|
|
|
2012-11-08 22:30:42 +08:00
|
|
|
if test -z "$window"; then
|
|
|
|
echo "Window not found." >& 2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check (or Delete) Opacity
|
|
|
|
#
|
|
|
|
|
|
|
|
if test "$opacity" = "none"; then
|
|
|
|
xprop $window -remove _NET_WM_WINDOW_OPACITY
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
opacity=$(echo "$opacity" | sed 's/[^-+0-9]//g')
|
|
|
|
if test -z "$opacity"; then
|
|
|
|
echo "Bad opacity value." >& 2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Determine Relative Opacity
|
|
|
|
#
|
|
|
|
|
|
|
|
if test -n "$(echo "$opacity" | sed 's/^\(+\|-\).*$\|^.*$/\1/')"; 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))
|
2012-11-08 22:30:42 +08:00
|
|
|
cur=$((cur * 100 / 0xffffffff))
|
|
|
|
opacity=$((cur + opacity))
|
2011-12-08 02:35:22 +08:00
|
|
|
fi
|
|
|
|
|
2012-11-08 22:30:42 +08:00
|
|
|
#
|
|
|
|
# Determine and Set Opacity
|
|
|
|
#
|
|
|
|
|
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
|
2012-11-08 22:30:42 +08:00
|
|
|
opacity=$((opacity * 0xffffffff / 100))
|
2011-12-08 02:35:22 +08:00
|
|
|
xprop $window -f _NET_WM_WINDOW_OPACITY 32c \
|
|
|
|
-set _NET_WM_WINDOW_OPACITY "$opacity"
|
|
|
|
fi
|