4

What size icon should I provide (and reference) in a .desktop file for an application? I'm using Sublime Text 2, which provides .PNGs up to 256 pixels square, but by default references 48x48 in it's .desktop file, this is fine in the sidebar/dock/thing but looks badly scaled on the alt-tab app switching view, which is larger.

Icon=/opt/Sublime Text 2/Icon/48x48/sublime_text.png

Is there any problem if I simply reference the bigger file?

I also notice that some existing .desktop files don't seem to reference a file, but just a name - how does that work? (for example chromium-browser.desktop just has the value with no path or file extension:

Icon=chromium-browser
kiri
  • 28,246
  • 16
  • 81
  • 118
Andrew M
  • 2,398

1 Answers1

10

Referencing icons in .desktop files

You can simply put the full path in the file or the path to an icon in the default icon directories (explained below)


Adding multiple resolutions to an icon

You can let your own icons have multiple resolutions by placing them in one of the following folders:

Replace <RESOLUTION> with the resolution of the icon (in 48x48 format), replace <NAME> with a unique name you would like to reference it with, replace .png with the extension for the icon (if it has a different one).

  • For the current user only:

    ~/.local/share/icons/hicolor/<RESOLUTION>/apps/<NAME>.png
    
  • For all users on the system:

    /usr/share/icons/hicolor/<RESOLUTION>/apps/<NAME>.png
    

To reference this icon in a .desktop file, you will use only the <NAME> of it without the extension.

Notes:

  • The icon must be of PNG, XPM or SVG format, and have the correct file extension
    (.png, .xpm or .svg).

  • If the icon is a .svg (Scalable vector graphics) file, you can use scalable as the <RESOLUTION> in either path above.

References:


Finding icons without a full path

(Use this to locate the icon for chromium-browser, for example)

Inspired by Stefano Palazzo♦'s answer here:

#!/usr/bin/env python3

from gi.repository import Gtk

icon_name = input("Icon name (case sensitive): ")
if icon_name:
    theme = Gtk.IconTheme.get_default()
    found_icons = set()
    for res in range(0, 512, 2):
        icon = theme.lookup_icon(icon_name, res, 0)
        if icon:
            found_icons.add(icon.get_filename())

    print("\n".join(found_icons))

Save the above into a file and run it with python3 /path/to/file.

References:

kiri
  • 28,246
  • 16
  • 81
  • 118
  • nice info, but you didn't actually mention what the recommended icon size would be if you reference it by path ^^ – xeruf Jul 01 '19 at 15:01