Difference between revisions of "Desktop entries (简体中文)"

From ArchWiki
Jump to navigation Jump to search
m (fixed category (see Help:i18n))
m (隐藏窗口启动)
 
(20 intermediate revisions by 4 users not shown)
Line 4: Line 4:
 
[[en:Desktop entries]]
 
[[en:Desktop entries]]
 
[[ja:デスクトップエントリ]]
 
[[ja:デスクトップエントリ]]
 +
[[ru:Desktop entries]]
 
{{Related articles start}}
 
{{Related articles start}}
 
{{Related articles end}}
 
{{Related articles end}}
{{TranslationStatus (简体中文)|Desktop_entries|2015-11-24|409972}}
+
{{TranslationStatus (简体中文)|Desktop_entries|2018-07-03|519256}}
 +
[https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html XDG 桌面配置项规范]为应用程序和[[desktop environment|桌面环境]]的菜单整合提供了一个标准方法。只要桌面环境遵守[https://specifications.freedesktop.org/menu-spec/menu-spec-latest.html 菜单规范],应用程序图标就可以显示在系统菜单中。
  
桌面配置项(Desktop entries)是 [http://www.freedesktop.org/wiki/ freedesktop.org(自由桌面社区)] 制订的一个用于规范 [[Xorg]] 环境中程序运行行为的标准。它是一个配置文件,描述了某个应用程序如何被启动以及怎样在菜单中以图标形式出现。大部分桌面配置项是 {{ic|.desktop}} 和 {{ic|.directory}} 文件。本文将概述如何创建一个合规可用的桌面配置项,主要面向软件包发布者和维护者,但对软件开发者及其他人也会是有用的。
+
每个桌面项必须包含 {{ic|Type}} 和 {{ic|Name}},还可以选择定义自己在程序菜单中的显示方式。
  
 
桌面配置项大致分为三类:
 
桌面配置项大致分为三类:
  
; 应用程序 : 指向某个应用程序的快捷方式
+
; 应用程序 : 文件后缀是 ''.desktop'',定义如何启动程序,支持哪些 MIME。
; 链接 : 指向某个网址的链接
+
; 链接 : 文件后缀是 ''.desktop'',定义指向某个 {{ic|URL}} 的链接。
; 目录 : 某个菜单项元数据的容器
+
; 目录 : 文件后缀是 ''.directory'',定义应用程序菜单中的子菜单。
  
 
下列章节概述如何创建它们并使其生效。
 
下列章节概述如何创建它们并使其生效。
 +
 +
{{ic|.desktop}} 文件中还定义了数据文件的 MIME 类型关联。[[Default applications (简体中文)]] 介绍了它们的配置方法。 
 +
 +
[[XDG MIME Applications]] 会使用应用程序项的 {{ic|MimeType}} 字段。
 +
 +
将 [[XDG Autostart|XDG 自动启动程序]]项放到特定位置,可以[[Autostarting|自动启动]]应用程序。
  
 
== 应用程序配置项 ==
 
== 应用程序配置项 ==
  
Desktop entries for applications, or {{ic|.desktop}} files, are generally a combination of meta information resources and a shortcut of an application. These files usually reside in {{ic|/usr/share/applications}} or {{ic|/usr/local/share/applications}} for applications installed system-wide, or {{ic|~/.local/share/applications}} for user-specific applications. User entries take precedence over system entries.
+
应用程序配置项,即 {{ic|.desktop}} 文件是元信息资源和应用程序快捷图标的集合。系统程序的配置项通常位于 {{ic|/usr/share/applications}} {{ic|/usr/local/share/applications}}目录,单用户安装的程序位于 {{ic|~/.local/share/applications}} 目录,桌面环境会优先使用用户的配置项。
  
 
=== 范例文件 ===
 
=== 范例文件 ===
  
Following is an example of its structure with additional comments. The example is only meant to give a quick impression, and does not show how to utilize all possible entry keys. The complete list of keys can be found in the [http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s05.html freedesktop.org specification].
+
下面是一个示例结构和注释,这个示例文件没有使用所有的键值,[https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys freedesktop.org 规范]包含了完整的键值列表.
  
 
  [Desktop Entry]
 
  [Desktop Entry]
  Type=Application                          # Indicates the type as listed above
+
   
  Version=1.0                              # The version of the desktop entry specification to which this file complies
+
# The type as listed above
  Name=jMemorize                            # The name of the application
+
  Type=Application
  Comment=Flash card based learning tool    # A comment which can/will be used as a tooltip
+
  Path=/opt/jmemorise                      # The path to the folder in which the executable is run
+
# The version of the desktop entry specification to which this file complies
  Exec=jmemorize                            # The executable of the application.
+
  Version=1.0
  Icon=jmemorize                           # The name of the icon that will be used to display this entry
+
  Terminal=false                            # Describes whether this application needs to be run in a terminal or not
+
# The name of the application
  Categories=Education;Languages;Java;      # Describes the categories in which this entry should be shown
+
  Name=jMemorize
 +
 +
# A comment which can/will be used as a tooltip
 +
  Comment=Flash card based learning tool
 +
 +
# The path to the folder in which the executable is run
 +
  Path=/opt/jmemorise
 +
 +
# The executable of the application, possibly with arguments.
 +
  Exec=jmemorize
 +
 +
# The name of the icon that will be used to display this entry
 +
  Icon=jmemorize
 +
 +
# Describes whether this application needs to be run in a terminal or not
 +
  Terminal=false
 +
 +
# Describes the categories in which this entry should be shown
 +
Categories=Education;Languages;Java;
  
 
=== 关键字定义 ===
 
=== 关键字定义 ===
  
All Desktop recognized desktop entries can be found [http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s05.html on the freedesktop.org site].
+
全部有效的桌面配置项可参阅[https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys freedesktop.org网站]
For example, the {{Ic|Type}} key defines three types of desktop entries: Application (type 1), Link (type 2) and Directory (type 3).
+
举例:{{Ic|Type}}关键字(类型)定义了三类桌面项:应用程序(Application (type 1)),链接(Link (type 2))和目录(Directory (type 3))。
  
* {{Ic|Version}} key does not stand for the version of the application, but for the version of the desktop entry specification to which this file complies.
+
* {{Ic|Version}} (版本)关键字不是指应用程序的版本,而是本文件所遵循的'''桌面配置项规范'''的版本。
  
* {{Ic|Name}}, {{Ic|GenericName}} and {{Ic|Comment}} often contain redundant values in the form of combinations of them, like:
+
* {{Ic|Name}}(名称)、{{Ic|GenericName}}(通称)和{{Ic|Comment}} 注释often contain redundant values in the form of combinations of them, like:
  
 
  Name=Pidgin Internet Messenger
 
  Name=Pidgin Internet Messenger
Line 57: Line 83:
 
* {{Ic|Comment}} is intended to contain any usefull additional information.
 
* {{Ic|Comment}} is intended to contain any usefull additional information.
  
==== 过时的内容 ====
+
== 图标 ==
 
 
There are quite some keys that have become deprecated over time as the standard has matured. The best/simplest way is to use the tool {{Ic|desktop-file-validate}} which is part of the package {{Pkg|desktop-file-utils}}. To validate, run
 
$ desktop-file-validate <your desktop file>
 
This will give you very verbose and useful warnings and error messages.
 
  
== 图标 ==
+
参考 [https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html 图标主题标准].
  
 
=== 通用图像格式 ===
 
=== 通用图像格式 ===
  
Here is a short overview of image formats commonly used for icons.
+
用于图标的图像文件格式简述如下:
  
 
{| class="wikitable" align="center"
 
{| class="wikitable" align="center"
|+ Support for image formats for icons as specified by the [http://standards.freedesktop.org/icon-theme-spec/latest/ar01s02.html freedesktop.org standard].
+
|+ Support for image formats for icons as specified by the freedesktop.org standard.
 
! Extension
 
! Extension
 
! Full Name and/or Description
 
! Full Name and/or Description
Line 80: Line 102:
 
| Portable Network Graphics
 
| Portable Network Graphics
 
| [[wikipedia:Raster graphics|Raster]]
 
| [[wikipedia:Raster graphics|Raster]]
| bgcolor="red" | no
+
| {{No}}
| bgcolor="#00cc00"| yes
+
| {{Yes}}
 
|-
 
|-
 
!align="left" | .[[wikipedia:Scalable Vector Graphics|svg(z)]]
 
!align="left" | .[[wikipedia:Scalable Vector Graphics|svg(z)]]
 
| Scalable Vector Graphics
 
| Scalable Vector Graphics
 
| [[wikipedia:Vector graphics|Vector]]
 
| [[wikipedia:Vector graphics|Vector]]
| bgcolor="red" | no
+
| {{No}}
| bgcolor="#66cc00"| yes (optional)
+
| {{G|Yes (optional)}}
 
|-
 
|-
 
!align="left" | .[[wikipedia:X PixMap|xpm]]
 
!align="left" | .[[wikipedia:X PixMap|xpm]]
 
| X PixMap
 
| X PixMap
 
| [[wikipedia:Raster graphics|Raster]]
 
| [[wikipedia:Raster graphics|Raster]]
| bgcolor="red" | no
+
| {{No}}
| bgcolor="yellow"| yes (deprecated)
+
| {{Y|Yes (不推荐)}}
 
|-
 
|-
 
!align="left" | .[[wikipedia:Graphics Interchange Format|gif]]
 
!align="left" | .[[wikipedia:Graphics Interchange Format|gif]]
 
| Graphics Interchange Format
 
| Graphics Interchange Format
 
| [[wikipedia:Raster graphics|Raster]]
 
| [[wikipedia:Raster graphics|Raster]]
| bgcolor="red" | no
+
| {{No}}
| bgcolor="red"| no
+
| {{No}}
 
|-
 
|-
 
!align="left" | .[[wikipedia:ICO (icon image file format)|ico]]
 
!align="left" | .[[wikipedia:ICO (icon image file format)|ico]]
 
| MS Windows Icon Format
 
| MS Windows Icon Format
 
| [[wikipedia:Raster graphics|Raster]]
 
| [[wikipedia:Raster graphics|Raster]]
| bgcolor="#00cc00" | yes
+
| {{Yes}}
| bgcolor="red"| no
+
| {{No}}
 
|-
 
|-
 
!align="left" | .[[wikipedia:Apple Icon Image|icns]]
 
!align="left" | .[[wikipedia:Apple Icon Image|icns]]
 
| Apple Icon Image
 
| Apple Icon Image
 
| [[wikipedia:Raster graphics|Raster]]
 
| [[wikipedia:Raster graphics|Raster]]
| bgcolor="#00cc00"| yes
+
| {{Yes}}
| bgcolor="red"| no
+
| {{No}}
 
|-
 
|-
 
|}
 
|}
Line 117: Line 139:
 
=== 图标格式转换 ===
 
=== 图标格式转换 ===
  
If you stumble across an icon which is in a format that is not supported by the freedesktop.org standard (like ''gif'' or ''ico''), you can '''convert''' (which is part of the '''imagemagick''' package) it to a supported/recommended format, e.g.:
+
If you stumble across an icon which is in a format that is not supported by the freedesktop.org standard (like {{ic|gif}} or {{ic|ico}}), you can use the ''convert'' tool (which is part of the {{Pkg|imagemagick}} package) to convert it to a supported/recommended format, e.g.:
 +
 
 
  $ convert <icon name>.gif <icon name>.png
 
  $ convert <icon name>.gif <icon name>.png
If you convert from a container format like ''ico'', you will get all images that were encapsulated in the ''ico'' file in the form ''<icon name>-<number>.png''.
+
 
If you want to know the size of the image, or the number of images in a container file like ''ico'' you can use '''identify''' (also part of the '''imagemagick''' package)
+
If you convert from a container format like {{ic|ico}}, you will get all images that were encapsulated in the {{ic|ico}} file in the form {{ic|<icon name>-<number>.png}}. If you want to know the size of the image, or the number of images in a container file like {{ic|ico}} you can use the ''identify'' tool (also part of the {{Pkg|imagemagick}} package):
$ identify /usr/share/vlc/vlc48x48.ico
+
 
/usr/share/vlc/vlc48x48.ico[0] ICO 32x32 32x32+0+0 8-bit DirectClass 84.3kb
+
{{hc|$ identify /usr/share/vlc/vlc48x48.ico|
/usr/share/vlc/vlc48x48.ico[1] ICO 16x16 16x16+0+0 8-bit DirectClass 84.3kb
+
/usr/share/vlc/vlc48x48.ico[0] ICO 32x32 32x32+0+0 8-bit DirectClass 84.3kb
/usr/share/vlc/vlc48x48.ico[2] ICO 128x128 128x128+0+0 8-bit DirectClass 84.3kb
+
/usr/share/vlc/vlc48x48.ico[1] ICO 16x16 16x16+0+0 8-bit DirectClass 84.3kb
/usr/share/vlc/vlc48x48.ico[3] ICO 48x48 48x48+0+0 8-bit DirectClass 84.3kb
+
/usr/share/vlc/vlc48x48.ico[2] ICO 128x128 128x128+0+0 8-bit DirectClass 84.3kb
/usr/share/vlc/vlc48x48.ico[4] ICO 32x32 32x32+0+0 8-bit DirectClass 84.3kb
+
/usr/share/vlc/vlc48x48.ico[3] ICO 48x48 48x48+0+0 8-bit DirectClass 84.3kb
/usr/share/vlc/vlc48x48.ico[5] ICO 16x16 16x16+0+0 8-bit DirectClass 84.3kb
+
/usr/share/vlc/vlc48x48.ico[4] ICO 32x32 32x32+0+0 8-bit DirectClass 84.3kb
As you can see, the example ''ico'' file, although its name might suggest a single image of size 48x48, contains no less than 6 different sizes, of which one is even greater than 48x48, namely 128x128. And to give a bit of motivation on this subject, at the point of writing this section (2008-10-27), the 128x128 size was missing in the ''vlc'' package (0.9.4-2). So the next step would be to look at the vlc PKGBUILD and check whether this icon format was not in the source package to begin with (in that case we would inform the vlc developers), or whether this icon was somehow omitted from the Arch-specific package (in that case we can file a bug report at [https://bugs.archlinux.org/ the Arch Linux bug tracker]).
+
/usr/share/vlc/vlc48x48.ico[5] ICO 16x16 16x16+0+0 8-bit DirectClass 84.3kb
(''Update:'' this bug has now been [https://bugs.archlinux.org/task/11923 fixed], so as you can see, your work will not be in vain.)
+
}}
 +
 
 +
As you can see, the example ''ico'' file, although its name might suggest a single image of size 48x48, contains no less than 6 different sizes, of which one is even greater than 48x48, namely 128x128.
 +
 
 +
Alternatively, you can use ''icotool'' (from {{Pkg|icoutils}}) to extract png images from ico container:
 +
$ icotool -x <icon name>.ico
 +
 
 +
For extracting images from .icns container, you can use ''icns2png'' (provided by {{Pkg|libicns}}):
 +
$ icns2png -x <icon name>.icns
  
 
=== Obtaining icons ===
 
=== Obtaining icons ===
  
Although packages that already ship with a .desktop-file most certainly contain an icon or a set of icons, there is sometimes the case when a developer has not created a .desktop-file, but may ship icons, nonetheless. So a good start is to look for icons in the source package.
+
Although packages that already ship with a ''.desktop'' file most certainly contain an icon or a set of icons, there is sometimes the case when a developer has not created a ''.desktop'' file, but may ship icons, nonetheless. So a good start is to look for icons in the source package.
 
You can i.e. first filter for the extension with '''find''' and then use '''grep''' to filter further for certain buzzwords like the package name, "icon", "logo", etc, if there are quite a lot of images in the source package.
 
You can i.e. first filter for the extension with '''find''' and then use '''grep''' to filter further for certain buzzwords like the package name, "icon", "logo", etc, if there are quite a lot of images in the source package.
 
  $ find /path/to/source/package -regex ".*\.\(svg\|png\|xpm\|gif\|ico\)$"
 
  $ find /path/to/source/package -regex ".*\.\(svg\|png\|xpm\|gif\|ico\)$"
 
If the developers of an application do not include icons in their source packages, the next step would be to search on their web sites.
 
If the developers of an application do not include icons in their source packages, the next step would be to search on their web sites.
 
Some projects, like i.e. ''tvbrowser'' have an [http://enwiki.tvbrowser.org/index.php/Banners,_Logos_and_other_Promotion_Material artwork/logo page] where additional icons may be found. If a project is multi-platform, there may be the case that even if the linux/unix package does not come with an icon, the Windows package might provide one. If the project uses a [[wikipedia:Version control system|Version control system]] like CVS/SVN/etc. and you have some experience with it, you also might consider browsing it for icons.
 
Some projects, like i.e. ''tvbrowser'' have an [http://enwiki.tvbrowser.org/index.php/Banners,_Logos_and_other_Promotion_Material artwork/logo page] where additional icons may be found. If a project is multi-platform, there may be the case that even if the linux/unix package does not come with an icon, the Windows package might provide one. If the project uses a [[wikipedia:Version control system|Version control system]] like CVS/SVN/etc. and you have some experience with it, you also might consider browsing it for icons.
If everything fails, the project might simple have no icon/logo yet.
+
If everything fails, the project might simply have no icon/logo yet.
  
 
== 工具 ==
 
== 工具 ==
Line 169: Line 200:
 
* Use {{Ic|1=--name='Program Name'}} for choosing a name for the menu entry.
 
* Use {{Ic|1=--name='Program Name'}} for choosing a name for the menu entry.
  
* Use {{Ic|1=--exec='/opt/some_app/elf --with-ponies'}} for setting the exec field.
+
* Use {{Ic|1=--exec='/opt/some_app/elf --some-arg --other-arg'}} for setting the exec field.
  
 
* See the [https://github.com/xyproto/gendesk gendesk project] for more information.
 
* See the [https://github.com/xyproto/gendesk gendesk project] for more information.
  
=== lsdsk ===
+
=== lsdesktopf ===
  
The {{AUR|lsdsk}} bash script searching for content in "Categories" or "Exec", if "Categories" doesn't exist then it uses content of "Name". It's main purpose to get a quick overview in console of the available programs with their command lines and categories in *.desktop. It shows coloured existing base path defined in "DskPath" array.
+
{{AUR|lsdesktopf}} can list available ''.desktop'' files or search their contents.
  
Examples
+
$ lsdesktopf
  # lsdsk
+
  $ lsdesktopf --list
  # lsdsk game
+
  $ lsdesktopf --list gtk zh_TW,zh_CN,en_GB
# lsdsk gtk
+
 
 +
It can also perform MIME-type-related searches. See [[XDG MIME Applications#lsdesktopf]].
  
 
=== fbrokendesktop ===
 
=== fbrokendesktop ===
  
The {{AUR|fbrokendesktop}} bash script using command "which" to detect broken Exec that points to not existing path. Without any parameters it uses preset folders in "DskPath" array. It shows only broken *.desktop with full path and filename that is missing.
+
The {{AUR|fbrokendesktop}} Bash script detects broken {{ic|Exec}} values pointing to non-existent paths. Without any arguments it uses preset directories in the {{ic|DskPath}} array. It shows only broken ''.desktop'' with full path and filename that is missing.
  
 
Examples
 
Examples
  
  # fbrokendesktop
+
  $ fbrokendesktop
  # fbrokendesktop /usr
+
  $ fbrokendesktop /usr
  # fbrokendesktop /usr/share/apps/kdm/sessions/icewm.desktop
+
  $ fbrokendesktop /usr/share/apps/kdm/sessions/icewm.desktop
  
 
== 提示与技巧 ==
 
== 提示与技巧 ==
  
=== 隐藏桌面配置项 ===
+
=== 从终端启动程序 ===
  
{{Tip|Desktop entries can be hidden by creating a symbolic link to {{ic|/dev/null}}. For example:
+
安装软件包 {{Pkg|dex}},并运行 {{ic|dex ''/path/to/application.desktop''}}.
$ ln -s /dev/null ~/.local/share/applications/''foo''.desktop
 
}}
 
  
Firstly, copy the desktop entry file in question to {{ic|~/.local/share/applications}} to avoid your changes being overwritten.
+
=== 隐藏窗口启动 ===
  
Then, to hide the entry in all environments, open the desktop entry file in a text editor and add the following line: {{ic|NoDisplay&#61;true}}.
+
首先,将桌面配置项复制到 {{ic|~/.local/share/applications}},避免修改被后续升级覆盖。
  
To hide the entry in a specific desktop, add the following line to the desktop entry file: {{ic|NotShowIn&#61;''desktop-name''}}
+
要在所有环境隐藏,在桌面配置项中加入 {{ic|NoDisplay&#61;true}}.
 +
要在某个环境中隐藏,在桌面配置项中加入 {{ic|NotShowIn&#61;''desktop-name''}}
  
where ''desktop-name'' can be option such as ''GNOME'', ''Xfce'', ''KDE'' etc. A desktop entry can be hidden in more than desktop at once - simply separate the desktop names with a semi-colon.
+
''desktop-name'' 可以是 ''GNOME'', ''Xfce'', ''KDE'' 等,指定多个桌面时用分号隔开。
  
=== 自动启动 ===
+
=== 修改环境变量 ===
  
If you use an XDG-compliant desktop environment, such as GNOME or KDE, the desktop environment will automatically start [[Desktop entries|*.desktop]] files found in the following directories:
+
在 {{ic|Exec}} 命令中可以使用 {{ic|env}} 修改环境变量:
  
* System-wide: {{ic|$XDG_CONFIG_DIRS/autostart/}} ({{ic|/etc/xdg/autostart/}} by default)
+
{{hc|~/.local/share/applications/abiword.desktop|2=
:* GNOME also starts files found in {{ic|/usr/share/gnome/autostart/}}
+
Exec=env LANG=he_IL.UTF-8 abiword %U
* User-specific: {{ic|$XDG_CONFIG_HOME/autostart/}} ({{ic|~/.config/autostart/}} by default)
+
}}
 
 
Users can override system-wide {{ic|*.desktop}} files by copying them into the user-specific {{ic|~/.config/autostart/}} folder.
 
 
 
For an explanation of the desktop file standard refer to [http://standards.freedesktop.org/desktop-entry-spec/latest/ Desktop Entry Specification]. For a more specific description of directories used, [http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html Desktop Application Autostart Specification].
 
 
 
{{Note|This method is supported only by XDG-compliant desktop environments. Tools like {{AUR|dapper}}, {{pkg|dex}}, or {{AUR|fbautostart}} can be used to offer XDG autostart in unsupported desktop environments as long as some other autostart mechanism exists. Use the existing mechanism to start the xdg compliant autostart tool.}}
 
  
 
== 参阅 ==
 
== 参阅 ==
Line 226: Line 251:
 
* [[DeveloperWiki:Removal of desktop files]]
 
* [[DeveloperWiki:Removal of desktop files]]
 
* [[Wikipedia:.desktop|desktop wikipedia article]]
 
* [[Wikipedia:.desktop|desktop wikipedia article]]
* [http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s05.html recognized desktop entry keys]
 
* [http://freedesktop.org/wiki/Specifications/desktop-entry-spec freedesktop.org desktop entry specification]
 
* [http://freedesktop.org/wiki/Specifications/icon-theme-spec freedesktop.org icon theme specification]
 
* [http://freedesktop.org/wiki/Specifications/menu-spec freedesktop.org menu specification]
 
* [http://freedesktop.org/wiki/Specifications/basedir-spec freedesktop.org basedir specification]
 
 
* [http://freedesktop.org/wiki/Howto_desktop_files information for developers]
 
* [http://freedesktop.org/wiki/Howto_desktop_files information for developers]

Latest revision as of 01:34, 2 June 2019

翻译状态: 本文是英文页面 Desktop_entries翻译,最后翻译时间:2018-07-03,点击这里可以查看翻译后英文页面的改动。

XDG 桌面配置项规范为应用程序和桌面环境的菜单整合提供了一个标准方法。只要桌面环境遵守菜单规范,应用程序图标就可以显示在系统菜单中。

每个桌面项必须包含 TypeName,还可以选择定义自己在程序菜单中的显示方式。

桌面配置项大致分为三类:

应用程序 
文件后缀是 .desktop,定义如何启动程序,支持哪些 MIME。
链接 
文件后缀是 .desktop,定义指向某个 URL 的链接。
目录 
文件后缀是 .directory,定义应用程序菜单中的子菜单。

下列章节概述如何创建它们并使其生效。

.desktop 文件中还定义了数据文件的 MIME 类型关联。Default applications (简体中文) 介绍了它们的配置方法。

XDG MIME Applications 会使用应用程序项的 MimeType 字段。

XDG 自动启动程序项放到特定位置,可以自动启动应用程序。

应用程序配置项

应用程序配置项,即 .desktop 文件是元信息资源和应用程序快捷图标的集合。系统程序的配置项通常位于 /usr/share/applications/usr/local/share/applications目录,单用户安装的程序位于 ~/.local/share/applications 目录,桌面环境会优先使用用户的配置项。

范例文件

下面是一个示例结构和注释,这个示例文件没有使用所有的键值,freedesktop.org 规范包含了完整的键值列表.

[Desktop Entry]

# The type as listed above
Type=Application

# The version of the desktop entry specification to which this file complies
Version=1.0

# The name of the application
Name=jMemorize

# A comment which can/will be used as a tooltip
Comment=Flash card based learning tool

# The path to the folder in which the executable is run
Path=/opt/jmemorise

# The executable of the application, possibly with arguments.
Exec=jmemorize

# The name of the icon that will be used to display this entry
Icon=jmemorize

# Describes whether this application needs to be run in a terminal or not
Terminal=false

# Describes the categories in which this entry should be shown
Categories=Education;Languages;Java;

关键字定义

全部有效的桌面配置项可参阅freedesktop.org网站。 举例:Type关键字(类型)定义了三类桌面项:应用程序(Application (type 1)),链接(Link (type 2))和目录(Directory (type 3))。

  • Version (版本)关键字不是指应用程序的版本,而是本文件所遵循的桌面配置项规范的版本。
  • Name(名称)、GenericName(通称)和Comment 注释often contain redundant values in the form of combinations of them, like:
Name=Pidgin Internet Messenger
GenericName=Internet Messenger

or

Name=NoteCase notes manager
Comment=Notes Manager

This should be avoided, as it will only be confusing to users. The Name key should only contain the name, or maybe an abbreviation/acronym if available.

  • GenericName should state what you would generally call an application that does what this specific application offers (i.e. Firefox is a "Web Browser").
  • Comment is intended to contain any usefull additional information.

图标

参考 图标主题标准.

通用图像格式

用于图标的图像文件格式简述如下:

Support for image formats for icons as specified by the freedesktop.org standard.
Extension Full Name and/or Description Graphics Type Container Format Supported
.png Portable Network Graphics Raster No Yes
.svg(z) Scalable Vector Graphics Vector No Yes (optional)
.xpm X PixMap Raster No Yes (不推荐)
.gif Graphics Interchange Format Raster No No
.ico MS Windows Icon Format Raster Yes No
.icns Apple Icon Image Raster Yes No

图标格式转换

If you stumble across an icon which is in a format that is not supported by the freedesktop.org standard (like gif or ico), you can use the convert tool (which is part of the imagemagick package) to convert it to a supported/recommended format, e.g.:

$ convert <icon name>.gif <icon name>.png

If you convert from a container format like ico, you will get all images that were encapsulated in the ico file in the form <icon name>-<number>.png. If you want to know the size of the image, or the number of images in a container file like ico you can use the identify tool (also part of the imagemagick package):

$ identify /usr/share/vlc/vlc48x48.ico
/usr/share/vlc/vlc48x48.ico[0] ICO 32x32 32x32+0+0 8-bit DirectClass 84.3kb
/usr/share/vlc/vlc48x48.ico[1] ICO 16x16 16x16+0+0 8-bit DirectClass 84.3kb
/usr/share/vlc/vlc48x48.ico[2] ICO 128x128 128x128+0+0 8-bit DirectClass 84.3kb
/usr/share/vlc/vlc48x48.ico[3] ICO 48x48 48x48+0+0 8-bit DirectClass 84.3kb
/usr/share/vlc/vlc48x48.ico[4] ICO 32x32 32x32+0+0 8-bit DirectClass 84.3kb
/usr/share/vlc/vlc48x48.ico[5] ICO 16x16 16x16+0+0 8-bit DirectClass 84.3kb

As you can see, the example ico file, although its name might suggest a single image of size 48x48, contains no less than 6 different sizes, of which one is even greater than 48x48, namely 128x128.

Alternatively, you can use icotool (from icoutils) to extract png images from ico container:

$ icotool -x <icon name>.ico

For extracting images from .icns container, you can use icns2png (provided by libicns):

$ icns2png -x <icon name>.icns

Obtaining icons

Although packages that already ship with a .desktop file most certainly contain an icon or a set of icons, there is sometimes the case when a developer has not created a .desktop file, but may ship icons, nonetheless. So a good start is to look for icons in the source package. You can i.e. first filter for the extension with find and then use grep to filter further for certain buzzwords like the package name, "icon", "logo", etc, if there are quite a lot of images in the source package.

$ find /path/to/source/package -regex ".*\.\(svg\|png\|xpm\|gif\|ico\)$"

If the developers of an application do not include icons in their source packages, the next step would be to search on their web sites. Some projects, like i.e. tvbrowser have an artwork/logo page where additional icons may be found. If a project is multi-platform, there may be the case that even if the linux/unix package does not come with an icon, the Windows package might provide one. If the project uses a Version control system like CVS/SVN/etc. and you have some experience with it, you also might consider browsing it for icons. If everything fails, the project might simply have no icon/logo yet.

工具

gendesk

gendesk started as an Arch Linux-specific tool for generating .desktop files by fetching the needed information directly from PKGBUILD files. Now it is a general tool that takes command-line arguments.

Icons can be automatically downloaded from openiconlibrary, if available. (The source for icons can easily be changed in the future).

用法

  • Add gendesk to makedepends
  • Start the prepare() function with:
gendesk --pkgname "$pkgname" --pkgdesc "$pkgdesc"
  • Alternatively, if an icon is already provided ($pkgname.png, for instance). The -n flag is for not downloading an icon or using the default icon. Example:
gendesk -n --pkgname "$pkgname" --pkgdesc "$pkgdesc"
  • $srcdir/$pkgname.desktop will be created and can be installed in the package() function with:
install -Dm644 "$pkgname.desktop" "$pkgdir/usr/share/applications/$pkgname.desktop"
  • The icon can be installed with:
install -Dm644 "$pkgname.png" "$pkgdir/usr/share/pixmaps/$pkgname.png"
  • Use --name='Program Name' for choosing a name for the menu entry.
  • Use --exec='/opt/some_app/elf --some-arg --other-arg' for setting the exec field.

lsdesktopf

lsdesktopfAUR can list available .desktop files or search their contents.

$ lsdesktopf
$ lsdesktopf --list
$ lsdesktopf --list gtk zh_TW,zh_CN,en_GB

It can also perform MIME-type-related searches. See XDG MIME Applications#lsdesktopf.

fbrokendesktop

The fbrokendesktopAUR Bash script detects broken Exec values pointing to non-existent paths. Without any arguments it uses preset directories in the DskPath array. It shows only broken .desktop with full path and filename that is missing.

Examples

$ fbrokendesktop
$ fbrokendesktop /usr
$ fbrokendesktop /usr/share/apps/kdm/sessions/icewm.desktop

提示与技巧

从终端启动程序

安装软件包 dex,并运行 dex /path/to/application.desktop.

隐藏窗口启动

首先,将桌面配置项复制到 ~/.local/share/applications,避免修改被后续升级覆盖。

要在所有环境隐藏,在桌面配置项中加入 NoDisplay=true. 要在某个环境中隐藏,在桌面配置项中加入 NotShowIn=desktop-name

desktop-name 可以是 GNOME, Xfce, KDE 等,指定多个桌面时用分号隔开。

修改环境变量

Exec 命令中可以使用 env 修改环境变量:

~/.local/share/applications/abiword.desktop
Exec=env LANG=he_IL.UTF-8 abiword %U

参阅