Change icon of button

Hey,

I got the osx dock from Gulivert’s theme, and I love it !
My question is, can i change the volume icon when I mute it (setting it to 0%)
How do I do that ?

Greetz,
Deva

You’d have to post the (I assume) FvwmScript which does it.

– Thomas Adam

I’ve done it like this:

*OSXDock: (24x26+1100+0, Padding 1 0, Icon $[fvwm_icon_path]/v4.png, ActionOnPress, Action(Mouse 1) Menu MenuVol Rectangle +$left+25 0 0m, Action (Mouse 1) Menu MenuVol Rectangle +$left+25 0 0m )


DestroyMenu MenuVol
AddToMenu MenuVol
+ "100%%" Exec exec aumix -w 100
+ "90%%" Exec exec aumix -w 90
+ "80%%" Exec exec aumix -w 80
+ "70%%" Exec exec aumix -w 70
+ "60%%" Exec exec aumix -w 60
+ "50%%" Exec exec aumix -w 50
+ "40%%" Exec exec aumix -w 40
+ "30%%" Exec exec aumix -w 30
+ "20%%" Exec exec aumix -w 20
+ "10%%" Exec exec aumix -w 10
+ "0%%" Exec exec aumix -w 0

Right, so it’s using FvwmButtons. What you can do, is make use of Dyamanic buttons in this case, by changing the above line, and giving it an Id, so that it can later be referenced. Something like:

*OSXDock: (24x26+1100+0, Id "A", Padding 1 0, Icon $[fvwm_icon_path]/v4.png, ActionOnPress, Action(Mouse 1) Menu MenuVol Rectangle +$left+25 0 0m, Action (Mouse 1) Menu MenuVol Rectangle +$left+25 0 0m )

Then in the function you had: “MenuVol”, when the 0% mark is pressed, all we would need to do is tell it to run another function – this function will run aumix, and more importantly send a message to the OSXDock (just an FvwmButtons instance) to change the icon.

So for your menuVol function, the 0% line should be changed to read:

DestroyMenu MenuVol
AddToMenu MenuVol
+ "0%%" SoundChangeIcon

Then the “SoundChangeIcon”:

DestroyFunc SoundChangeIcon
AddToFunc SoundChangeIcon
+ I Exec exec aumix -w 0
+ I SendToModule OSXDock ChangeButton "A" Icon some_icon.png

That should then change the icon to whatever you like. You will have to do something similar, for when you press something other than 0% – to change the icon from mute, or whatever you decide you want to use. One way you can do this, is to make a more generic function, instead. Your menu would have to be replaced, thus:

DestroyMenu MenuVol
AddToMenu MenuVol
+ "100%%" ChangeSoundVolAndIcon 100
+ "90%%" ChangeSoundVolAndIcon 90
+ "80%%" ChangeSoundVolAndIcon 80
+ "70%%" ChangeSoundVolAndIcon 70
+ "60%%" ChangeSoundVolAndIcon 60
+ "50%%" ChangeSoundVolAndIcon 50
+ "40%%" ChangeSoundVolAndIcon 40
+ "30%%" ChangeSoundVolAndIcon 30
+ "20%%" ChangeSoundVolAndIcon 20
+ "10%%" ChangeSoundVolAndIcon 10
+ "0%%"  SoundChangeIcon

Leaving the “0%” menu option as a special case. For the “ChangeSoundVolAndIcon” function, you’re passing in the value of the percentage, so that aumix can use it, hence:

DestroyFunc ChangeSoundVolAndIcon
AddToFunc ChangeSoundVolAndIcon
+ I Exec exec aumix -w $0
+ I SendToModule OSXDock ChangeButton "A" Icon $[fvwm_icon_path]/v4.png

That way, when you went to essentially “unmute” your button, you’d get the old icon back.

I hope that makes sense – it seems a bit of a mess to me. If I can help clarify anything, let me know.

– Thomas Adam

R.E.S.P.E.C.T.

Thx !

OK. I don’t know whether you’d have got the changes I made to my post. They were only minor typographical ones, but if you run into any difficulties, that should address them.

– Thomas Adam

Well it works, but now I have, lets say 3 icons, and i wonna do something like this …

[code]
DestroyFunc ChangeSoundVolAndIcon
AddToFunc ChangeSoundVolAndIcon

  • I Exec exec aumix -w $0
  • I Test ($0 == “0”) SendToModule OSXDock ChangeButton “Volume” Icon $[fvwm_icon_path]/v0.png [/code]

What am i doing wrong here ?

Is there like a “between-function”? $0 between x and y …

Greetz,
Deva

You need to use the shell, to do arithemtic evaluation. This is done via “PipeRead”:

[code]

  • I PipeRead ‘[ “$0” == “0” ] && echo SendToModule OSXDock ChangeButton “Volume” Icon $[fvwm_icon_path]/v0.png’[/code]

– Thomas Adam