2014-05-22

Adding Custom Menus for Linux Desktops

The "Start Menu" of a Linux Desktop usually comes with a predefined set of categories that make up the sub menus. If you have a lot of custom applications then you might want to group them under a dedicated sub menu instead of having them spread out over all the menu categories.

Adding sub menus and new categories on Linux Desktops is defined in the Desktop Menu Specification in Appendix C. It turns out that it is really simple and the following example from ImmobilienScout24 can serve as a base for your own custom menu.

You will need the following parts:
  1. A Desktop file using a custom category
  2. A Directory file defining the icon and description for the new sub menu
  3. The icon for the sub menu
  4. An XML file describing how to integrate the new sub menu into the menu structure and which categories of Desktop files to show in the new menu
The Desktop file describes the menu entry, in this example the VPN client:
The important part here is the Categories entry which specifies a generic category (Network) and a new custom category (X-IS24). The Desktop Menu Specification states that custom categories must start with X-. The Desktop file usually goes to /usr/share/applications.

The Directory file also conforms to the Desktop Entry Specification but is of Type Directory:
The XML file is placed usually in /etc/xdg/menus/applications-merged and extends the menu structure with the new sub menu, tying together the categories and the Directory file:
In this case we also exclude the X-IS24 category from the Network category so that our menu entries will not show up in several sub menus.

KDE, Gnome Classic, XFCE and other desktops with a regular menu all follow the same standards and show the new sub menu. Unity and Gnome 3 seem to have a fixed set of build-in categories and don't show the new sub menu as a new category.