picom-trans: add `--toggle` action to toggle between set opacity and unset.

Fixes: #472
This commit is contained in:
Bernd Busse 2020-10-22 23:06:17 +02:00
parent c9ccd8fb71
commit a854acc2d0
No known key found for this signature in database
GPG Key ID: 6DD2A3C48E63A5AB
2 changed files with 22 additions and 6 deletions

View File

@ -21,6 +21,8 @@
# $ picom-trans -c +5
# Delete current window's opacity
# $ picom-trans -c --delete
# Toggle current window's opacity between 90 and unset
# $ picom-trans -c --toggle 90
# Reset all windows
# $ picom-trans --reset
print_usage() {
@ -35,6 +37,8 @@ print_usage() {
echo "Actions:"
echo " -g, --get Print the target window's opacity."
echo " -d, --delete Delete opacity of the target window."
echo " -t, --toggle Toggle the target window's opacity, i.e. set if not already set"
echo " and delete else."
echo " -r, --reset Reset opacity for all windows."
echo ""
echo "Window Selection:"
@ -87,10 +91,10 @@ while test $# -gt 0; do
OPTIND=1
# Read options
while getopts 'hscrdgn:w:o:-:' option "$@"; do
while getopts 'hscrtdgn:w:o:-:' option "$@"; do
if test "$option" = '-'; then
case "$OPTARG" in
help | select | current | reset | delete | get)
help | select | current | reset | toggle | delete | get)
v=''
;;
name | window | opacity)
@ -117,6 +121,7 @@ while test $# -gt 0; do
wprefix='-id'; window=$active
;;
r) action='reset' ;;
t) action='toggle' ;;
d) action='delete' ;;
g) action='get' ;;
n) wprefix='-name'; window=$OPTARG ;;
@ -206,15 +211,17 @@ if test -z "$topmost"; then
exit 1
fi
# Get current opacity.
cur=$(xprop -id "$topmost" -notype _NET_WM_WINDOW_OPACITY \
| sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/')
# Remove the opacity property.
if test x"$action" = x'delete'; then
if test x"$action" = x'delete' -o \( x"$action" = x'toggle' -a -n "$cur" \); then
xprop -id "$topmost" -remove _NET_WM_WINDOW_OPACITY
exit 0
fi
# Get current opacity.
cur=$(xprop -id "$topmost" -notype _NET_WM_WINDOW_OPACITY \
| sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/')
# Unset opacity equals fully opaque
test -z "$cur" && cur=0xffffffff
cur=$((cur * 100 / 0xffffffff))

View File

@ -42,6 +42,9 @@ Print the target window's opacity instead of setting it.
*-d*, *--delete*::
Delete opacity of the target window instead of setting it.
*-t*, *--toggle*::
Toggle the target window's opacity: Set opacity if not already set, and delete if already set.
*-r*, *--reset*::
Reset opacity for all windows instead of setting it.
@ -90,6 +93,12 @@ picom-trans -c -- -5
picom-trans -c --delete
------------
* Toggle current window's opacity between 90 and unset
+
------------
picom-trans -c --toggle 90
------------
* Reset all windows:
+
------------