In GTK4 the icon system for displaying the apps have changed.
In GTK3/GTK2 we could use simple commands like gtk_window_set_icon() or gtk_window_set_default_icon_from_file() or gtk_window_set_icon_list().
In GTK4 these commands are gone and we have to use the system of theming defined by the Freedesktop Icon Theme Specification (which could be also used in GTK3). I have dug into what it means in practical in this previous question : GTK 4 and applications icons : how to include an application icon in a portable way?
And finally the resulting code is quite simple :
icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
gtk_icon_theme_add_search_path(icon_theme,path_to_my_ressource_directory);
if(gtk_icon_theme_has_icon(icon_theme,"my-icon")!=1)
{
// manage error
}
gtk_window_set_default_icon_name("my-icon"); // default icon for all windows if nothing is set explicitly if I understand well.
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Your app");
gtk_window_set_icon_name(GTK_WINDOW (window),"my-icon"); // set explicitly the icon for the min window
Assuming that the ressource_directory is defined like that :
/ressources$ ls
hicolor icon-theme.cache
cd hicolor/
/ressources/hicolor$ ls
128x128 150x150 192x192 256x256 310x310 48x48 512x512 64x64 72x72 96x96 scalable
/ressources/hicolor$ cd 128x128
/ressources/hicolor/128x128$ ls
apps
/ressources/hicolor/128x128$ cd apps
/ressources/hicolor/128x128/apps$ ls
my-icon.png
And it now works, i have my wonderfull icon when i launch the application.
Buuuuuttttt ... the reality is that the icon is fuzzy, whereas in the GTK2 version of my application, it is not.
The first icon from the bottom is my application in GTK2, the second icon (the fuzzy one) is the same appli in GTK4.
The result is a fuzzy icon. I have made some tests on the icons and it seems that under the hood GTK use only the 48x48 icon in this context in GTK4, which give a fuzzy icon when it is used in other context.
Is it a bug of GTK ? Is it a bad interaction with my desktop environment (KDE here) ? Or is it an error from my side ?
And more importantly : how to correct this dissatisfying result ?