Skip to content

Instantly share code, notes, and snippets.

@5310
Forked from bharadwaj-raju/panel-alpha.sh
Last active September 18, 2020 07:02
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 5310/1033619bd0c9a14a53c4c3fec82a903a to your computer and use it in GitHub Desktop.
Save 5310/1033619bd0c9a14a53c4c3fec82a903a to your computer and use it in GitHub Desktop.
Changes XFCE panel transparency depending on whether any window on the current workspace is maximized or not #script
#!/usr/bin/env bash
#-- CONFIGURATION
transparent_alpha=0
maximized_alpha=100
interval=0.5
#--
alpha_prop_list=()
for prop in $(xfconf-query -c xfce4-panel -p /panels -l); do
[[ "$prop" == *"background-alpha"* ]] && alpha_prop_list+=($prop)
done
on_maximized() {
for alpha_prop in "${alpha_prop_list[@]}"; do
xfconf-query -c xfce4-panel -p "$alpha_prop" -s "$maximized_alpha"
done
}
on_no_window_maximized() {
for alpha_prop in "${alpha_prop_list[@]}"; do
xfconf-query -c xfce4-panel -p "$alpha_prop" -s "$transparent_alpha"
done
}
echo $alpha_prop_list
while true; do
current_desktop=$(wmctrl -d | grep '*' | cut -d ' ' -f1)
is_any_window_maximized=false
for i in $(wmctrl -lG | awk -v d="$current_desktop" '$2==d {print $1}'); do
status=$(xprop -id $i _NET_WM_STATE)
if [[ "$status" == *"MAXIMIZED"* && "$status" != *"HIDDEN"* ]]; then
is_any_window_maximized=true
break
else
is_any_window_maximized=false
fi
done
if [[ $is_any_window_maximized == true ]]; then
on_maximized
else
on_no_window_maximized
fi
sleep $interval
done
@denikris
Copy link

hi, are there any guide to make it work with xubuntu 19.04? it work on xubuntu 18.04 but in 19.04 it's only work for xfce4-dockbarx-plugin but other component stay solid, maybe make revision for future use like xfce 4.14 in upcoming ubuntu release

@5310
Copy link
Author

5310 commented Aug 29, 2019 via email

@denikris
Copy link

xfce4-dockbarx-plugin get dynamic transparent like the script want it to be when i set it to "blend with panel", so when no maximized window(s) the only area get transparent is dockbarx, and other stay solid, and when at least one window maximized, dockbarx area on panel became solid following the rest of panel color.

i see xfce panel 4.12.x have different settings compared to 4.13.x and 4.14.x, like set transparency in "none (use system scheme)" and "solid color" for 4.12 but in 4.13 and 4.14 you can only set transparency from "solid color" only

@5310
Copy link
Author

5310 commented Aug 29, 2019 via email

@denikris
Copy link

i don't know, i'm not really that good finding something that necessary for bash script, i'm just daily linux user and just "google" for something when it doesn't work. like first time i can't apply this when using 18.04 and then the solution is to make this executable and install wmctrl and then add this to "session and startup".

maybe you can update(or make new one because 18.04 still active until future date) the script when 20.04 lts is released because sometimes there are many change in setting because development update and the old one like 4.13.x (the one i currently use) will be deprecated in the future

@5310
Copy link
Author

5310 commented Aug 29, 2019 via email

@rouchage
Copy link

Your code is pretty easy to rewrite for xfce 4.14, you need to change background-alpha to background-rgba, because background-alpha is gone)) and instead of 0-100 integer, now there is array of floating numbers, so you have to set transparency like this:
xfconf-query -c xfce4-panel -p "$alpha_prop" -t double -s 1.000000 -t double -s 0.500000 -t double -s 0.000000 -t double -s "$maximized_alpha"
You must change just last value, cause it sets transparency, whole should look like this:

#!/usr/bin/env bash

#-- CONFIGURATION
transparent_alpha=0.000000
maximized_alpha=1.000000
interval=0.1
#--

alpha_prop_list=()
for prop in $(xfconf-query -c xfce4-panel -p /panels -l); do
	[[ "$prop" == *"background-rgba"* ]] && alpha_prop_list+=($prop)
done

on_maximized() {
	for alpha_prop in "${alpha_prop_list[@]}"; do
		#xfconf-query -c xfce4-panel -p "$alpha_prop" -s "$maximized_alpha"
		xfconf-query -c xfce4-panel -p "$alpha_prop" -t double -s 1.000000 -t double -s 0.500000 -t double -s 0.000000 -t double -s "$maximized_alpha"
	done
}

on_no_window_maximized() {
	for alpha_prop in "${alpha_prop_list[@]}"; do
		#xfconf-query -c xfce4-panel -p "$alpha_prop" -s "$transparent_alpha"
		xfconf-query -c xfce4-panel -p "$alpha_prop" -t double -s 1.000000 -t double -s 0.500000 -t double -s 0.000000 -t double -s "$transparent_alpha"
	done
}

echo $alpha_prop_list

while true; do
	current_desktop=$(wmctrl -d | grep '*' | cut -d ' ' -f1)
	is_any_window_maximized=false
	for i in $(wmctrl -lG | awk -v d="$current_desktop" '$2==d {print $1}'); do
		status=$(xprop -id $i _NET_WM_STATE)
		if [[ "$status" == *"MAXIMIZED"* && "$status" != *"HIDDEN"* ]]; then
			is_any_window_maximized=true
			break
		else
			is_any_window_maximized=false
		fi
	done
		
	if [[ $is_any_window_maximized == true ]]; then
		on_maximized
	else
		on_no_window_maximized
	fi
	
	sleep $interval
done

And there is just single problem: panel updates color partially, unless you move mouse all over panel. but if you set color from panel preferences it updates immediately, maybe because it flashes during settings is open. If you get this fix please let me know.
And in xfce 4.14 you need first change panel color manually from: panel preferences >> Appearance >> Style - set to "solid color".
And I've forked your code and added animation, so if you're on xfce 4.12 check my version. I'll try to make it for 4.14 as well.

@nelsonaloysio
Copy link

nelsonaloysio commented Oct 16, 2019

I've forked Rouchage's code (here) with a patch for versions>=4.13. I noticed however a delay by xfce4-panel in applying the alpha value when compared to previous parameters - it seems to 'lag' on both animated and un-animated methods. I included both for further testing.

Note: as observed, the panel must be configured to solid color in panel preferences >> Appearance >> Style for versions 4.13+.

@5310
Copy link
Author

5310 commented Oct 17, 2019

This is great! Does either of these versions work for the 4.12 as well?

@nelsonaloysio
Copy link

Yes - tested and fully working with 4.12 as well. To make sure, I added a condition to check the installed xfce4-panel version (line 33).

@rouchage
Copy link

Good job. Add bc in "Required software" list. And have you any idea how to fix color changing lag? It does not occur when you open panel preferences and there change panel color, in this time rectangle around panel flashes, may be it is reason that avoids lag? What do you think about it?

@nelsonaloysio
Copy link

Good catch! Added bc to the requirements. On Arch Linux, it already came installed as a dependency from cups. Not sure on Ubuntu.

Yeah, I think you're on to something as well regarding the refresh issue; the delay is almost unnoticeable from the panel settings. Maybe it enforces refreshing when the user changes values? The enter/leave opacity values for the panel are also refreshed instantly when applied.

@rouchage
Copy link

And if you monitor panel with: xfconf-query -c xfce4-panel -m -v and change color from panel preferences you'll see that it changes just background-rgba property to ((null)) and there's also warning: "Unable to convert GValue to string".
Seems like bug ?

@nelsonaloysio
Copy link

Looking further, I found the line which issues the error message in xfconf source code (here). However, it only seems to output the error message when in verbose mode (-v); otherwise, it just prints the panel name i.e. set: /panels/panel-X/background-rgba when changed.

I also narrowed down the moment it issues the error (here). It might be because GValue in this case is an array with 4 values (rgba)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment