Xfce Forum

Sub domains
 

You are not logged in.

#1 2013-10-28 00:18:37

jmrichardson
Member
Registered: 2013-08-20
Posts: 4

Switch panel with workspace

Hello,

Is there a way in xfce to switch the panel when switching to a new workspace?  Or just switching the panel in general.  I am working on a project where I would like to be able to offer an entirely different set of functions in the control panel depending on the task at hand.  My idea was to be able to switch to a new workspace and new set of panel icons.  However, I can't figure out if something like this is even possible?  Or perhaps, just having a click or hot key to just switch the panel to a new configuration of icons? 

Any help would greatly be appreciated,
John

Offline

#2 2013-10-28 00:35:14

ToZ
Moderator
From: Toronto, Canada
Registered: 2011-06-02
Posts: 1,061

Re: Switch panel with workspace

Not sure that its possible. There is this bug/enhancement request from 2008 that doesn't appear to be acted on. As a suggestion, you could create multiple panels, one for each set of panel icons that you want and positioned in different locations on the screen and set to auto-hide. Then depending on the workspace that you are on, move your mouse to the location of the screen where the corresponding panel is hidden.

Offline

#3 2013-10-28 00:44:50

jmrichardson
Member
Registered: 2013-08-20
Posts: 4

Re: Switch panel with workspace

Thanks ToZ for the quick reply.  I thought of that but I potentially have a need for many different panels.  I am concerned things would get cluttered quickly or confusing.  Do you know of a way to programatically change a specific panel on the fly to point to a new configuration.  Lets say I create multiple panels positioned on top of each other.  Perhaps a way to hide all except the one I want?  Or only display the one I want? 

John

Offline

#4 2013-10-28 01:49:18

ToZ
Moderator
From: Toronto, Canada
Registered: 2011-06-02
Posts: 1,061

Re: Switch panel with workspace

Challenge accepted.

Here is something that might work (at least it works here with two panels and two workspaces with limited Sunday night testing).

First, you need to have "wmctrl" installed.

Second, you need to create all the extra panels you want and autohide them. Make note of the panel number for each panel (they start at 0 and can be seen in the Panel Preferences). You might end up with something that looks like this:

Workspace 1 = Panel 1
Workspace 2 = Panel 2
Workspace 3 = Panel 4
Workspace 4 = Panel 3
*Note: in the above example Panel 0 will not be considered, meaning it will be visible on all workspaces - in case you want this flexibility.

This would translate to configuration parameters which would look like this:

	WORKSPACE[1]=1													                        
	WORKSPACE[2]=2		
	WORKSPACE[3]=4													                        
	WORKSPACE[4]=3

Next, create the following script. Let's call it "panel_switcher" and put it where you want. Content is:

#!/bin/bash
# The Poor Man's Panel Switcher solution
# Requires: wmctrl
# Make sure you edit the PANEL configuration parameters to suit.
# debug mode = bash -xv /path/to/psw 2>&1 | tee wspm.log

# make sure that only one instance of this script is running
lockfile=/tmp/.psw.lockfile
if ( set -o noclobber; echo "locked" > "$lockfile") 2> /dev/null; then
  	trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
  	echo "pswDEBUG: Locking succeeded" >&2

######### PANEL CONFIGURATION: EDIT THESE VALUES ######################################################
###																												
### WORKSPACE[x]=Panel Number					                                                        
###																										              
	WORKSPACE[1]=1													                        
	WORKSPACE[2]=2		
	WORKSPACE[3]=4													                        
	WORKSPACE[4]=3										                       
####################################################################################################

######### DO NOT EDIT BELOW #############################################################################
	CURRENT_WORKSPACE=$(($(wmctrl -d | grep \* | cut -d' ' -f1)+1))
	xfconf-query -c xfce4-panel -p /panels/panel-${WORKSPACE[$CURRENT_WORKSPACE]}/autohide -s false
	
	while true
	do
		NEW_WORKSPACE=$(($(wmctrl -d | grep \* | cut -d' ' -f1)+1))	
		if [ $CURRENT_WORKSPACE -ne $NEW_WORKSPACE ]; then
			wmctrl -s $((($NEW_WORKSPACE)-1))
			# autohide the current workspace panel
			xfconf-query -c xfce4-panel -p /panels/panel-${WORKSPACE[$CURRENT_WORKSPACE]}/autohide -s true
			# unhide the new workspace panel
			xfconf-query -c xfce4-panel -p /panels/panel-${WORKSPACE[$NEW_WORKSPACE]}/autohide -s false
			CURRENT_WORKSPACE=$NEW_WORKSPACE
		fi
	sleep 1
	done

  	rm -f "$lockfile"
else
  	echo "pswDEBUG: Lock failed - exit" >&2
  	exit 1
fi			

...make sure to change the configuration parameters in the "PANEL CONFIGURATION" section to match your setup.

Finally, make the script executable.

What this script basically does, is it polls, using wmctrl, the current workspace and when it changes, it uses one xfconf-query command to autohide the panel of the workspace we left and a second xconf-query command to unhide the panel of the workspace we just moved to.

To test, in a terminal window, run /path/to/panel_switcher (change /path/to to be the actual path to the script). The first thing that should happen is that the panel for the current workspace should become visible. Then, change the workspace and the panels should change. (There will be a slight delay while they change).

Anyways, give it a test and see if it works.

**One thing to keep in mind. I've added code:

# make sure that only one instance of this script is running
lockfile=/tmp/.psw.lockfile
if ( set -o noclobber; echo "locked" > "$lockfile") 2> /dev/null; then
  	trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
  	echo "pswDEBUG: Locking succeeded" >&2

...to ensure that only one instance of this script runs. During testing you may find yourself getting a "pswDEBUG: Lock failed - exit" message when trying to run the script. If you do, first try to locate a running instance of this script and kill it. If you can't find a running instance, delete the /tmp/.psw.lockfile and try again.

Last edited by ToZ (2013-10-28 12:29:12)

Offline

#5 2013-10-28 11:48:21

jmrichardson
Member
Registered: 2013-08-20
Posts: 4

Re: Switch panel with workspace

Wow!  Thank you very much. I will be testing this out and let you know how it goes.

Offline

#6 2013-10-28 12:30:22

ToZ
Moderator
From: Toronto, Canada
Registered: 2011-06-02
Posts: 1,061

Re: Switch panel with workspace

I just found a typo in the script above and corrected it. Make sure you update your script to use this fixed version.

Offline

Board footer

Powered by FluxBB