Development/Howto/MenuSystem
From Mandriva Community Wiki
Contents |
[edit] Presentation
Mandriva Linux systems used the menu package designed by Debian since Mandrake 7.1, until Mandriva Linux 2006.0.
Starting with Mandriva Linux 2007.0, it will use Freedesktop.org XDG menu system, described here.
This excellent software provides a Window-Manager independent way to register an application on the system. Most of the time, this registration will become effective in the Start button or alike of your favourite Window Manager.
A menu file is first dropped in /usr/lib/menu, and then a script is run to regenerate the menu of each wm, according to files in /etc/menu-methods/. Later, the file can be edited with Menudrake, for the user or for the system.
[edit] In practice
[edit] Overview
It works like this: each package includes a file in the directory /usr/lib/menu/. Most of the time the filename will be the name of the package. In this file, it will have one line per menu-entry (or several lines concatenated through "\"), like this:
?package(xbase):command="/usr/bin/X11/xedit" icon="xbase.png" needs="X11" section="Applications/Editors" \ title="Xedit" longtitle="The basic editor for the X Window system" \ mimetypes="text/html,text/plain" accept_url="false" multiple_files="true"
It is suggested that you put the menu file within the spec, instead of creating a separate source for it. To do that you can :
install -m 755 -d $RPM_BUILD_ROOT%{_menudir}/
cat << EOF > $RPM_BUILD_ROOT%{_menudir}/myprogram
?package(xbase):command="/usr/bin/X11/xedit" \
icon="xbase.png" needs="X11" section="Applications/Editors" \
title="Xedit" longtitle="The basic editor for the X Window system" \
mimetypes="text/html,text/plain" accept_url="false" \
multiple_files="true"
EOF
in the %install section. You noticed the %{_menudir} macro. It shall expand to /usr/lib/menu.
[edit] Detailed description of the entry
The format of the menu files is described in the menufile man pages, and in the menu package documentation. But here is a short explanation
- command : the command to launch ; it can be absolute or not (if so, it will use the PATH of the Window-Manager).
- icon : the png icon to be used by the Window Manager to refer to the application ; mainly used in the start button alike, but also can be used to dock (include in a toolbar/panel) the app ; therefore, you will not give an absolute path, and provide three classes of icons in your rpm package: a 16x16, a 32x32, and a 48x48, respectively in /usr/share/icons/mini, /usr/share/icons, and /usr/share/icons/large with the same name. There are macros for these three directories: %{_miconsdir} ; %{_iconsdir} and %{_liconsdir}.
- needs : there are three classes of needs:
- x11 indicates an application that will be launched under a private window provided by the X-Window system;
- text indicates an application needing a terminal to be run (for example, this is the case for telnet, gnuplot, etc.);
- the last one is the name of a Window Manager, in order to prevent the other WM's from proposing this app; for example you will like that iceconf appears in the menu only under icewm, and you will use needs="icewm" for this one.
- section : the section where the application will go ; it has to be normalized in order to be efficient, therefore see for the complete menu structure
- title : the name under which the application will be registered in the start button alike of the Window Managers
- longtitle : used by the Window Managers which support tooltips to display more information
- startup_notify : used by GNOME and KDE to enable/disable Startup notification for this applications. Default value is false but it should always be specified, to help package maintainance.
- mimetypes : used to link program with predefined mimetypes. If this mimetype is not recognized by KDE or GNOME, it must be added in mandrake-mime package (see in CVS, soft/mandrake-mime modules). Mimetypes are separated by commas. These keywords and following ones are only supported with Mandrakelinux 8.1 and above.
- accept_url : used for mimetype support. Specify if the program accepts url on the command line. If not specified, default is false.
- multiple_files : used for mimetype support. Specify if the program accepts multiple files (or urls) on the command line. If not specified, default is false.
[edit] Post install script
Whenever root runs update-menus, it will check all new or changed menufiles in /etc/menu and /usr/lib/menu, and run the installation scripts Window Managers should provide in /etc/menu-methods on them. Use our special macros for that:
%post
%{update_menus}
%postun
%{clean_menus}
This will run the update_menu script, which updates the menu for each wm.
[edit] Icons
You will have to provide the three icons described earlier. One popular way of doing it is to declare the three icons (we used to bzip2 them, but as we now use png in stead of xpm, there's no reason to), with Source: tags, and install them in appropriate directories in the %install section:
Source11: %{name}.16.png
Source12: %{name}.32.png
Source13: %{name}.48.png
# ..
%install
# ..
install -m644 %{SOURCE11} -D $RPM_BUILD_ROOT%{_miconsdir}/%{name}.png
install -m644 %{SOURCE12} -D $RPM_BUILD_ROOT%{_iconsdir}/%{name}.png
install -m644 %{SOURCE13} -D $RPM_BUILD_ROOT%{_liconsdir}/%{name}.png
In the past, we used xpm, but we switched to png. If you update a package, you can use convert from ImageMagick to transform an xpm to a png.
convert icon.xpm icon.png
[edit] On the WM side
In order to be updated, a window manager should drop a file in the /etc/menu-methods/. The documentation is in /usr/share/doc/menu-*/, with a lot of examples. And you can find documents on the internet such as http://www.handhelds.org/~nelson/menu/
[edit] Menu Structure
Here's the new menu structure to be used beginning with version 10.0. It is mandatory to use it. rpmlint will complain if not used.
Office/Accessories Office/Address Books Office/Communications/Fax Office/Communications/PDA Office/Communications/Phone Office/Drawing Office/Graphs Office/Presentations Office/Publishing Office/Spreadsheets Office/Tasks Management Office/Time Management Office/Wordprocessors Internet/Chat Internet/File Transfer Internet/Instant Messaging Internet/Mail Internet/News Internet/Other Internet/Remote Access Internet/Video Conference Internet/Web Browsers Internet/Web Editors Multimedia/Graphics Multimedia/Sound Multimedia/Video System/Archiving/Backup System/Archiving/CD Burning System/Archiving/Compression System/Archiving/Other System/Configuration/Boot and Init System/Configuration/Hardware System/Configuration/Networking System/Configuration/Other System/Configuration/Packaging System/Configuration/Printing System/File Tools System/Monitoring System/Session/Windowmanagers System/Terminals System/Text Tools More Applications/Accessibility More Applications/Communications More Applications/Databases More Applications/Development/Code Generators More Applications/Development/Development Environments More Applications/Development/Interpreters More Applications/Development/Tools More Applications/Documentation More Applications/Editors More Applications/Emulators More Applications/Finances More Applications/Games/Adventure More Applications/Games/Arcade More Applications/Games/Boards More Applications/Games/Cards More Applications/Games/Other More Applications/Games/Puzzles More Applications/Games/Sports More Applications/Games/Strategy More Applications/Games/Toys More Applications/Sciences/Artificial Intelligence More Applications/Sciences/Astronomy More Applications/Sciences/Biology More Applications/Sciences/Chemistry More Applications/Sciences/Computer Science More Applications/Sciences/Data Visualization More Applications/Sciences/Electricity More Applications/Sciences/Geosciences More Applications/Sciences/Image Processing More Applications/Sciences/Mathematics More Applications/Sciences/Numerical Analysis More Applications/Sciences/Other More Applications/Sciences/Parallel Computing More Applications/Sciences/Physics More Applications/Sciences/Robotics More Applications/Shells
[edit] Tips
In order to generate a menu only for a wm, you should put a line like this one :
?package(fluxbox):needs=fluxbox \
section="Fluxbox" \
title="Reload Configuration" \
command="reconfig" \
longtitle="Reload Configuration" \
icon="fluxbox.png"
Since there is a clause needs=fluxbox, it will only be updated for fluxbox. The same can be used for specific wm.

