[size=84][color=blue]
I’d like to dynamically change the color of a titlebar button, dependent on some
state the window is in (which is managed with a State variable).
How can I do this? I’ve read the manual head to tail and diagonally, but it hasn’t
become very clear how to do this elegantly and in a simple way, and on top of
that all my attempts so far failed.
Basically, the button should be more an indicator of a state. It would be nice if
I could still click on it as with a real button, but for now I’d settle with anything
that just changes color/pixmap whenever a state is true (or false) for the window.
Thanks for any pointers.
bjd
[/size][/color]
[color=red]Edited by theBlackDragon:
–>Moved from Basic questions[/color]
Hmm. This depends whether you’re using vectors or pixmaps, or indeed pngs. You cannot change the background colour of a button which uses vectors. But what you can do (possibly) is change the background colour of a png. But there are some caveats to be aware of:
The PNGs would have to be predefined with an appropriate background.
It might not give the effect you wanted – especially if the buttons are small.
I suppose you could script 1. above, using convert(1), but it depends. Anyway to do what you want, you probably want to use FvwmEvent. You can then get FvwmEvent to listen for certain “triggers” that can then be tested to see what actions need to be performed.
Since I don’t know the precise details of what it is you’re wanting to test, I’d suggest an initial FvwmEvent config of something like:
Here, what that is saying is that there is a one second delay before the initial conditions are looked for. This is done so that we don’t get ourselves into a loop that might otheriwse cause us grief.
Ignoring that for the moment, the next thing we need to consider is how your decors are going to be arranged. What I would do, is rather than write out separate decors for each case, simply define a variable Fvwm can use. So at the top of your ~/.fvwm2rc file, you might have something like:
SetEnv fvwm_button ~/.fvwm/icons/default.png
Then in your default decor definition, you might have something like:
It’s the parts in bold in the decor that are the key – for whichever button you’re wanting to have changed, you will have to change your decor like at the top.
So having done that, all we need to do now, is to create a function that gets run when the FvwmEvent we defined earlier is triggered. Now, you said you wanted to test on the value of a State – that’s fine. I’ll just show you an example for if it were a sticky window, say:
DestroyFunc FvwmToggleStatePixmap
AddToFunc FvwmToggleStatePixmap
+ I Any (CurrentDesk Sticky AcceptsFocus) SetEnv fvwm_button ~/.fvwm/some_other_name.png
+ I All (CurrentDesk Sticky AcceptsFocus) WindowStyle UseDecor NormalDecor
In that way, if the function doesn’t match any sticky windows, the value of $[fvwm_button] is never updated, and hence your button on your windows never changes.
You can obviously adapt this to suit your needs, even for State-aware windows as well.