#!/usr/bin/install-menu
#
# This file is located in /etc/menu-methods/jwm
# See "Debian Menu System" /usr/share/doc/menu/html/index.html

compat="menu-1"

# /etc/menu-methods/menu.h
!include menu.h

outputencoding="UTF-8"
genmenu="jwmrc"
rootprefix="/etc/jwm/"
userprefix="jwmrc"
treewalk="(M)"
#rcfile="system.jwmrc";
#examplercfile="system.jwmrc-menu";

function q($com)=esc($com,"\"")
#function f($com)="  \"" q(title()) "\"    f.exec  \"" q($com) " &\"\n"

function xml_escape($s) = replace(replace(replace($s, \
"&",  "&amp;"), \
">",  "&gt;"), \
"<",  "&lt;")

supported
    x11=     nstring(level(), "  ") "    <Program label=\"" xml_escape(title()) "\" confirm=\"false\">" xml_escape($command) "</Program>\n"
    text=    nstring(level(), "  ") "    <Program label=\"" xml_escape(title()) "\" confirm=\"false\">" xml_escape(term()) "</Program>\n"
#    wm=     nstring(level(), "  ") "    <Exit label=\"" xml_escape(title()) "\" confirm=\"false\">" xml_escape($command) "</Exit>\n"
endsupported

startmenu=nstring(level(), "  ") "    <Menu label=\"" q(title()) "\">\n"
endmenu=nstring(level(), "  ") "    </Menu>\n"

# submenutitle= nstring(level(), "   ") "  \"" q(title()) q($section) "\"\n"


# FOR THE DEBIAN DEVELOPER
#
# 1) copy content from the jwm source (example.jwmrc)
#    - Remember to make "postoutput" where Debian menus are inserted.
#    - Use x-terminal-emulator, not xterm, rxvt etc.
#    - Check <Clock format="%H:%M" ...
#
# 2) Possibly replace font setting
#    FreeSans-12:bold 	=> -*-fixed-*-r-*-*-10-*-*-*-*-*-*-*
#    FreeSans-10 	=>
#    FreeSans-9:bold 	=>
#    - Change also RootMenu height 32 => 15
#
# 3) Substitute all quotes with backslash+quote
#
# 4) Substitute all newlines with "\n\"
#
# To test:
#
#       update-menus --stdout > /tmp/menu-stdin
#       cd  debian/
#   [1] cp jwm.menu-method /etc/menu-methods/jwm
#   [2] /etc/menu-methods/jwm -v < /tmp/menu-stdin
#       less /etc/jwm/jwmrc
#
#   Run 1 & 2 if you modify the menu-method file and want to see results
#
# To test desktop:
#
#     cp Jwm.desktop /usr/share/jwm/xsessions/Jwm.desktop

preoutput="\
<?xml version=\"1.0\"?>\n\
\n\
<JWM>\n\
\n\
   <!-- The root menu, if this is undefined you will not get a menu. -->\n\
   <!-- Additional RootMenu attributes: onroot, labeled, label -->\n\
   <RootMenu height=\"15\" onroot=\"123\">\n\
      <Program icon=\"rxvt.png\" label=\"Terminal\">x-terminal-emulator</Program>\n\
         <Program icon=\"firefox.png\" label=\"Www Browser\">x-www-browser</Program>\n\
\n\
<!-- #DEBIAN unused\n\
      <Menu icon=\"folder.png\" label=\"Applications\">\n\
         <Program icon=\"firefox.png\" label=\"Iceweasel\">iceweasel</Program>\n\
\n\
         <Program icon=\"audacious.png\" label=\"Audacious\">audacious</Program>\n\
         <Program icon=\"dia.png\" label=\"Dia\">dia</Program>\n\
         <Program icon=\"pidgin.png\" label=\"Pidgin\">pidgin</Program>\n\
         <Program icon=\"gimp.png\" label=\"Gimp\">gimp</Program>\n\
         <Program icon=\"gtk-gnutella.png\" label=\"gtk-gnutella\">\n\
            gtk-gnutella\n\
         </Program>\n\
         <Program icon=\"gxine.png\" label=\"gxine\">gxine</Program>\n\
         <Program icon=\"ooffice.png\" label=\"Open Office\">ooffice</Program>\n\
      </Menu>\n\
      <Menu icon=\"folder.png\" label=\"Utilities\">\n\
         <Program icon=\"xcalc.png\">xcalc</Program>\n\
         <Program icon=\"xfontsel.png\">xfontsel</Program>\n\
         <Program icon=\"xmag.png\">xmag</Program>\n\
         <Program icon=\"xprop.png\" label=\"xprop\">\n\
            xprop | xmessage -file -\n\
         </Program>\n\
      </Menu>\n\
-->\n\
"


postoutput="\n  \
      <Separator/>\n\
      <Restart label=\"Restart\" icon=\"restart.png\"/>\n\
      <Exit label=\"Exit\" confirm=\"true\" icon=\"exit.png\"/>\n\
      <Program label=\"Shutdown\" confirm=\"false\" icon=\"exit.png\">\n\
        /usr/lib/jwm/jwm-poweroff.sh\n\
     </Program>\n\
   </RootMenu>\n\
\n\
   <Group>\n\
      <Class>Pidgin</Class>\n\
      <Option>sticky</Option>\n\
   </Group>\n\
\n\
   <Group>\n\
      <Name>gkrellm2</Name>\n\
      <Option>nolist</Option>\n\
   </Group>\n\
\n\
   <Group>\n\
      <Name>rxvt</Name>\n\
      <Option>vmax</Option>\n\
   </Group>\n\
\n\
   <!-- Additional tray attributes: autohide, width, border, layer, layout -->\n\
   <Tray  x=\"0\" y=\"-1\" height=\"32\">\n\
\n\
      <!-- Additional TrayButton attribute: label -->\n\
      <TrayButton label=\"JWM\">root:1</TrayButton>\n\
\n\
      <TrayButton label=\"_\">showdesktop</TrayButton>\n\
\n\
      <!-- Additional Pager attributes; width, height -->\n\
      <Pager/>\n\
\n\
      <!-- Additional TaskList attribute: maxwidth -->\n\
      <TaskList/>\n\
\n\
      <Dock/>\n\
\n\
      <!-- Additional Swallow attribute: height -->\n\
      <Swallow name=\"xload\" width=\"64\">\n\
         xload -nolabel -bg black -fg red -hl white\n\
      </Swallow>\n\
\n\
      <Clock format=\"%H:%M\">xclock</Clock>\n\
\n\
   </Tray>\n\
\n\
   <!-- Visual Styles -->\n\
\n\
   <WindowStyle>\n\
\n\
      <Font>-*-fixed-*-r-*-*-9-*-*-*-*-*-*-*</Font>\n\
      <Width>4</Width>\n\
      <Height>20</Height>\n\
\n\
      <Active>\n\
         <Text>white</Text>\n\
         <Title>#70849d:#2e3a67</Title>\n\
         <Corner>white</Corner>\n\
         <Outline>black</Outline>\n\
      </Active>\n\
\n\
      <Inactive>\n\
         <Text>#aaaaaa</Text>\n\
         <Title>#808488:#303438</Title>\n\
         <Corner>#aaaaaa</Corner>\n\
         <Outline>black</Outline>\n\
      </Inactive>\n\
\n\
   </WindowStyle>\n\
\n\
   <TaskListStyle>\n\
      <Font>-*-fixed-*-r-*-*-10-*-*-*-*-*-*-*</Font>\n\
      <ActiveForeground>black</ActiveForeground>\n\
      <ActiveBackground>gray90:gray70</ActiveBackground>\n\
      <Foreground>black</Foreground>\n\
      <Background>gray70:gray90</Background>\n\
   </TaskListStyle>\n\
\n\
   <!-- Additional TrayStyle attribute: insert -->\n\
   <TrayStyle>\n\
      <Font>-*-fixed-*-r-*-*-10-*-*-*-*-*-*-*</Font>\n\
      <Background>gray90</Background>\n\
      <Foreground>black</Foreground>\n\
   </TrayStyle>\n\
\n\
   <PagerStyle>\n\
      <Outline>black</Outline>\n\
      <Foreground>gray90</Foreground>\n\
      <Background>#808488</Background>\n\
      <ActiveForeground>#70849d</ActiveForeground>\n\
      <ActiveBackground>#2e3a67</ActiveBackground>\n\
   </PagerStyle>\n\
\n\
   <MenuStyle>\n\
      <Font>-*-fixed-*-r-*-*-9-*-*-*-*-*-*-*</Font>\n\
      <Foreground>black</Foreground>\n\
      <Background>gray90</Background>\n\
      <ActiveForeground>white</ActiveForeground>\n\
      <ActiveBackground>#70849d:#2e3a67</ActiveBackground>\n\
   </MenuStyle>\n\
\n\
   <PopupStyle>\n\
      <Font>-*-fixed-*-r-*-*-10-*-*-*-*-*-*-*</Font>\n\
      <Outline>black</Outline>\n\
      <Foreground>black</Foreground>\n\
      <Background>yellow</Background>\n\
   </PopupStyle>\n\
\n\
   <IconPath>\n\
      $HOME/.icons\n\
   </IconPath>\n\
\n\
   <!-- Virtual Desktops -->\n\
   <!-- Desktop tags can be contained within Desktops for desktop names. -->\n\
   <Desktops count=\"4\">\n\
\n\
      <!-- Default background. Note that a Background tag can be\n\
           contained within a Desktop tag to give a specific background\n\
           for that desktop.\n\
       -->\n\
<!-- #DEBIAN change. Was bg.xpm -->\n\
      <Background type=\"tile\">$HOME/jwm-bg.xpm</Background>\n\
\n\
\n\
   </Desktops>\n\
\n\
   <!-- Double click speed (in milliseconds) -->\n\
   <DoubleClickSpeed>400</DoubleClickSpeed>\n\
\n\
   <!-- Double click delta (in pixels) -->\n\
   <DoubleClickDelta>2</DoubleClickDelta>\n\
\n\
   <!-- The focus model (sloppy or click) -->\n\
   <FocusModel>sloppy</FocusModel>\n\
\n\
   <!-- The snap mode (none, screen, or border) -->\n\
   <SnapMode distance=\"10\">border</SnapMode>\n\
\n\
   <!-- The move mode (outline or opaque) -->\n\
   <MoveMode>opaque</MoveMode>\n\
\n\
   <!-- The resize mode (outline or opaque) -->\n\
   <ResizeMode>opaque</ResizeMode>\n\
\n\
   <!-- Key bindings -->\n\
   <Key key=\"Up\">up</Key>\n\
   <Key key=\"Down\">down</Key>\n\
   <Key key=\"Right\">right</Key>\n\
   <Key key=\"Left\">left</Key>\n\
   <Key key=\"h\">left</Key>\n\
   <Key key=\"j\">down</Key>\n\
   <Key key=\"k\">up</Key>\n\
   <Key key=\"l\">right</Key>\n\
   <Key key=\"Return\">select</Key>\n\
   <Key key=\"Escape\">escape</Key>\n\
\n\
<!-- #DEBIAN unused -->\n\
   <Key mask=\"A\" key=\"Tab\">nextstacked</Key>\n\
-->\n\
<!-- #DEBIAN add -->\n\
   <Key mask=\"A\" key=\"Tab\">next</Key>\n\
\n\
   <Key mask=\"A\" key=\"F4\">close</Key>\n\
   <Key mask=\"A\" key=\"#\">desktop#</Key>\n\
   <Key mask=\"A\" key=\"F1\">root:1</Key>\n\
   <Key mask=\"A\" key=\"F2\">window</Key>\n\
\n\
</JWM>\n\
\n\
"
