Xfce Wiki

Sub domains
 

自定义 Xfce 菜单

此页介绍如何在4.5或更高版本 Xfdesktop 上自定义菜单。对于早期版本,您可以使用 libxfce4menu 的 GUI。

GNU 许可的 LXDE 的图形菜单编辑器 LXMenuEditor ,从 Xfce 4.8.0和LXMenuEditor 20110523 起,它也可以用于 XFCE 了。

xfdesktop 会安装什么文件

Xfdesktop 会安装菜单文件和 .desktop 文件以及一些定义菜单的非 xfdesktop 的 .desktop 文件。自定义菜单就需要修改这些文件。这里描述修改的菜单文件由环境变量 $XDG_CONFIG_HOME 确定(通常为空,所以是 ~/.config/menus/xfce-applications.menu)和一些你的主目录中 .desktop 文件。

你的修改什么时候生效

当 xfdesktop 会话启动时,如果菜单文件的目录存在,修改立即生效。同样地,当 xfdesktop 会话启动时,如果你主目录中的 .local/share/applications 目录存在的话,对 .desktop 文件的修改也立即生效。

复制菜单文件

只有你想要修改硬编码的项(通常在“设置”菜单以上,及最后一个子菜单以下)或者说你需要修改子菜单的定义时才需要这样做。

创建 ~/.config/menus 目录(如果还不存在):

mkdir ${XDG_CONFIG_HOME:-~/.config}/menus/

复制已安装的菜单文件到先于默认安装的菜单文件路径的 xfdesktop 查找的路径中(在大多数系统上 $prefix = /usr)。

cp $prefix/etc/xdg/menus/xfce-applications.menu ${XDG_CONFIG_HOME:-~/.config}/menus

或者

cp $prefix/etc/xfce/xdg/menus/xfce-applications.menu ${XDG_CONFIG_HOME:-~/.config}/menus

复制 .desktop 文件

例如,要复制Web浏览器的 .desktop 文件到主目录中的 .local/share/applications 目录 (在大多数系统上 $prefix = /usr):

cp $prefix/share/applications/xfce4-web-browser.desktop ~/.local/share/applications 

或者

cp /usr/share/applications/xfce4-web-browser.desktop ~/.local/share/applications

隐藏菜单项

如果你想隐藏菜单项,复制他的 .desktop 文件,编辑并添加一行 NoDisplay=true


的解释,NoDisplay=true 会在菜单上隐藏程序,但 mime 类型的关联仍然存在。Hidden=true 等价于删除这个文件。

只隐藏根菜单项

如果你只想删除根菜单项,复制它们的 .desktop 文件,编辑并删除 X-Xfce-Toplevel Category。

Xfdesktop 默认会安装下面这些根菜单项(在大多数系统上 $prefix = /usr):

  • $prefix/share/applications/xfce4-about-xfce.desktop
  • $prefix/share/applications/xfce4-file-manager.desktop
  • $prefix/share/applications/xfce4-help.desktop
  • $prefix/share/applications/xfce4-logout.desktop
  • $prefix/share/applications/xfce4-run-program.desktop
  • $prefix/share/applications/xfce4-terminal.desktop
  • $prefix/share/applications/xfce4-web-browser.desktop

例如,把Web浏览器从根菜单中删除,复制它的 .desktop 文件,编辑并修改 Categories=X-XFCE;X-Xfce-Toplevel;Categories=X-XFCE;

添加菜单项

为每个菜单项创建一个 .desktop。例如,一个 Eclipse 的菜单项,在 ~/.local/share/applications中创建文件 eclipse.desktop

[Desktop Entry]
Version=1.0
Type=Application
Encoding=UTF-8
Exec=eclipse
Icon=eclipse
StartupNotify=false
Categories=X-XFCE;X-Xfce-Toplevel;
OnlyShowIn=XFCE;
Name=Eclipse
Comment=Eclipse Java IDE

如果你喜欢用 GUI 工具(可以浏览选择图标),你可以用下面的命令创建 .desktop 文件

exo-desktop-item-edit --create-new ~/.local/share/applications

但这样新建的文件类别(Category)里面只有 Application, 可能需要再编辑才行。

类别(Category)决定菜单项会显示在哪。要在根菜单中显示,添加 X-Xfce-Toplevel 类别。要在子菜单中显示,添加至少一个已定义的子菜单类别。这个可以在 ${XDG_CONFIG_HOME:-~/.config}/menus/xfce-applications.menu 文件中找到。例如这是一个“附件”菜单的定义:

    <Menu>
        <Name>Accessories</Name>
        <Directory>xfce-accessories.directory</Directory>
        <Include>
            <Or>
                <Category>Accessibility</Category>
                <Category>Core</Category>
                <Category>Legacy</Category>
                <Category>Utility</Category>
            </Or>
        </Include>
    </Menu>

任何包含 Accessibility, Core, Legacy 及 Utility 类别的并没有 NoDisplay=true 的 .desktop 文件都会显示在“附件”菜单下。

"其他" 子菜单

如果有 .desktop 文件配置了要在菜单中显示,但没有任何已定义的类别(用于包含他们到已定义的菜单中),“其他”菜单就会显示这些菜单项。这条规则适用于 $prefix/share/applications/和 ~/.local/share/applications 中的 .desktop 文件。

如果你的系统有”其他“,但你不想要它,复制菜单项的 .desktop 文件,修改它的类别,使它被包含到其他子菜单中去。

创建子菜单

创建一个新的子菜单, 添加一个 “Menu” 元素到 ~/.config/menus/xfce-applications.menu 到和其他 xfdesktop 子菜单(比如“图像”,“多媒体”)相同的级别。再添加一个 “Name” 元素,及另外两个必须的元素:第一,“Directory” 元素,它对关联子菜单和 desktop 文件,及一个相应的合适的图标。. 第二,“Category” 元素,它关联 .desktop 文件和子菜单。建议自定义类别时使用“X-“开头,这是非标准的类别的前缀约定。例如,创建一个子菜单,用你喜欢的文件管理器打开不同的文件夹。新的菜单项,应该类似于下面这样:

  <Menu>
    <Name>Folders</Name>
    <Directory>folders.directory</Directory>
    <Include>
      <Category>X-Folders</Category>
    </Include>
  </Menu>

接下来,创建 ~/.local/share/desktop-directories/folders.directory 文件,内容如下:

[Desktop Entry]
Version=1.0
Type=Directory
Icon=file-manager
Name=Folders
Comment=Folders viewed in a file manager

这提供了子目录的显示名字及合适的图标。

最后,在 ~/.local/share/applications 文件夹中创建 .desktop 文件来构成子菜单。为了显示在子菜单中,添加自定义的类别到”Categories” 列表中。我们就把它命名为 thunar-home.desktop 它的内容类似于下面这样:

[Desktop Entry]
Version=1.0
Type=Application
Exec=/usr/local/bin/thunar /usr/home/yourname
Icon=file-manager
StartupNotify=false
Categories=X-Folders;
OnlyShowIn=XFCE
Name=home
Comment=home displayed in Thunar

做完这些,你会发现多了一个叫 “Folders” 的子菜单,图标为文件管理器的图标。这个菜单项,应该在 Thunar 里面显示你的主目录。当然,你可以添加更多的条目作为到常用的位置 /cdrom,/stick,/,以及其他你觉得可以的位置的快捷方式。

强制修改

这通常没有必要并且不一定起作用;注销然后再进入才总是有用的。

如果菜单没有自动更新,试一下

xfdesktop --reload

如果没有起作用,再试一下

killall -HUP xfdesktop

问题

Answered

Question: I setup several machines for my company. After migrating all the software to the new version 9.04 we realized we cannot use the custom menus that points to our software with specific variables. Answer: In Jaunty the appropriate file might be found in /etc/xdg/xubuntu/menus/xfce-applications.menu and not in /etc/xdg/menus/xfce-applications.menu. Everything else should work as described above. Could be any other *buntu-flavor in the path also, I have no appropriate machine to compare. Also note that you should not only extend your Layout-Section but also your Include-Section …

Question: Primarily i wanted to modify the menu-structure. Just copying xfce-applications.menu to my home didn't do it. After tracing around with strace and inotify i finally logged out of xfce and back in. Before that my local copy didnt even get touched. xfdesktop –reload didn't work either. Modifying menu entries was ok but changes to the structure of the menu file had no effect. Answer: Menu file changes are implemented immediately if the menu file's directory exists when the xfdesktop session starts. Any further changes you made after logging out of the Xfce session and back in again should have been reflected in the menu immediately.

Question: I want to add an entry for an application that's installed by hand, rather than through the package manager. If I make a local copy of /etc/xdg/xubuntu/menus/xfce-applications.menu, then when I add a further application using the package manager, won't it change only the master? Will I have to re-copy and re-edit? Answer: No. The menu file defines which categories of entry go where. Your further application will appear in the defined place(s). If not, compare its categories with the categories in the menu file and adjust accordingly. Another possible gotcha is that the .desktop file has an OnlyShowIn or NotShowIn line that does not match Xfce.

Unanswered

  • What do i do, if the above does not work? (only xfce's own desktop files are seen, not even the one created with exo-desktop-item-edit, not to speak from common desktop files in both /usr/share/applications/ and ~/.local/share/applications/)
  • Where do i find a log or anything like that, actually giving me a clue other than simply empty space in the menu?
  • I run Jaunty and need to make the menu to be multi-level, which, in previous versions I believe, could be achieved by editing '/etc/X11/xdg/xfce4/desktop/menu.xml' and replace style=“simple” with style=“multilevel” in the <include>. How do I do this in Jaunty? I need this because I have certain applications under Wine which have very many start-menu entries and they are all merged into one menulevel, which is really annoying to navigate thru. Please help …