.desktop files: how to specify the icon path [duplicate]

Solution 1:

Yeah the lookup is pretty complicated. Here are the freedesktop icon specifications on directory layouts:

Icons and themes are looked for in a set of directories. By default, apps should look in $HOME/.icons (for backwards compatibility), in $XDG_DATA_DIRS/icons and in /usr/share/pixmaps (in that order). Applications may further add their own icon directories to this list, and users may extend or change the list (in application/desktop specific ways).In each of these directories themes are stored as subdirectories. A theme can be spread across several base directories by having subdirectories of the same name. This way users can extend and override system themes.

In order to have a place for third party applications to install their icons there should always exist a theme called "hicolor" 1. The data for the hicolor theme is available for download at: http://www.freedesktop.org/software/icon-theme/. Implementations are required to look in the "hicolor" theme if an icon was not found in the current theme.

Each theme is stored as subdirectories of the base directories. The internal name of the theme is the name of the subdirectory, although the user-visible name as specified by the theme may be different. Hence, theme names are case sensitive, and are limited to ASCII characters. Theme names may also not contain comma or space.

In at least one of the theme directories there must be a file called index.theme that describes the theme. The first index.theme found while searching the base directories in order is used. This file describes the general attributes of the theme.

In the theme directory are also a set of subdirectories containing image files. Each directory contains icons designed for a certain nominal icon size, as described by the index.theme file. The subdirectories are allowed to be several levels deep, e.g. the subdirectory "48x48/apps" in the theme "hicolor" would end up at $basedir/hicolor/48x48/apps.

The image files must be one of the types: PNG, XPM, or SVG, and the extension must be ".png", ".xpm", or ".svg" (lower case). The support for SVG files is optional. Implementations that do not support SVGs should just ignore any ".svg" files. In addition to this there may be an additional file with extra icon-data for each file. It should have the same basename as the image file, with the extension ".icon". e.g. if the icon file is called "mime_source_c.png" the corresponding file would be named "mime_source_c.icon".

The full specifications are much more exhausti{ve,ng} than this but the crux of it is: there are set directories you can just stuff icons into and the desktop will find them. Which of those best applies to you depends on your problem and your patience :)

Solution 2:

If you put icons in /usr/share/icons/ (for system wide) or in your home ~/.icons, then you can use only the icon file name without the extension in the .desktop file. E.g.

Icon=vlc

If not, then you must to use the absolute path for the icon in the .desktop file. E.g.

Icon=/usr/local/share/my-icon.png

Solution 3:

I have experience with just emblems, not icons, but that should work:

mkdir -p $HOME/.icons/hicolor/48x48/

put the icon in that directory, let's suppose it is myicon.png

cp  myicons.png $HOME/.icons/hicolor/48x48/

Add the description file:

gedit $HOME/.icons/hicolor/48x48/myicon.icon

with content:

[Icon Data]

DisplayName=myicon

and now your Icon=myicon line should work. It works with emblems if you put them in an "emblems" subdirectory:

personalized emblem

Thanks to @Oli now I know why it works :-)