hw <[email protected]> writes:

> Dan Espen <[email protected]> writes:
>
>> hw <[email protected]> writes:
>>
>>> Hi,
>>>
>>> how can I conditionally add menu entries?  For example:
>>>
>>>
>>> [...]
>>> Read fvwm-functions-starters-common.fvwm
>>> Read fvwm-functions-starters-games.fvwm quiet
>>> Read fvwm-functions-starters-local.fvwm quiet
>>> [...]
>>>
>>>
>>> DestroyMenu Main
>>> AddToMenu Main
>>> + "Main"                        Title
>>> + "Common"                      PopUp Common
>>> + "Games"                       PopUp Games
>>> + "Local"                       PopUp Local
>>>
>>>
>>> I want the "Common" and "Games" entries in the menu only when the files
>>> defining them (like fvwm-functions-starters-games.fvwm) can be read.
>>>
>>> I thought I could use something like
>>>
>>> DestroyMenu Main
>>> AddToMenu Main
>>> + Test (f fvwm-functions-starters-games.fvwm) AddToMenu Main "Games" PopUp 
>>> Games
>>>
>>>
>>> and that doesn't work in that the menu entry doesn't show up regardless
>>> of the existance of the file.  There doesn't seem to be a way to test
>>> whether something is defined or not; if there was, I could test if a
>>> menu has been defined and only then add it to another menu.
>>
>> Try PipeRead.  Use shell, Perl, Python, your choice.
>
> How would that work?  I'm trying to make a kinda dynamic configuration,
> meaning that there is supposed to be a basic configuration accompanied
> by optional configurations.  An optional configuration needs to make an
> entry for its sub-menu into the root menu if the optional configuration
> is available.
>
> If I was to write some program to create the root menu, I would always
> need to modify the program when new optional configurations are to be
> added so it could recognize them.  That is something I would prefer to
> avoid.
>
> Hm, having that said, I can make it so that the optional configurations
> add themselves to the root menu.  All they need is a line like
>
> AddToMenu Main "Games" PopUp Games
>
> Unfortunately, that raises the question how I can make it so that the
> entries in the root menu appear in a desired order and with the title at
> the top rather than somewhere in between the entries ...  Is there a way
> to sort menu entries once no more entries are being added?
>
> I'm probably not the first one to try this.  It can't be this difficult,
> can it?

No, it's not difficult at all.

I have a number of scripts that work with PipeRead, here is a very short
one:

  #!/usr/bin/perl

  print "DestroyFunc LockTerm\n";
  $_ = `uname -s`;
  chomp;
  if ( /Linux/ ) {
    print "AddToFunc LockTerm I Exec exec gnome-screensaver-command -l\n";
    exit 0;
  }
  print "AddToFunc  LockTerm I Exec exec myscreensaver -lock\n";


This creates a "LockTerm" function which is different when running on Linux.
(I used the same configuration file on Solaris systems.)

Doing sorts, file existence tests, just about anything should be
obvious.  Just only print commands when you want to generate Fvwm
commands.

If you look at fvwm-menu-desktop you'll see how far you can go with
this.

-- 
Dan Espen

Reply via email to