Browse Source

Add support Openbox pipe-menus

pull/30/head
digital-freak 2 months ago
parent
commit
f0c632076f
  1. 30
      man/xdgmenumaker.t2t
  2. 49
      src/xdgmenumaker

30
man/xdgmenumaker.t2t

@ -35,6 +35,7 @@ according to the running user locale settings.
- fvwm - fvwm
- icewm - icewm
- jwm - jwm
- openbox
- pekwm - pekwm
- twm and compatible derivatives such as ctwm and vtwm - twm and compatible derivatives such as ctwm and vtwm
- windowmaker - windowmaker
@ -49,8 +50,8 @@ dependency (used by the **--max-icon-size** option).
: **-f, --format** : **-f, --format**
specify the output format to use. Valid options are //amiwm//, //blackbox//, specify the output format to use. Valid options are //amiwm//, //blackbox//,
//compizboxmenu//, //fluxbox//, //fvwm//, //icewm//, //jwm//, //pekwm//, //compizboxmenu//, //fluxbox//, //fvwm//, //icewm//, //jwm//, //openbox//,
//twm// and //windowmaker//. //pekwm//, //twm// and //windowmaker//.
Specifying the output format is mandatory. Specifying the output format is mandatory.
: **-i, --icons** : **-i, --icons**
@ -300,6 +301,31 @@ refresh the menu, like this:
``<Program label="Refresh Menu">jwm -reload</Program>`` ``<Program label="Refresh Menu">jwm -reload</Program>``
: **Openbox**
To generate an application menu for Openbox, run **xdgmenumaker** like this:
``$ xdgmenumaker -f openbox > ~/.cache/openbox/apps.menu``
or if you want icons in your menu:
``$ xdgmenumaker -i -f openbox > ~/.cache/openbox/apps.menu``
and you can then edit your //~/.config/openbox/menu.xml// file and add this
line somewhere in //<menu id="root-menu" label="Openbox 3">// section:
``<menu execute="cat ~/.cache/openbox/apps.menu" id="applications-pipe-menu" label="Applications"/>``
You can add the **xdgmenumaker** command as another item in your menu, if
you want to update it, without having to run the command manually again:
```
<item label="Rebuild applications menu">
<action name="Execute">
<command>xdgmenumaker -i -f openbox > ~/.cache/openbox/apps.menu</command>
</action>
</item>
```
: **pekwm** : **pekwm**
There are two ways to have an XDG menu in pekwm. The first one, There are two ways to have an XDG menu in pekwm. The first one,

49
src/xdgmenumaker

@ -230,6 +230,8 @@ def main(argv):
elif xopts['desktop'] == "amiwm": elif xopts['desktop'] == "amiwm":
xopts['seticon'] = False xopts['seticon'] = False
amiwm() amiwm()
elif xopts['desktop'] == "openbox":
openbox()
else: else:
usage() usage()
sys.exit(2) sys.exit(2)
@ -241,7 +243,8 @@ def usage():
print('OPTIONS:') print('OPTIONS:')
print(' -f, --format the output format to use.') print(' -f, --format the output format to use.')
print(' Valid options are amiwm, blackbox, compizboxmenu,') print(' Valid options are amiwm, blackbox, compizboxmenu,')
print(' fluxbox, fvwm, twm, icewm, jwm, windowmaker and pekwm') print(' fluxbox, fvwm, twm, icewm, jwm, openbox,')
print(' windowmaker and pekwm')
print(' -i, --icons enable support for icons in the') print(' -i, --icons enable support for icons in the')
print(' menus. Does not work with windowmaker or amiwm') print(' menus. Does not work with windowmaker or amiwm')
print(' --no-svg Do not use SVG icons even for WMs that support it') print(' --no-svg Do not use SVG icons even for WMs that support it')
@ -290,8 +293,9 @@ def icon_full_path(icon):
ext = os.path.splitext(icon)[1].lower() ext = os.path.splitext(icon)[1].lower()
if os.path.exists(icon): if os.path.exists(icon):
if ext == ".svg" or ext == ".svgz": if ext == ".svg" or ext == ".svgz":
# only jwm and icewm support svg icons # only jwm, icewm and openbox support svg icons
if (xopts['desktop'] == "jwm" or xopts['desktop'] == "icewm") and not xopts['nosvg']: if (xopts['desktop'] == "jwm" or xopts['desktop'] == "icewm"
or xopts['desktop'] == "openbox") and not xopts['nosvg']:
return icon return icon
else: else:
# icon is not svg # icon is not svg
@ -303,8 +307,9 @@ def icon_full_path(icon):
icon = icon_strip(icon) icon = icon_strip(icon)
icon_theme = gtk.icon_theme_get_default() icon_theme = gtk.icon_theme_get_default()
try: try:
# JWM and IceWM support svg icons # JWM, IceWM and Openbox support svg icons
if (xopts['desktop'] == "jwm" or xopts['desktop'] == "icewm") and not xopts['nosvg']: if (xopts['desktop'] == "jwm" or xopts['desktop'] == "icewm"
or xopts['desktop'] == "openbox") and not xopts['nosvg']:
icon = icon_theme.lookup_icon(icon, xopts['iconsize'], gtk.ICON_LOOKUP_FORCE_SVG) icon = icon_theme.lookup_icon(icon, xopts['iconsize'], gtk.ICON_LOOKUP_FORCE_SVG)
# but none of the other WMs does # but none of the other WMs does
else: else:
@ -880,6 +885,40 @@ def amiwm():
print(' ToolItem "{n}" "{c}" ""'.format(n=name, c=command)) print(' ToolItem "{n}" "{c}" ""'.format(n=name, c=command))
print("}") print("}")
def openbox():
print('<?xml version="1.0" encoding="UTF-8"?>')
print('<openbox_pipe_menu>')
spacing = ' '
for menu_category in menu():
category = menu_category.category
cat_name = category.decode()
cat_id = 'apps-{}-menu'.format(cat_name.lower())
cat_icon = category_icon(category)
cat_icon = icon_full_path(cat_icon)
if xopts['seticon'] and cat_icon is not None:
print('{s}<menu id="{d}" label="{c}" icon="{i}">'
.format(s=spacing, d=cat_id, c=cat_name, i=cat_icon))
else:
print('{s}<menu id="{d}" label="{c}">'
.format(s=spacing, d=cat_id, c=cat_name))
for app in menu_category.applist:
name = app.name.decode()
command = app.command
icon = app.icon
if xopts['seticon'] and icon is not None:
print('{s}{s}<item label="{n}" icon="{i}">'
.format(s=spacing, n=name, i=icon))
else:
print('{s}{s}<item label="{n}">'
.format(s=spacing, n=name))
print('{s}{s}{s}<action name="Execute">'.format(s=spacing))
print('{s}{s}{s}{s}<command>{c}</command>'.format(s=spacing,
c=command))
print('{s}{s}{s}</action>'.format(s=spacing))
print('{s}{s}</item>'.format(s=spacing))
print('{s}</menu>'.format(s=spacing))
print('</openbox_pipe_menu>')
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv[1:]) main(sys.argv[1:])

Loading…
Cancel
Save