Haskell, GTK4 and application icons

On Windows 11, in File Explorer, gtk-picture.exe has Windows’ default icon for an executable file and GTK4’s default icon in the task bar when running:

I wanted to customise these icons. Also, I wanted a similar icon to appear in the application’s window’s header bar, to the left.

*.res file

The icon can be set by linking an appropriate *.res (resource) file. In my case, the file was haskell-logo.res. The file is linked by specifying the GHC option -optl. For example:

*.rc file

A *.res file is created by compiling an appropriate *.rc (resource script) file with the windres application. That application is provided by the MSYS2 package mingw-w64-x86_64-binutils. It acts like the Windows Resource Compiler. For example:

The *.rc file specifies the icon. For example:

IDI_ICON1 is an identifier for the resource. By convention, the initial IDI indicates that the resource is an icon or bitmap. ICON identifies the resource type as an icon. The type is followed by the path to the resource, in this case a *.ico (Windows icon) file.

*.ico file

An *.ico file stores one or more icon images of different sizes. It can be created from a *.svg file with the ImageMagick application. For example:

It is important to specify -background none before the input *.svg file is specified, otherwise the background will be white.

I used the 2009 Thompson-Wheeler logo, resized in InkScape to be 256 px x 256 px:

gtk-picture.exe

The end result was as desired: in File Explorer, gtk-picture.exe had the specified icon and the same icon in the task bar when running:

For an icon in the application’s header bar, the solution was for the ApplicationWindow value to specify a HeaderBar value as its titleBar and for an appropriate Image value to be packed at the start of that header bar, as follows:

A 24 px square image seemed an appropriate size. If the titleWidget of a HeaderBar is not set, it displays the title of the window that it is contained in. The default showTitleButtons of a HeaderBar is True.