picom/bin/compton-trans
2012-11-08 09:21:57 -06:00

161 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
#
# compton-trans
# transset in a bash script
# Copyright (c) 2011-2012, Christopher Jeffrey
#
# Usage:
# 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
if test -z "$(which xprop)" -o -z "$(which xwininfo)"; then
echo "Please install x11-utils/xorg-xprop/xorg-xwininfo." >& 2
exit 1
fi
window=
opacity=
cur=
root=
parent=
i=
#
# Options
#
arg=
val=
active=
select=
while test $# -gt 0; do
arg="$1"
shift
case "$arg" in
-s | -select | --select) ;;
-c | -current | --current)
active=$(xprop -root -notype "_NET_ACTIVE_WINDOW" \
| sed 's/^.*\(0x\S*\).*$/\1/')
window="-id $active"
;;
-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"
;;
esac
done
if test -z "$window"; then
select=$(xwininfo | grep 'Window id:' | sed 's/^.*\(0x\S*\).*$/\1/')
window="-id $select"
fi
#
# Find Window
#
root=$(xwininfo -all -root \
| grep "Root window id" \
| sed 's/^.*\(0x\S*\).*$/\1/')
parent=$window
i=0
while true; do
parent=$(xwininfo -all $parent \
| grep Parent \
| sed 's/^.*\(0x\S*\).*$/\1/')
if test -z "$parent"; then
echo "Window not found." >& 2
exit 1
fi
if test "$parent" = "$root"; then
break
fi
parent="-id $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
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
cur=$(xprop $window -notype "_NET_WM_WINDOW_OPACITY" \
| sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/')
test -z "$cur" && cur=$((0xffffffff))
cur=$((cur * 100 / 0xffffffff))
opacity=$((cur + opacity))
fi
#
# Determine and Set Opacity
#
if test -n "$opacity" -a -n "$window"; then
test $opacity -lt 0 && opacity=0
test $opacity -gt 100 && opacity=100
opacity=$((opacity * 0xffffffff / 100))
xprop $window -f _NET_WM_WINDOW_OPACITY 32c \
-set _NET_WM_WINDOW_OPACITY "$opacity"
fi