Page 1 of 1

Create user's directories in LXDE/Lubuntu programs menu

Posted: Sat May 03, 2014 6:49 pm
by Iaups
From my own experience, there are several webpages which describe wrong methods to edit Lubuntu o LXDE programs menu. In this situation, the best source of information is the freedesktop specifications (which LXDE follows, so it is valid for Lubuntu):

http://standards.freedesktop.org/menu-spec/1.0/index.html

If an user only wants to add some directory entries with their own program entries at their user's custom menu, which only that user will be able to use, the procedure that document states is quite simple. Root permission are not requiered. There are three steps:

1) Writing the program entry files which are .desktop files. This process is well described in LXDE English Wiki: http://wiki.lxde.org/en/Main_Menu. They should be copied to ~/.local/share/applications user's folder.

2) Writing the directory entry files which are .directory files. This is going to be told in this "how to". They sould be copied onto ~/.local/share/desktop-directories user's folder.

3) Writing the merged application menu, a menu which adds the new directories without changing anything else. It is a .menu file and should be copied onto ~/.config/menus/applications-merged user's folder.

The operating system will read these user's localizations before reading the system ones.

Besides, icons for the menu and applications entries have to be created if the user does not want to use default or other programs' icons. These icons should be .png image files and as light as posible. They should be copied onto a folder in ~/.local/share/icons/hicolor/.

According to LXDE English Wiki, the .desktop files have to follow the format:

Code: Select all

[Desktop Entry]
Encoding=UTF-8
Exec=executable adress of the application
Icon=your .png icon in a folder in /home/yourUserName/.local/share/icons
Type=Application
Terminal=false
Name=The name of the application
GenericName=A decription of the application
Comment=The text Lubuntu/LXDE will show when the user places their mouse over the menu entry.
StartupNotify=false
Categories=The categories of the directories where the applications is going to appears.



The UTF-8 enconding is right for Western languages, so I suppose this line ought to be left out or changed if the Directory name is in other type of language. For instance, Google Chrome .desktop file has not got any encoding declaration and it includes other kinds of characters.

The .menu file matches categories to directories in order to decide where program entries are going to be placed. Several categories have to specified with a semicolon between them, e.g. "Game;Education". Categories created by users has to begin with "X-" in order to be distinguished from default or registered ones. The main registered categories are:

AudioVideo
A multimedia (audio/video) application

Audio
An audio application. Desktop entry must include AudioVideo as well

Video
A video application. Desktop entry must include AudioVideo as well

Development
An application for development

Education
Educational software

Game
A game

Graphics
Graphical application

Network
Network application such as a web browser

Office
An office type application

Settings
Settings applications. Entries may appear in a separate menu or as part of a "Control Center"

System
System application, "System Tools" such as say a log viewer or network monitor

Utility
Small utility application, "Accessories"


For example, this file (xmahjongg-bridge.desktop) can function as an entry for the xmahjongg video game:

Code: Select all

[Desktop Entry]
Encoding=UTF-8
Exec=/usr/games/xmahjongg -l bridge
Icon=/home/yourUserName/.local/share/icons/hicolor/48x48/xmahjongg48.png
Type=Application
Name=xmahjongg bridge
GenericName=Bridge Board
Comment=A colorful solitaire Mah Jongg game
Terminal=false
Categories=X-Mahjongg;
Version=1.0



I have not included the category "Game" so that this program entry does not appear at Games menu section. I will include it in a mahjongg sub-directory and I do not want it to be duplicated.



The .directory files have to stick to the format:

Code: Select all

[Desktop Entry]
Encoding=UTF-8
Type=Directory
Name=Directory name
Icon=folder or folder icon adress



Here, the comment about UTF-8 in the desktop paragraphs is equally appropiate.

If "folder" is written in the "Icon" line, the system will use the default folder menu icon which has a design similar to other menu directory icons.

As an directory entry for application entries of xmahjongg, I can write this mahjongg-mahjongg.directory file:

Code: Select all

[Desktop Entry]
Encoding=UTF-8
Type=Directory
Name=Mah Jongg
Icon=folder





The freedesktop specifications recommend to name these files as: nameOrganization-nameEntry.desktop and nameOrganization-nameEntry.directory so as to prevent names from being duplicated.



The .menu file has to begin with the doctype:

Code: Select all

<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"
"http://www.freedesktop.org/standards/menu-spec/menu-1.0.dtd">


The new directories have to be put in their places in the <Menu> tags structure and select the .desktop files or categories which are going to be included.

For example, if I wanted to create a new directory in the Games menu entry and include the .desktop files with the X-Mahjongg category, I ought to write:

Code: Select all

<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"
"http://www.freedesktop.org/standards/menu-spec/menu-1.0.dtd">
<Menu>
   <Name>Applications</Name>
   <Menu>   
      <Name>Games</Name>
      <Menu>
         <Name>mahjongg-mahjongg</Name>
         <Directory>mahjongg-mahjongg.directory</Directory>
         <Include>
            <Category>X-Mahjongg</Category>
         </Include>
      </Menu>
   </Menu>
</Menu>



The name of <Menu> items do not have to be the same as the categories included in them. For instance, the Games section in the menu is named "Games" and its categoy is "Game". The main .menu file of your system might be at /etc/xdg/lubuntu/menus/lxde-applications.menu. There you might read the <Menu> tags structure. An usual <Menu> tags structure is:

Code: Select all

<Menu>
   <Name>Applications</Name>
    <Menu>
      <Name>Accessories</Name>
   </Menu>
   <Menu>
      <Name>Universal Access</Name>
   </Menu>
   <Menu>
      <Name>Development</Name>
   </Menu>
   <Menu>
      <Name>Education</Name>
   </Menu>
   <Menu>
      <Name>Electronics</Name>
   </Menu>
   <Menu>
      <Name>Games</Name>
   </Menu>
   <Menu>
      <Name>Graphics</Name>
   </Menu>
   <Menu>
      <Name>Internet</Name>
   </Menu>
   <Menu>
      <Name>Multimedia</Name>
   </Menu>
   <Menu>
      <Name>Office</Name>
   </Menu>
   <Menu>
      <Name>Other</Name>
   </Menu>

<!-- Administration Menu, to include in Layout section -->
   <Menu>
      <Name>Administration</Name>
   </Menu>

<!-- Preferences Menu, to include in Layout section -->
   <Menu>
      <Name>DesktopSettings</Name>
   </Menu>

</Menu>



If you want to know more accurately how to include or exclude applications entries in directories, you can read the freedesktop specifications:

http://standards.freedesktop.org/menu-spec/1.0/ar01s04.html

<Include>
An <Include> element is a set of rules attempting to match some of the known desktop entries. The <Include> element contains a list of any number of matching rules. Matching rules are specified using the elements <And>, <Or>, <Not>, <All>, <Filename>, and <Category>. Each rule in a list of rules has a logical OR relationship, that is, desktop entries which match any rule are included in the menu.

<Include> elements must appear immediately under <Menu> elements. The desktop entries they match are included in the menu. <Include> and <Exclude> elements for a given <Menu> are processed in order, with queries earlier in the file handled first. This has implications for merging, see the section called “Merging”. See the section called “Generating the menus” for full details on how to process <Include> and <Exclude> elements.



<Exclude>
Any number of <Exclude> elements may appear below a <Menu> element. The content of an <Exclude> element is a list of matching rules, just as with an <Include>. However, the desktop entries matched are removed from the list of desktop entries included so far. (Thus an <Exclude> element that appears before any <Include> elements will have no effect, for example, as no desktop entries have been included yet.)



<Filename>
The <Filename> element is the most basic matching rule. It matches a desktop entry if the desktop entry has the given desktop-file id. See Desktop-File Id.



<Category>
The <Category> element is another basic matching predicate. It matches a desktop entry if the desktop entry has the given category in its Categories field.



<All>
The <All> element is a matching rule that matches all desktop entries.


<And>
The <And> element contains a list of matching rules. If each of the matching rules inside the <And> element match a desktop entry, then the entire <And> rule matches the desktop entry.



<Or>
The <Or> element contains a list of matching rules. If any of the matching rules inside the <Or> element match a desktop entry, then the entire <Or> rule matches the desktop entry.



<Not>
The <Not> element contains a list of matching rules. If any of the matching rules inside the <Not> element matches a desktop entry, then the entire <Not> rule does not match the desktop entry. That is, matching rules below <Not> have a logical OR relationship.



I hope this will help anyone customize their LXDE/Lubuntu menu.



A method to edit the menu for all of the users intead of only one user is told to be described in:

http://lxlinux.com/#9