Set window icon (Gtk4)

I know that the usual way of giving an application an icon is via its desktop file. However, there are situations where this does not really apply:

  • Development builds
  • On Windows
  • AppImage

How can I get custom window icons to work in these situations? I’ve both used window.set_icon_name and gtk::Window::set_default_icon_name to the AppID, but it does not work. I’m pretty sure the icon itself works though, because it is shown fine in the About dialog and the logs with GTK_DEBUG set confirm this.

(As as side question: is it possible for an application to have multiple windows with different icons?)

As the documentation for gtk::Window::set_icon_name mentions:

On some platforms, the window icon is not used at all.

Looking at today’s GTK checkout, “some platforms” currently means “not X11”. That is, the property is ignored on wayland, windows and mac OS.

There are a few Gtk applications that are commonly distributed across all platforms (Gimp, Xournal++, Xournal) and they window icons working just fine. So there somehow must be another way? (I think those are all still Gtk 3 so at least there must have been some way in the past)

There is no wayland protocol for window icons, so at least that backend won’t work in GTK3 either.

Okay, so a custom icon for development and non-packaged builds on Wayland is off the table. This is unfortunate, but not really Gtk’s fault.

Which leaves open the Windows issue. There must be some mechanism already implemented because it worked at least in Gtk 3 and even my Gtk 4 application has an icon (the Gtk logo). One thing to note is that set_icon_name was previously set_icon in Gtk 3, maybe this is a relevant change somehow.

Application icons on Windows are typically included in the .res file. GTK includes the GTK icon logo there, which is why you’re seeing it.

You are correct, I tried setting an icon for the .exe and it got also used for the Window. Thanks.

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