2

I want to create an application menu in Xfce that contains no submenus, rather just contains application launchers for all .desktop files in the virtualization category. If you are uncertain as to what I am referring to, please refer to the screenshot below.

enter image description here

In this screenshot, if I had my way, there would be no virtualization submenu, rather "Arch Linux", "CentOS 7-1511", "Debian 8.2", etc. and all the other .desktop files for these VMs would be placed in the Virtualization application menu directly. I have written custom .menu files before, and I have tried:

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

<Menu>
  <Name>Virtualization</Name>
  <Directory>xfce-virtualization.directory</Directory>
  <!-- Read standard .directory and .desktop file locations -->
  <DefaultAppDirs/>
  <DefaultDirectoryDirs/>

  <!-- Read in overrides and child menus from applications-merged/ -->
  <DefaultMergeDirs/>
  <!-- Virtualization Software-->
  <Include>
    <And>
      <Category>Virtualization</Category>
    </And>
  </Include>

  <Layout>
    <Merge type="menus"/>
  </Layout>

</Menu>

but it gave me an empty virtualization application menu.

  • Not sure what went wrong in your case, but I have added a working example in my answer below. I didn't use <Directory> tag and "Merge" stuffs, since I see these as optional. – clearkimura Jan 31 '16 at 11:13
2

For the applications' shortcuts to be found, the .desktop files must be located in one of default directories, such as ~/.local/share/applications for current user or /usr/share/applications for all users.

If you are unsure what went wrong in your case, check out my working example tested in Xubuntu 14.04 (Xfce 4.10) as below.

Example setup

The following setup assumes that:

  • the shortcuts (.desktop files) have been created and include at least one category, which could be existent (i.e. "System") or non-existent (i.e. "Custom", "Virtual");
  • the shortcuts have been moved to the shared or local directory i.e. ~/.local/share/applications;
  • the menu (.menu file) have been created such that the shortcuts from particular defined category is included (i.e. "Virtual");
  • the menu is placed somewhere appropriate i.e. ~/.config/menus directory

The .menu file contains the following.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE Menu
  PUBLIC '-//freedesktop//DTD Menu 1.0//EN'
  'http://standards.freedesktop.org/menu-spec/menu-1.0.dtd'>
<Menu>
    <Name>Parent</Name>
    <!--This defines where to find .desktop files-->
    <DefaultAppDirs />
    <!--This affects what entries will appear under "Parent"-->
    <Include>
        <Category>Virtual</Category>
        <Category>X-Xfce-Toplevel</Category>
    </Include>
    <!--This includes what entries will appear under "Child" -->
    <Menu>
        <Name>Child</Name>
        <Include>
        <Filename>exo-terminal-emulator.desktop</Filename>
        </Include>
    </Menu>
    <!--This affects how will the entries appear under "Parent"-->
    <Layout>
        <Menuname>Child</Menuname>
        <Filename>xfce4-about.desktop</Filename>
        <Filename>exo-file-manager.desktop</Filename>
        <Filename>exo-terminal-emulator.desktop</Filename>
        <Filename>vm-test.desktop</Filename>
    </Layout>
</Menu>

In this example, I have only created one custom shortcut named vm-test.desktop that will appear under "Parent" menu. The other .desktop files are already existing in ~/.local/share/applications and /usr/share/applications directories. I had included these on purpose, to show it works in both ways.

Example screenshots

Add "Application Menu" applet to the Xfce panel, and select "Use custom menu file" and load the .menu file from the share or local directory. Finally, click on the menu applet to see the shortcuts.

Xfce menu applet properties

Xfce menu applet demo

Discovering shortcuts

The shortcuts that have been added to ~/.local/share/applications directory will also be found automatically by Whisker Menu or Applications Menu applet (using default .menu file).

The .desktop files, which specify non-existent category or do not specify any category, will appear under "Other" category. If it has several or more categories, it will appear in the existent category only i.e. "System" and does not appear under "Other".

To understand this, see the content of .desktop file I have used in example above.

[Desktop Entry]
Version=1.0
Type=Application
Name=VirtualBox VM test
Comment=Run "test" VM in VirtualBox
Exec=virtualbox --startvm "test"
Icon=virtualbox
Terminal=false
StartupNotify=false
Categories=Custom;System;Virtual;
Name[en_US]=VirtualBox VM test
GenericName=VM test

As such, the custom shortcut will appear under "System" category in Application Menu based on the specified categories. Additionally, because it has specified "Virtual" category, the custom .menu file can easily include any .desktop files that have "Virtual" category.

Additional notes

In Debian, there were no .desktop files by default in ~/.local/share/applications and ~/.config/menus directory does not exist (need to create this manually).

Tested working in Xubuntu 14.04 (Xfce 4.10) and Debian 8.3 Xfce (Xfce 4.10) 32-bit systems.

References

  • Added content of .desktop file used in my example. Now it is better understood on how the custom shortcut is included in the custom menu by specifying the Categories=. – clearkimura Jan 31 '16 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.