Xfce Forum

Sub domains
 

You are not logged in.

#1 2021-04-06 13:26:45

PseudAnonymous
Member
Registered: 2021-04-05
Posts: 42

[SOLVED] Workspace Switcher / GenMon Colourschemes

Is there a way to have the GenMon applet display a value in a different colour, depending on the value passed to it?

I order my workspaces negatively/positively, depending on their relationship to my default (central) workspace upon session start. My XFCE session starts on the sixth of eleven workspaces (named '0'). The first left is named '-1', the first right '1'. The fifth left is named '-5', the fifth right '5'.  You get the idea.

Specifically, I'd like to modify the script (as per ToZ here) such that what the GenMon applet displays is determined by the name of the desktop.

Even if I name the right-hand workspaces with a plus, so that they're '+1' to '+5', because the '-' and '+' take up a different amount of space in a proportional font, like Sans, things jump when I shift from one side of the scale to the next (by wrapping around from +/-5 to -/+5) or across '0'.

It's a first world problem to be sure but I just know that, as time goes by, it will irritate me.

What would be great, therefore, would be to have the script look at the name of the desktop and, if it's negative, output the name in red (or whatever) and in green (or whatever), if not negative.

Thanks.

Last edited by PseudAnonymous (2021-12-06 12:55:35)


Don't dance like nobody's watching, dance like a toddler instead - they don't even care if there's any music!

Offline

#2 2021-04-06 16:59:51

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,006

Re: [SOLVED] Workspace Switcher / GenMon Colourschemes

Yes, genmon supports the Pango Markup Language. Something like this?

#!/bin/bash

# requires wmctrl

CURRENT_DESKTOP=$(( $(wmctrl -d | grep "*" | awk '{print $1}') +1))
CURRENT_DESKTOP_NAME=$(xfconf-query -c xfwm4 -p /general/workspace_names |\
	tail -$(xfconf-query -c xfwm4 -p /general/workspace_count) |\
	awk -v i=$CURRENT_DESKTOP 'NR==i')

case $CURRENT_DESKTOP_NAME in
	-*) COLOR="red" ;;
	+*) COLOR="green" ;;
	*)  COLOR="grey" ;;
esac

case $1 in
	number)
		echo "<txt> <span foreground='$COLOR'>$CURRENT_DESKTOP</span> </txt>"
		echo "<tool></tool>"
	;;
	name)
		echo "<txt> <span foreground='$COLOR'>$CURRENT_DESKTOP_NAME</span> </txt>"
		echo "<tool></tool>"		
	;;
	both)
		echo "<txt> <span foreground='$COLOR'>$CURRENT_DESKTOP : $CURRENT_DESKTOP_NAME</span> </txt>"
		echo "<tool></tool>"
	;;
esac

exit 0

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 2021-04-06 18:00:04

PseudAnonymous
Member
Registered: 2021-04-05
Posts: 42

Re: [SOLVED] Workspace Switcher / GenMon Colourschemes

Not quite, unfortunately.

I want to do away with the '-' and '+' altogether and simply have the numbers displayed in red, if the workspace is one of the negative ones ... or green, if one of the positive ones - i.e. instead of '-1' or '-5', it's a red '1' or '5' and instead of '+2' or '+3', it's a green '2' or '3'.

Otherwise what will happen is that the jumps will still happen, they'll just be in colour as well.


I suspect what would be needed would be a calculation based upon the actual number of the workspace (the one currently named '-5' is actually workspace 1, '0' is actually 6 and '+5' is actually 11).

First there'd need to be a simple threshold test (is it below 6 or above 6?)

Then there'd need to be a translation from the actual workspace number to the equivalent 'name' value, so that workspace 1 gets displayed as red '5',workspace 2 as red '4' ... all the way up to workspace 10 being displayed as green '4' and workspace 11 as green '5'.


Then, of course, it needs to fit into your GenMon script from yesterday

#!/bin/bash

# requires wmctrl

CURRENT_DESKTOP=$(( $(wmctrl -d | grep "*" | awk '{print $1}') +1))
CURRENT_DESKTOP_NAME=$(xfconf-query -c xfwm4 -p /general/workspace_names |\
	tail -$(xfconf-query -c xfwm4 -p /general/workspace_count) |\
	awk -v i=$CURRENT_DESKTOP 'NR==i')

case $1 in
	number)
		echo "<txt> $CURRENT_DESKTOP </txt>"
		echo "<tool></tool>"
	;;
	name)
		echo "<txt> $CURRENT_DESKTOP_NAME </txt>"
		echo "<tool></tool>"		
	;;
	both)
		echo "<txt> $CURRENT_DESKTOP : $CURRENT_DESKTOP_NAME </txt>"
		echo "<tool></tool>"
	;;
esac

exit 0

... so that the translation and colourisation happen simultaneously  with the value update when the workspace number is passed to GenMon.


Sorry to be so helpless but it's been a long time since I did any development and I just haven't kept up with things over the years, so I'm trying to run before I can even crawl right now.


Don't dance like nobody's watching, dance like a toddler instead - they don't even care if there's any music!

Offline

#4 2021-04-06 18:07:03

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,006

Re: [SOLVED] Workspace Switcher / GenMon Colourschemes

Try this one instead:

#!/bin/bash

# requires wmctrl

CURRENT_DESKTOP=$(( $(wmctrl -d | grep "*" | awk '{print $1}') +1))
CURRENT_DESKTOP_NAME=$(xfconf-query -c xfwm4 -p /general/workspace_names |\
	tail -$(xfconf-query -c xfwm4 -p /general/workspace_count) |\
	awk -v i=$CURRENT_DESKTOP 'NR==i')

case $CURRENT_DESKTOP in
	[1-5]) COLOR="red" ;;
	6) COLOR="grey" ;;
	[7-11]) COLOR="green" ;;
esac

case $1 in
	number)
		echo "<txt> <span foreground='$COLOR'>$CURRENT_DESKTOP</span> </txt>"
		echo "<tool></tool>"
	;;
	name)
		echo "<txt> <span foreground='$COLOR'>$CURRENT_DESKTOP_NAME</span> </txt>"
		echo "<tool></tool>"		
	;;
	both)
		echo "<txt> <span foreground='$COLOR'>$CURRENT_DESKTOP : $CURRENT_DESKTOP_NAME</span> </txt>"
		echo "<tool></tool>"
	;;
esac

exit 0

...its based on workspace numbers.


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

#5 2021-04-06 18:24:32

PseudAnonymous
Member
Registered: 2021-04-05
Posts: 42

Re: [SOLVED] Workspace Switcher / GenMon Colourschemes

It works on workspaces 1 to 6 - whatever I name them gets displayed in red for 1 to 5 and grey for 6.

Above 6 though, it just displays the name assigned to workspace 6 in grey.

If I wrap around from 1 to 11 it displays the name of workspace 1 in red until it gets to workspace 6, whereupon it turns grey again (but with the correct name).


Don't dance like nobody's watching, dance like a toddler instead - they don't even care if there's any music!

Offline

#6 2021-04-06 18:30:52

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,006

Re: [SOLVED] Workspace Switcher / GenMon Colourschemes

Ahh, I see. I got the bash case condition wrong (I wasn't testing with >9 workspaces). Try this one instead:

#!/bin/bash

# requires wmctrl

CURRENT_DESKTOP=$(( $(wmctrl -d | grep "*" | awk '{print $1}') +1))
CURRENT_DESKTOP_NAME=$(xfconf-query -c xfwm4 -p /general/workspace_names |\
	tail -$(xfconf-query -c xfwm4 -p /general/workspace_count) |\
	awk -v i=$CURRENT_DESKTOP 'NR==i')

case $CURRENT_DESKTOP in
	[1-5]) COLOR="red" ;;
	[6]) COLOR="grey" ;;
	[7-9] | 1[0-1]) COLOR="green" ;;
esac

case $1 in
	number)
		echo "<txt> <span foreground='$COLOR'>$CURRENT_DESKTOP</span> </txt>"
		echo "<tool></tool>"
	;;
	name)
		echo "<txt> <span foreground='$COLOR'>$CURRENT_DESKTOP_NAME</span> </txt>"
		echo "<tool></tool>"		
	;;
	both)
		echo "<txt> <span foreground='$COLOR'>$CURRENT_DESKTOP : $CURRENT_DESKTOP_NAME</span> </txt>"
		echo "<tool></tool>"
	;;
esac

exit 0

We're getting close.


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

#7 2021-04-06 18:34:56

PseudAnonymous
Member
Registered: 2021-04-05
Posts: 42

Re: [SOLVED] Workspace Switcher / GenMon Colourschemes

That got it.

Thanks a lot!

Right ... I'mma study the script now and see if I can't work how it does what it does smile


Don't dance like nobody's watching, dance like a toddler instead - they don't even care if there's any music!

Offline

#8 2021-11-30 17:28:27

PseudAnonymous
Member
Registered: 2021-04-05
Posts: 42

Re: [SOLVED] Workspace Switcher / GenMon Colourschemes

How do I change the colours to bold/bright, etc?

I tried using "light green", "bold green".

Tried using "\e[1;32m" and suchlike.


No joy, however.

Last edited by PseudAnonymous (2021-11-30 17:43:51)


Don't dance like nobody's watching, dance like a toddler instead - they don't even care if there's any music!

Offline

#9 2021-11-30 20:33:38

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,006

Re: [SOLVED] Workspace Switcher / GenMon Colourschemes

PseudAnonymous wrote:

I tried using "light green",

"light green should work. For example:

case $CURRENT_DESKTOP in
	[1-5]) COLOR="red" ;;
	[6]) COLOR="grey" ;;
	[7-9] | 1[0-1]) COLOR="light green" ;;
esac

You can use any of the colours from the rgb.txt file (should be in /etc/X11).

"bold green".

Bold is a different attribute. See: https://docs.gtk.org/Pango/pango_markup.html. You would need to add a "<b> </b>" attribute to the existing format. For example:

name)
		echo "<txt> <span foreground='$COLOR'><b>$CURRENT_DESKTOP_NAME</b></span> </txt>"
		echo "<tool></tool>"		
	;;

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

#10 2021-12-06 12:54:56

PseudAnonymous
Member
Registered: 2021-04-05
Posts: 42

Re: [SOLVED] Workspace Switcher / GenMon Colourschemes

Tried "light green", etc., but no joy.

However, the <b> got it, thanks - should really have thought of that myself, tbh (it is pretty obvious in context)


Don't dance like nobody's watching, dance like a toddler instead - they don't even care if there's any music!

Offline

Board footer

Powered by FluxBB