A little useful function

Hello there,

i would like have this behavior when i click on an icon on my FvwmButtons. If i click on the xterm button, i want this :

  • if there isn’t any xterm, then exec xterm;
  • if there is one xterm, then WindowListFunc this xterm;
  • if there are several xterms, then popup a menu.

I have done that :

[code]AddToFunc TestFunc

  • I SetEnv nbr_fenetre 0
  • I Current All (Gvim) PipeRead ‘echo SetEnv nbr_fenetre $$(($$nbr_fenetre + 1))’
  • I Test (EnvMatch nbr_fenetre 0) Exec gvim
  • I PipeRead ‘if [${nbr_fenetre} -eq 1];
    then echo “Next (Gvim) WindowListFunc”
    elif [${nbr_fenetre} -gt 1];
    then echo “Popup MenuPlusieursFenetres”
    fi;’

AddToMenu MenuPlusieursFenetres

  • “test”[/code]
    If i haven’t got any xterm, it opens one but if i have one or more than one, it does nothing. Any ideas ?
 + I None (Xterm) Exec exec xterm

PipeRead – well, more specifically, the test construct. You
want a space after the angle brackets, so:

+ I PipeRead 'if [ ${nbr_fenetre} -eq 1 ]; \
        then echo "Next (Gvim) WindowListFunc" \
    elif [ ${nbr_fenetre} -gt 1 ]; \
        then echo "Popup MenuPlusieursFenetres" \
    fi;'

HTH,

– Thomas Adam

A better way to find out if there is only one instance of a window is this:

[code]DestroyFunc WindowTest
AddToFunc WindowTest

  • I Next ($0) Next ($0) PipeRead “[ $$[w.id] = $$$$[w.id] ] && echo WindowListFunc || echo Popup MenuPlusieursFenetres”
  • I TestRc (NoMatch) Exec $1

WindowTest XTerm xterm[/code]
Note how the first $$[w.id] will expand after the first next, while $$$$[w.id] will expand after the second. If there only is one window matching it will be the same id in both cases.

Hello there !

I’ve found something which work a little :

[code]DestroyFunc LookUpWindow
AddToFunc LookUpWindow

  • I All ($0) Popup MultiWindowMenu
  • I TestRc (NoMatch) Exec exec $1

AddToMenu MultiWindowMenu DynamicPopupAction MultiWindowMenuFunc

DestroyFunc MultiWindowMenuFunc
AddToFunc MultiWindowMenuFunc

  • I DestroyMenu MultiWindowMenu
  • I AddToMenu MultiWindowMenu DynamicPopupAction MultiWindowMenuFunc
  • I Current All ($[w.class], CirculateHit) MenuWindowListFunc
  • I AddTomenu MultiWindowMenu %cancel.png%“Annuler” Nop

DestroyFunc MenuWindowListFunc
AddToFunc MenuWindowListFunc

  • I AddToMenu MultiWindowMenu %$[w.miniiconfile]%"$[w.class]: $[w.name]" WindowId $[w.id] WindowListFunc[/code]
    I called this with for instance :
LookUpWindow Gvim gvim

This function popups a menu if there is at least one gvim or create one if not.
My only problem is that i have to click 3 times on the menus in order to close it (if i have 3 gvim). I have to click 10 times if i have 10 gvim…
How can i do to close the menu just when i click one time ?
For example : i have 4 aterm, i popup the menu, i choose one aterm by clicking on it and the menu closes.

Thanks for your help.