This patch implements support for icons in user-defined menus into Openbox (the patch is for version 3.4.6.1). Image loading is done using the Imlib2 library. I chose Imlib2 because it's pretty fast, it's easy to use, supports many file formats (tested xpm, gif, jpeg, png) and doesn't introduce too much bloat (it depends :)).
What's new?
Syntax of configuration files (namely rc.xml and menu.xml) has been changed slightly to allow users to associate icons to menu entries. This is done by specifying path to icon file in the new "icon" attribute in "<item>" element, e.g:
<item label="Vim" icon="/usr/share/pixmaps/vim-32.xpm">
<action name="Execute"><execute>x-terminal-emulator -T Vim -e vim</execute></action>
</item>
If user doesn't want to display any icons in his user-defined menus, he/she can disable icons in rc.xml, inside "<menu>" section:
<menu>
.
.
.
<showIcons>no</showIcons>
.
.
.
</menu>
Default value is "yes".
(New boolean variable "config_menu_user_show_icons" has been added to source code.)
An icon is loaded (using menu_item_attach_icon()) when a new entry of menu is created. Fortunately, I haven't notice any performance problems because of this :).
The dark side of the patch
* Imlib2 is a new run-time dependency (unfortunately, I don't have enough experience with autoconf to add an option like --disable-icons-in-menus).
* There's no cache for icons. If one icon happens to be in menu 100 times, it will be loaded 100 times (but we don't need to bother with cache coherency :)). However, adding some caching shouldn't be difficult.
How to get icons working in Debian menu
To have icons in your Debian menu, you need to update your /etc/menu-methods/openbox (see attachment for example) file and run "update-menus" as a root.
Created attachment 1722[details]
Support of icons in user-defined menus (for 3.4.7-pre3)
I ported the patch to 3.4.7-pre3 and added some enhancements. Caching is much better now, and icons can be disabled at compile time using --disable-imlib2 option.
Please note that before applying this patch, the patch for bug #3589 must be applied first.
Created attachment 1729[details]
On-demand loading of icons, XML schema updates
This patch updates previous patch (id=1722).
I realized that I had accidentaly forgotten to include updated XML schema (data/menu.xsd, data/rc.xsd) in previous patch. This patch includes the update.
Moreover, icon-handling code i openbox/menu.c has been changed, so icons are loaded when they are needed. This speeds start up of Openbox a bit.
im not comfortable with on-demand loading blocking the menu appearing. it should be in a separate thread or else done beforehand.
right now the resizing is still blocking the menu appearing, maybe we should force them to be resized appropriately when loaded, rather than waiting until we want to display it.
Created attachment 1709 [details] Implements icons in user-defined menus
Created attachment 1710 [details] Menu method for Debian menu with icons
Created attachment 1711 [details] Implements icons in user-defined menus (generated by diff -pu)
Created attachment 1729 [details] On-demand loading of icons, XML schema updates This patch updates previous patch (id=1722). I realized that I had accidentaly forgotten to include updated XML schema (data/menu.xsd, data/rc.xsd) in previous patch. This patch includes the update. Moreover, icon-handling code i openbox/menu.c has been changed, so icons are loaded when they are needed. This speeds start up of Openbox a bit.