diff --git a/bin/opacity b/bin/opacity index 4a624c5..ff5d499 100755 --- a/bin/opacity +++ b/bin/opacity @@ -1,6 +1,14 @@ #!/bin/sh -if [ "$TERM" = "xterm-kitty" ] -then - kitty @ set-background-opacity $1 +id=$(xdotool selectwindow) + +before=$(xprop -id $id 32c _NET_WM_WINDOW_OPACITY | lua -e 'print(tonumber(io.read():match("= .*$"):sub(2)))') +initial=$(xprop -id $id 32c _NET_WM_WINDOW_OPACITY | lua -e 'print(math.floor(tonumber(io.read():match("= .*$"):sub(2)) / 0xffffffff * 100 + 0.5))') + +((zenity --scale --title "Opacity" --value=$initial --print-partial; echo $? >&3) \ +| lua -e 'for line in io.lines() do print(string.format("0x%08x", math.floor(tonumber(line) / 100 * 0xffffffff + 0.5))) end' \ +| xargs -I{} xprop -id $id -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY {}) 3>&1 | (read xs; exit $xs) + +if [ $? -ne 0 ] +then xprop -id $id -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $before fi