Skip to content

Instantly share code, notes, and snippets.

@Misko-2083
Last active December 12, 2019 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Misko-2083/b369ff31acf21c7fa542664447c3451d to your computer and use it in GitHub Desktop.
Save Misko-2083/b369ff31acf21c7fa542664447c3451d to your computer and use it in GitHub Desktop.
Dynamic panel transparency (Budgie) like in Mate Desktop
#!/bin/bash
# Dynamic panel transparency (Budgie) like in Mate Desktop
# This script sets the top panel to full transparency if no maximized window is on the current workspace.
# Sort of like Dynamic Transparency with budgie-panel’s in Solus.
# Whenever there is a maximized window on a workspace the top panel will turn off transparency.
# The only issue is that clock applet opacity isn’t changing.
# Save, make executable, run on startup
# Requires: xprop, imagemagick
# check if xprop is installed
if ! hash xprop; then
echo "Install xprop!"
exit 1
fi
if ! hash convert; then
echo "Install ImageMagick!"
exit 1
fi
##################################
# Adjust values to suit
PANEL=top
PANEL_ALPHA_REGULAR=0.65
PANEL_ALPHA_MAXIMUM=0.90
##################################
##################################
# don't change anything below here
gsettings set org.mate.panel.toplevel.background:/org/mate/panel/toplevels/top/background/ type "none"
if [[ "${PANEL}" == "top" ]]; then
PANEL_XID="$(xwininfo -root -children \
| awk '/[Tt]op\ [Pp]anel.*[Mm]ate-[Pp]anel/ {print $1}')"
elif [[ "${PANEL}" == "bottom" ]]; then
PANEL_XID="$(xwininfo -root -children \
| awk '/[Bb]ottom\ [Pp]anel.*[Mm]ate-[Pp]anel/ {print $1}')"
elif [[ "${PANEL}" == "left" ]]; then
PANEL_XID="$(xwininfo -root -children \
| awk '/[Ll]eft\ [Pp]anel.*[Mm]ate-[Pp]anel/ {print $1}')"
elif [[ "${PANEL}" == "right" ]]; then
PANEL_XID="$(xwininfo -root -children \
| awk '/[Rr]ight\ [Pp]anel.*[Mm]ate-[Pp]anel/ {print $1}')"
else
echo "Unknown panel position"; exit 1
fi
COL="$(import -window ${PANEL_XID} -colorspace sRGB -set colorspace RGB -format %c histogram:info: \
| sort -r -n | head -n 1 | grep -oE "rgb.*" | grep -oE "[0-9]*,[0-9]*,[0-9]*")"
GTK_THEME="$(gsettings get org.mate.interface gtk-theme)"
gsettings set org.mate.panel.toplevel.background:/org/mate/panel/toplevels/top/background/ type "color"
CURR=0
while true
do
# Theme changed
if [[ "${GTK_THEME}" != "$(gsettings get org.mate.interface gtk-theme)" ]]
then
GTK_THEME="$(gsettings get org.mate.interface gtk-theme)"
gsettings set org.mate.panel.toplevel.background:/org/mate/panel/toplevels/top/background/ type "none"
COL="$(import -window ${PANEL_XID} -colorspace sRGB -set colorspace RGB -format %c histogram:info: \
| sort -r -n | head -n 1 | grep -oE "rgb.*" | grep -oE "[0-9]*,[0-9]*,[0-9]*")"
gsettings set org.mate.panel.toplevel.background:/org/mate/panel/toplevels/${PANEL}/background/ type "color"
fi
MAX_FND=0
for w in $(xprop -notype -root _NET_CLIENT_LIST 2>/dev/null | cut -d'#' -f2 | tr ',' '\n' | awk '{print $1}')
do
if [[ "$(xprop -id $w -notype _NET_WM_DESKTOP 2>/dev/null | cut -d' ' -f3)" -eq "$(xprop -root -notype _NET_CURRENT_DESKTOP 2>/dev/null | cut -d' ' -f3)" ]]
then
if xprop -id $w _NET_WM_STATE | grep -E "MAXIMIZED_HORZ.*MAXIMIZED_VERT|MAXIMIZED_VERT.*MAXIMIZED_HORZ" > /dev/null 2>&1
then
if xprop -id $w WM_STATE | grep -E "window state: Normal" > /dev/null 2>&1
then
MAX_FND=1
break
fi
fi
fi
done
if [[ $MAX_FND -eq 1 && $CURR -eq 0 ]]
then
gsettings set org.mate.panel.toplevel.background:/org/mate/panel/toplevels/${PANEL}/background/ color "rgba(${COL},$PANEL_ALPHA_MAXIMUM)"
# echo "rgba(${COL},$PANEL_ALPHA_MAXIMUM)"
CURR=1
elif [[ $MAX_FND -eq 0 && $CURR -eq 1 ]]
then
gsettings set org.mate.panel.toplevel.background:/org/mate/panel/toplevels/${PANEL}/background/ color "rgba(${COL},$PANEL_ALPHA_REGULAR)"
# echo "rgba(${COL},$PANEL_ALPHA_REGULAR)"
CURR=0
fi
sleep 1
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment