30

I had a look at the .desktop files on my 12.04 Ubuntu system, and many of them do not have a full path specification for their icon file. It is rather something like:

Icon=anjuta

or

Icon=vlc

or

Icon=application-x-clementine

Is there a common path where icons can be stored so that this can work ? If not, how does this work ? If I try to do the same thing with my own icons I have to specify the full path.

e.g.

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

works fine, but

Icon=my-icon.png

will fail.

Any kind of help is welcome!

Radu Rădeanu
  • 169,590
user3430409
  • 401
  • 1
  • 4
  • 3

3 Answers3

21

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 :)

Oli
  • 293,335
10

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
Radu Rădeanu
  • 169,590
  • 2
    How long does it usually take for the OS to detect that you've updated or added an Icon entry to your .desktop file? – FilBot3 Jul 13 '20 at 01:54
  • @FilBot3 if you run gtk-update-icon-cache -f -t <path to icon theme>, it should be detected immediately. See manpage. Some package managers detect new icons and run this command automatically so you don't have to – smac89 Feb 25 '21 at 07:30
7

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 :-)

Rmano
  • 31,947
  • No way i did not know about emblems, super answer. I was actually making a badged/emblemed png than setting it to that. This is great man thanks. Is it just ubuntu that supports emblem? or all linux builds? – Noitidart Aug 28 '14 at 06:06
  • @Noitidart: I think it's basically a File Manager thing. They work at least in nautilus and in thunar (so in Ubuntu, Ubuntu Gnome, and XUbuntu; and in other distros using them). Never checked with the K-side. – Rmano Aug 28 '14 at 06:46