Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

Chapter 12. Integrating Applications

When integrating an application with the GNOME Desktop, the system administrator usually performs tasks related to customizing the Applications menu structure, and MIME types, such as:

12.1. Customizing Menus

The GNOME menu system is based on the freedesktop.org Desktop Menu Specification and consists of three major sets of configuration and data files:
Desktop Entry Files (.desktop)
The .desktop files provide data about each menu item such as its name, command to run, and its icon. The .desktop entry files also specify the location of the menu item in the menu hierarchy, and keywords used for application search in the Activities Overview.
The system .desktop files are located in the /usr/share/applications/ directory. User-specific .desktop files are located in the ~/.local/share/applications/ directory.
The following is a sample .desktop file named ~/.local/share/applications/myapplication1.desktop:
[Desktop Entry]
Type=Application
Name=My Application 1
Icon=myapplication1
Exec=myapplication1
Categories=Network;WebBrowser;
MimeType=application/x-newtype
The file above specifies the application's name (My Application 1), the application's icon (myapplication1), and the command to run the application (myapplication1). It also places the application in a specified category (Network;WebBrowser;), and associates the application with the application/x-newtype MIME type.
Menu Definition Files (.menu)
The .menu files are XML configuration files that specify the order, hierarchy, and merging of both menus and menu items.
The machine-wide .menu files are located in the /etc/xdg/menus/ directory. User-specific .menu files are located in the ~/.config/menus/ directory and can be used to override the values specified in the machine-wide .menu files.
In particular, the /etc/xdg/menus/applications.menu file contains the definition of the Applications menu layout.
Directory Entry Files (.directory)
The .directory files provide data about each menu such as its name, and are located in the /usr/share/desktop-directories/.

Getting More Information

For more information describing the Desktop Entry Files, see the Desktop Entry Specification located at the freedesktop.org website:
For detailed information describing the implementation of the GNOME menus system, see the Desktop Menu Specification located at the freedesktop.org website:

12.1.1. Removing a Menu Item for Individual Users

The Applications menu customization for a given user is by default stored in the ~/.config/menus/gnome-applications.menu definition file. The location of that file can be overridden by setting the $XDG_DATA_HOME environment variable.
To override the Applications menu defaults, you first need to create a gnome-applications.menu file. Note that removing an item from the Applications menu and its submenus also removes it from the Applications view in the Activities Overview, thus preventing the user from searching for that item from within the Activities Overview.

Procedure 12.1. Example: Remove the Calculator menu item from the Accessories submenu

  1. Consult the contents of the /usr/share/applications/ directory and determine a .desktop file that corresponds to the menu item you want to remove:
    $ grep -r "Name=Calculator" /usr/share/applications/
    /usr/share/applications/gcalctool.desktop:Name=Calculator
    As shown above, the Calculator menu item corresponds to the /usr/share/applications/gcalctool.desktop file.
  2. Create a ~/.config/menus/gnome-applications.menu file:
    <!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"
    "http://www.freedesktop.org/standards/menu-spec/1.0/menu.dtd">
    
    <Menu>
      <Name>Applications</Name>
      <MergeFile type="parent">/etc/xdg/menus/gnome-applications.menu</MergeFile>
    
    <!-- Removes the Calculator from the Accessories submenu -->
      <Menu>
        <Name>Accessories</Name>
        <Exclude>
          <Filename>gcalctool.desktop</Filename>
        </Exclude>
      </Menu>
    <!-- END of Calculator removal content -->
    
    </Menu>
    As shown above, the file contains a <Menu> section that specifies the name of the submenu (Accessories), the name of the .desktop file (gcalctool.desktop), and includes the <Exclude> element.

12.1.2. Removing a Menu Item for All Users

The Applications menu customization for all users is by default stored in the /etc/xdg/menus/applications.menu definition file. The location of that file can be overridden by setting the $XDG_CONFIG_DIRS environment variable.
To override the Applications menu defaults, you need to edit that .menu file. Note that removing an item from the Applications menu and its submenus also removes it from the Applications view in the Activities Overview, thus preventing the user from searching for that item from within the Activities Overview.

Procedure 12.2. Example: Remove the Calculator menu item from the Accessories submenu

  1. Consult the contents of the /usr/share/applications/ directory and determine a .desktop file that corresponds to the menu item you want to remove:
    $ grep -r "Name=Calculator" /usr/share/applications/
    /usr/share/applications/gcalctool.desktop:Name=Calculator
    As shown above, the Calculator menu item corresponds to the /usr/share/applications/gcalctool.desktop file.
  2. Edit the /etc/xdg/menus/applications.menu file and add a new <Menu> section before the final </Menu> tag at the end of that .menu file using the <Exclude> element as shown below:
    <!-- Removes the Calculator from the Accessories submenu -->
    
      <Menu>
        <Name>Accessories</Name>
        <Exclude>
          <Filename>gcalctool.desktop</Filename>
        </Exclude>
      </Menu>
    
    <!-- END of Calculator removal content -->
    
    </Menu> <!-- End Applications -->

12.1.3. Removing a Submenu for Individual Users

The Applications menu customization for a given user is by default stored in the ~/.config/menus/gnome-applications.menu definition file. The location of that file can be overridden by setting the $XDG_DATA_HOME environment variable.
To override the Applications menu defaults, you first need to create a gnome-applications.menu file. Note that removing a submenu from the Applications menu also removes all menu items contained within that submenu from the Applications view in the Activities Overview, thus preventing the user from searching for those items from within the Activities Overview.

Example 12.1. Remove the System Tools submenu from the Applications menu

Create a ~/.config/menus/gnome-applications.menu file:
<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"
"http://www.freedesktop.org/standards/menu-spec/1.0/menu.dtd">

<Menu>
  <Name>Applications</Name>
  <MergeFile type="parent">/etc/xdg/menus/gnome-applications.menu</MergeFile>

<!-- Removes the System Tools submenu from the Applications menu-->

  <Menu>
    <Name>System Tools</Name>
    <Deleted/>
  </Menu>

<!-- END of System Tools removal content -->

</Menu>
As shown above, the file contains a <Menu> section that specifies the name of the submenu (System Tools), and includes the <Deleted/> tag.

12.1.4. Removing a Submenu for All Users

The Applications menu customization for all users is by default stored in the /etc/xdg/menus/applications.menu definition file. The location of that file can be overridden by setting the $XDG_CONFIG_DIRS environment variable.
To override the Applications menu defaults, you need to edit that .menu file. Note that removing a submenu from the Applications menu also removes all menu items contained within that submenu from the Applications view in the Activities Overview, thus preventing the user from searching for those items from within the Activities Overview.

Example 12.2. Remove the System Tools submenu from the Applications menu

Edit a /etc/xdg/menus/applications.menu file and add a new <Menu> section before the final </Menu> tag at the end of that .menu file using the <Deleted/> element as shown below:
<!-- Removes the System Tools submenu from the Applications menu-->

  <Menu>
    <Name>System Tools</Name>
    <Deleted/>
  </Menu>

<!-- END of System Tools removal content -->

</Menu>