systray question Thread last updated on 2003-11-14 11:31:26

Posted by member 24766 on 2003-11-13 11:46:06

I'm using Xi01, with systray2, and I want to fix something that's been bugging me. The SystrayOnAdd and OnDel commands run for every time a tray icon is added, but i have a two-high tray. The result is that my taskbar is shrunk twice as much as it should be (those commands call !TaskbarShrink and !TaskbarGrow).
Is there a way to make it run those commands only when the width changes (i.e. every other icon)?
I've looked around at all the documentation I can find, but I can't seem to find anything that would let me do this.

I think i'd be able to make it work if I could find a value like SystrayWidth, but that seems to be disabled since I have AutoSize on.

Posted by member 1316 on 2003-11-13 13:14:16 link

you should be able to do it, but it would require some scripting. define a variable, set it to zero, and on each icon add, add 1 to the variable. then when it gets to 2, make the systray bigger, then zero out the variable again. something like that.

Posted by member 71746 on 2003-11-13 13:36:45 link

You can employ mzScript for this. Set up your mzScript rc to have a varfile and a scriptfile.. In the varfile have this:

TrayTicker 0


... then in the script have the following (note the pointy brackets in the gotoif lines):

*Script bang !IconAddedToTray
*Script gotoif ("%{TrayTicker}" = "0") lbl_noresize
; put your taskbar resizing routine here
*Script exec !VarSet TrayTicker 1
*Script exec goto end
*Script label lbl_noresize
*Script exec !VarSet TrayTicker 0
*Script ~bang

*Script bang !IconRemovedFromTray
*Script gotoif ("%{TrayTicker}" = "1") lbl_noresize
; put your taskbar resizing routine here
*Script exec !VarSet TrayTicker 0
*Script exec goto end
*Script label lbl_noresize
*Script exec !VarSet TrayTicker 1
*Script ~bang


Finally, to call the !Bangs defined in the script, in your systray.rc file (or step.rc if you're not shooting for OTS2 compliance) use these settings:

SystrayOnAdd !IconAddedToTray
SystrayOnDel !IconRemovedFromTray


Basically how this works is it has a variable it uses to judge whether it's an odd or even icon being added.. For odd icons (ie, the 1st, 3rd, 5th, etc) it simply increments the variable and does no resizing. For even icons (ie, the 2nd, 4th, 6th, etc) it decrements the variable back to 0 and resizes the taskbar..

When an icon is removed from the tray it checks the variable - if it's 1 (ie, if an odd icon has been added most recently) then it knows it'll have to resize the taskbar.. if it's 0 (ie, if an even icon has been added most recently) it knows it can just remove the icon and there'll still be the odd icon left so the taskbar doesn't have to be resized.

I haven't tested this but it's pretty rudimentary, I see no reason why it wouldn't work apart from the fact that systray2 seems to sometimes have troubles with the OnAdd/OnDel commands upon recycle.. That's not something that would have anything to do with this scripting though, that's just a shortcoming in systray2. You can get around this by adding this line to your script:

*Script start !NetReloadModule systray2-2.0


...but if your system tray is hooked into an LsBox that won't work, cause when you re-load the tray it will unhook it from its associated box. As long as your tray isn't mounted in an LsBox you should be good to go with that script though :)

Posted by member 1316 on 2003-11-13 13:47:28 link

*glares menacingly at inhaler* that was my idea! :( I just didn't take the time to think out the code at all.

Posted by member 24766 on 2003-11-13 14:38:51 link

Wow that was much more than I was expecting!
Thanks inhaler... now all I have to do is learn to use mzScript...

Posted by member 37 on 2003-11-13 21:46:39 link

Very nice script inhaler!

Posted by member 37809 on 2003-11-13 22:43:39 link

From a glance, *script exec goto end is supposedly *script goto end which could possibly be replaced by *script exit since *script label end is missing.

Also, it seems those bangs do nothing (to flip the value of TrayTicker as you intend):

if TrayTicker equals 0, set TrayTicker to 0.
if TrayTicker equals 1, set TrayTicker to 1.

You mean to flip the 0's and 1's in the gotoif conditions.

Otherwise this looks like an elegant solution, inhaler :)

Posted by member 24766 on 2003-11-13 23:35:32 link

For some reason I can't get Litestep to find my mzscript file! I feel like the newbie I am...
I tried (what I think is...) the code for NetLoadModule, with no obvious effects on recycle (taskbar covers systray like my previous problem).
I then tried the LoadModule command, and it can't find the module, even though it is exactly where the error message says it is....

Posted by member 1316 on 2003-11-14 11:31:26 link

you need to do "*mzScriptFile '$path$filename'".