Xfce Forum

Sub domains
 

You are not logged in.

#1 2017-03-18 19:16:52

xfceme
Member
Registered: 2017-03-18
Posts: 1

Panel at top, change opacity or colour, when a window is maximised

Hi All,

My first post, so I apologise if the subject matter is menial.

As the subject says, I want the panel at the top to change when a window is maximised.

From slightly to transparent to a broad full colour, is one example of what I want it to do.

Is this possible?

Thanks in advance people.

Offline

#2 2017-03-18 22:55:28

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Panel at top, change opacity or colour, when a window is maximised

Hello and welcome to the forums.

Unfortunately, Xfce (xfce4-panel) doesn't have the functionality that you are asking for. However, if you're willing to run a script you can simulate that functionality.

A window that is maximized using xfwm4 will set "_NET_WM_STATE_MAXIMIZED_HORZ, _NET_WM_STATE_MAXIMIZED_VERT " in the "_NET_WM_STATE(ATOM)". Knowing this, you can create a script using wmctrl and xprop that cycles through all the open windows checking to see if any have this set, and if so, use xfconf-query to change the "background-alpha" (transparency) value of your panel.

For example, assuming that in a non-maximized state, the panel transparency is set to 0 and in a maximized state you want it set to 80, you can use a script like this:

#!/bin/bash
# Requires: wmctrl xprop

##################################
# Adjust values to suit
PANEL_NUM=0
PANEL_ALPHA_REGULAR=0
PANEL_ALPHA_MAXIMUM=80
##################################
##################################
# don't change anything below here
CURR=0
while true
do
	MAX_FND=0
	for w in $( wmctrl -l | cut -d' ' -f1 )
   	do 
		if xprop -id $w | grep -E "MAXIMIZED_HORZ.*MAXIMIZED_VERT" > /dev/null 2>&1
		then
			MAX_FND=1
			break
		fi
	done

	if [[ $MAX_FND -eq 1 && $CURR -eq 0 ]]
	then 
		xfconf-query -c xfce4-panel -p /panels/panel-$PANEL_NUM/background-alpha -s $PANEL_ALPHA_MAXIMUM
		CURR=1			
	elif [[ $MAX_FND -eq 0 && $CURR -eq 1 ]]
	then
		xfconf-query -c xfce4-panel -p /panels/panel-$PANEL_NUM/background-alpha -s $PANEL_ALPHA_REGULAR
		CURR=0
	fi

	sleep 1
done
exit 0

...make sure to change the values of the 3 constants at the top of the script to suit your needs. Make the file executable and run it to see the effect.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2018-10-17 03:27:53

fyffetimesmore
Member
Registered: 2018-10-17
Posts: 1

Re: Panel at top, change opacity or colour, when a window is maximised

Thank you for your script but I had a couple issues with it.

First, I found that you have to initially change the alpha down from 100 or else you'll get errors about the property not existing.  Then I found that if you have a window that was in a maximized state and then minimized the script wouldn't update the panel.

Here is my slightly modified version:

#!/bin/bash
# Requires: wmctrl xprop

##################################
# Adjust values to suit
PANEL_NUM=2
PANEL_ALPHA_REGULAR=0
PANEL_ALPHA_MAXIMUM=99
##################################
##################################
# don't change anything below here
CURR=0
while true
do
	MAX_FND=0
	for w in $( wmctrl -l | cut -d' ' -f1 )
   	do 
		if xprop -id $w | grep -E "MAXIMIZED_HORZ.*MAXIMIZED_VERT" > /dev/null 2>&1
		then
			if xprop -id $w | grep -E "window state: Normal" > /dev/null 2>&1
			then
				MAX_FND=1
				break
			fi
		fi
	done

	if [[ $MAX_FND -eq 1 && $CURR -eq 0 ]]
	then 
		xfconf-query -c xfce4-panel -p /panels/panel-$PANEL_NUM/background-alpha -s $PANEL_ALPHA_MAXIMUM
		CURR=1			
	elif [[ $MAX_FND -eq 0 && $CURR -eq 1 ]]
	then
		xfconf-query -c xfce4-panel -p /panels/panel-$PANEL_NUM/background-alpha -s $PANEL_ALPHA_REGULAR
		CURR=0
	fi
	

	sleep 1
done
exit 0

I did notice there is some delay when a window changes size but for what the script does I can totally live with it.

Again, thank you.

Offline

#4 2018-10-18 13:13:35

Misko_2083
Member
Registered: 2015-10-13
Posts: 191
Website

Re: Panel at top, change opacity or colour, when a window is maximised

Nice srcipting ToZ.

fyffetimesmore wrote:

First, I found that you have to initially change the alpha down from 100 or else you'll get errors about the property not existing.

If there is no property it needs to be created with -n switch, but then the type must be specified.

Changed it to use xprop only and to check if the window checked for maximized is on the current workspace.
When switching to another workspace, and if there are no maximized windows in that workspace, panel background will be switched to transparent.
It's now faster if there are lots of windows on different workspaces.
The property will be created if it's not existiing.

#!/bin/bash
# Requires: xprop

##################################
# Adjust values to suit
PANEL_NUM=2
PANEL_ALPHA_REGULAR=0
PANEL_ALPHA_MAXIMUM=99
##################################
##################################
# don't change anything below here
CURR=0
while true
do
	MAX_FND=0
	for w in $(xprop -notype -root _NET_CLIENT_LIST | cut -d'#' -f2 | tr ',' '\n' | awk '{print $1}')
   	do 
                if [[ "$(xprop -id $w -notype _NET_WM_DESKTOP | cut -d' ' -f3)" -eq "$(xprop -root -notype _NET_CURRENT_DESKTOP | cut -d' ' -f3)" ]]
                then

		   if xprop -id $w _NET_WM_STATE | grep -E "MAXIMIZED_HORZ.*MAXIMIZED_VERT" > /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
		xfconf-query -n -c xfce4-panel -p /panels/panel-$PANEL_NUM/background-alpha -t int -s $PANEL_ALPHA_MAXIMUM
		CURR=1			
	elif [[ $MAX_FND -eq 0 && $CURR -eq 1 ]]
	then
		xfconf-query -n -c xfce4-panel -p /panels/panel-$PANEL_NUM/background-alpha -t int -s $PANEL_ALPHA_REGULAR
		CURR=0
	fi
	

	sleep 1
done
exit 0

I'm still thinking about a way to make it faster.

Last edited by Misko_2083 (2018-10-18 13:19:54)


Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c

Offline

#5 2018-10-18 17:38:40

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Panel at top, change opacity or colour, when a window is maximised

This script keeps getting better and better. Thanks.

I have a number of these scripts running now in my autostart. What might be neat is to create some sort of management app (yad/zenity) where you can add new scripts and enable/disable on them on the fly, edit functionality to change them, and have one entry on autostart. Kind of like a "script-enhanced Xfce" app.

*makes note on to-do list


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#6 2018-12-21 02:09:14

Misko_2083
Member
Registered: 2015-10-13
Posts: 191
Website

Re: Panel at top, change opacity or colour, when a window is maximised

ToZ wrote:

I have a number of these scripts running now in my autostart. What might be neat is to create some sort of management app (yad/zenity) where you can add new scripts and enable/disable on them on the fly, edit functionality to change them, and have one entry on autostart. Kind of like a "script-enhanced Xfce" app.

*makes note on to-do list

^Grat idea. Can't wait.

Script didn't work with compiz.
Compiz sets the _NET_WM_STATE X window properties in this order MAXIMIZED_VERT, MAXIMIZED_HORZ.

So the script will work on Compiz if next line

if xprop -id $w _NET_WM_STATE | grep -E "MAXIMIZED_HORZ.*MAXIMIZED_VERT" > /dev/null 2>&1

is changed to

if xprop -id $w _NET_WM_STATE | grep -E "MAXIMIZED_HORZ.*MAXIMIZED_VERT|MAXIMIZED_VERT.*MAXIMIZED_HORZ" > /dev/null 2>&1

Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c

Offline

#7 2019-04-13 14:58:17

symbolwraith
Member
Registered: 2019-04-13
Posts: 6

Re: Panel at top, change opacity or colour, when a window is maximised

Thanks for the script. I had similar needs but little to no knowledge in bash scripting.

Sadly, it works if I launch the script directly but not if I make a systemd service do it on startup. It results in:
xprop:  unable to open display ''

Pretty sure it just needs some basic modifications that I can't identify, any suggestions?

Offline

#8 2019-04-13 17:31:43

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Panel at top, change opacity or colour, when a window is maximised

symbolwraith wrote:

Thanks for the script. I had similar needs but little to no knowledge in bash scripting.

Sadly, it works if I launch the script directly but not if I make a systemd service do it on startup. It results in:
xprop:  unable to open display ''

Pretty sure it just needs some basic modifications that I can't identify, any suggestions?

Sounds like it doesn't know where the display is. Make sure you declare/export DISPLAY and DBUS_SESSION_BUS_ADDRESS at the beginning of the script. I use the following:

declare -x DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
declare -x DISPLAY=":0.0"

...where "1000" is my user id.

BTW, welcome to the forums.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#9 2019-04-13 20:13:00

symbolwraith
Member
Registered: 2019-04-13
Posts: 6

Re: Panel at top, change opacity or colour, when a window is maximised

ToZ wrote:
symbolwraith wrote:

Thanks for the script. I had similar needs but little to no knowledge in bash scripting.

Sadly, it works if I launch the script directly but not if I make a systemd service do it on startup. It results in:
xprop:  unable to open display ''

Pretty sure it just needs some basic modifications that I can't identify, any suggestions?

Sounds like it doesn't know where the display is. Make sure you declare/export DISPLAY and DBUS_SESSION_BUS_ADDRESS at the beginning of the script. I use the following:

declare -x DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
declare -x DISPLAY=":0.0"

...where "1000" is my user id.

BTW, welcome to the forums.


Thanks!

Added these two lines at the beginning, now I get this as status of my service:

apr 13 22:10:39 nico systemd[1]: Started Set panel opacity.
apr 13 22:10:39 nico sh[1143]: No protocol specified
apr 13 22:10:39 nico sh[1143]: xprop:  unable to open display ':0.0'
apr 13 22:10:40 nico sh[1143]: No protocol specified
apr 13 22:10:40 nico sh[1143]: xprop:  unable to open display ':0.0'

Here's the service itself:

[Unit]
Description=Set panel opacity

[Service]
ExecStart=sh /home/nico/panel_tt.sh
Type=simple

[Install]
WantedBy=default.target

The weird thing is that it runs without any complaints if I just run the script.

Offline

#10 2019-04-13 20:40:04

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Panel at top, change opacity or colour, when a window is maximised

Are you running this service as a systemd/user service?


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#11 2019-04-13 21:21:28

symbolwraith
Member
Registered: 2019-04-13
Posts: 6

Re: Panel at top, change opacity or colour, when a window is maximised

ToZ wrote:

Are you running this service as a systemd/user service?

I placed it in /etc/systemd/system, so I guess I'm not. Should I try setting it up as a user service?

Offline

#12 2019-04-13 21:46:18

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Panel at top, change opacity or colour, when a window is maximised

Yeah. I just tried it in Arch and it's set up to automatically export the required variables if you use the user systemd version. Put the service file in ~/.config/systemd/user and enable it via:

systemd --user enable name.service

...where "name" is the name of the service that you use.

Works fine here using this method. No need to export or declare anything.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#13 2019-04-13 22:11:57

symbolwraith
Member
Registered: 2019-04-13
Posts: 6

Re: Panel at top, change opacity or colour, when a window is maximised

Okay, it works now! wink

It behaves exactly how I wanted, even though the transition is a bit slow. But it might just be because I'm running it on a pretty weak Chromebook, might be faster on better hardware.

Offline

#14 2019-04-14 01:51:58

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Panel at top, change opacity or colour, when a window is maximised

There is a "sleep 1" in the script that pauses the script for a second to prevent a race condition. You can try to lower that to say (0.75s or 0.5s) to see if it makes it more responsive.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#15 2019-04-14 09:27:29

symbolwraith
Member
Registered: 2019-04-13
Posts: 6

Re: Panel at top, change opacity or colour, when a window is maximised

Setting it to 0.5 improves it quite a bit. Should I expect anything catastrophic to happen to my windows because of that?

Offline

#16 2019-04-14 09:50:39

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Panel at top, change opacity or colour, when a window is maximised

Depends on the speed of your system. You want to avoid the script running again while the commands are not yet complete. If it appears to work fine then it probably is.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#17 2019-04-14 12:35:44

symbolwraith
Member
Registered: 2019-04-13
Posts: 6

Re: Panel at top, change opacity or colour, when a window is maximised

Understood. Thanks for your help on such an old thread!

Chrome OS had this thing where the panel is opaque only when there'e a maximized window on it. It's pretty elegant because transparent panels are cool and all but seeing the background under maximized windows isn't that great. It was one of the few things I missed now that I recycled this chromebook as an Arch machine so I'm pretty grateful I found this thread. wink

Last edited by symbolwraith (2019-04-14 12:37:39)

Offline

Board footer

Powered by FluxBB