openbox
openbox copied to clipboard
Add XDG applications menu support
Hi,
I like openbox very much, there's only one thing that annoys me: I can't use XDG applications menu, although that's the de facto standard on almost all unices. I can create some dirty hacks with scripts and pipe menus, but that just feel not right. IMHO openbox should support the de facto standard application menu without any hacks. I've checked the source to figure out what would be the best way to do that. Here are my findings: First I was thinking about to introduce a new xml tag in config, like "<xdgapps/>", but that would unnecessarily complicate parse_menu() in config.c to keep the order of config_menu_files. Therefore I though it would be better to have "<file>__xdgapps</file>", there __xdgapps is not a real filename (not ending in ".xml") but a special keyword.
To handle this special menu "file", only one modification would be needed in menu.c line 84. The following:
for (it = config_menu_files; it; it = g_slist_next(it)) {
if (obt_xml_load_config_file(menu_parse_inst,
would became
for (it = config_menu_files; it; it = g_slist_next(it)) {
if (!strcmp(it->data, "__xdgapps") && obt_xml_load_from_desktop_files(menu_parse_inst))
{
loaded = TRUE;
obt_xml_tree_from_root(menu_parse_inst);
obt_xml_close(menu_parse_inst);
}
else if (obt_xml_load_config_file(menu_parse_inst,
and "obt_xml_load_from_desktop_files()" would create the same xml tree in memory by parsing /usr/share/applications/*.desktop files as if it were loaded from a menu.xml (all attributes of a menu item, "id", "label", "icon", "execute" action, parent menu (category), localized "label" etc. can be easily read from those .desktop files too, one would only need to use those parsed values when adding xml nodes to menu_parse_inst). Therefore other parts of the code (particularly parse_menu() in menu.c) wouldn't know the difference, and there's no need for further modifications. Even config.c would be intact.
The big advantage of this approach would be that it requires minimal modifications to the existing code, and it's configuration scheme is backward compatible. What's more, since this special value does not end in ".xml", it's guaranteed that no existing configuration would conflict with this patch.
What do you say? Is this a proper way to add XDG applications menu to openbox? bzt