How do I set an icon for my application?

I want my application to be bundled with it’s own resources. I mean I want all my resources to be compiled into application binary. And I managed to do it, however, I have problems with setting an icon for my main window. Icon is compiled with other gresources and I can get and display it with GtkImage (through GtkIconTheme object). However my GNOME on Wayland doesn’t display icon on my Window. Moreover, it doesn’t display any icon, even those already present in my system. So, my questions are:

  1. Is it possible to bundle ALL resources with the binary using GTK? (I’ve positive examples from other frameworks: Minecraft, Telegram, some Java apps…) And how to?
  2. How does Gnome decide which icon to display for the WINDOW?

Not possible, sorry. At minimum, you’ll need at least your desktop file and icon to be separate. Trying to get everything into one binary is just now how applications work on Linux.

There is an Icon= line in your desktop file, which must also be installed separately.

Like I told you on IRC, GNOME Shell uses the desktop file: Projects/GnomeShell/ApplicationBased - GNOME Wiki!

The Wayland protocol has no equivalent of the X11 properties for window icons, either, so there’s no fallback mechanism possible.

An application on Linux is composed of multiple files, all installed in the appropriate system location. If you don’t want/can’t do that, then the recommendation is to use a sandboxed mechanism, like Flatpak, which is designed explicitly to isolate each application and its dependencies.

Well, how do some Java apps, consisting of the only .jar file, draw their icons then?

Likely, because they are X11-only applications, and the Shell may still fall back to the NET_WM_ICON X11 property, or set a Pixmap with the icon data inside the WM_HINTS property.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.