<simplesect id="config-menu-dynamic" xreflabel="Dynamic Menus"> 
  <title>Dynamic Menus</title>

  <para>
    It is possible to use dynamic menus in pekwm, that is menus that regenerate
    themselves whenever the menu is viewed. This is done with the Dynamic keyword.
  </para>

  <para>
    To use this feature, you need to put a dynamic entry in the
    <filename>~/.pekwm/menu</filename> file with a parameter that
    tells pekwm what file to execute to get the menu. This file can be
    of any language you prefer, the main thing is that it outputs
    valid pekwm menu syntax inside a Dynamic {} section. The syntax of
    dynamic entry looks like this:
  </para>

  <screen>Entry = "" { Actions = "Dynamic /path/to/filename" }</screen>

  <para>
    The input from a program that creates the dynamic content should
    follow the general menu syntax encapsulated inside a Dynamic {}
    section.  Variables have to be included inside the dynamic menu
    for them to work.  A simple script to give pekwm dynamic menu
    content would look like this:
  </para>

  <screen>#!/bin/bash
output=$RANDOM # gets a random number

echo "Dynamic {"
echo " Entry = \"$output\" { Actions = \"Exec xmessage $output\" }"
echo "}"</screen>

  <para>
    This script would output something like:
  </para>
  <screen>Dynamic {
 Entry = "31549" { Actions = "Exec xmessage 31549" }
}</screen>

  <para>
    Clients can access the PID and Window that was active when the
    script was executed via the environment variables $CLIENT_PID and
    $CLIENT_WINDOW. $CLIENT_PID is only available if the client is
    being run on the same host as pekwm.
  </para>

</simplesect>

