I have started developing a small app in Rust using GTK4 bindings on Linux Mint.
I have created the following resources.gresource.xml in the project directory:
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/myapp">
<file>resources/icon.png</file>
</gresource>
</gresources>
When the project is compiled, the XML is compiled as well into a binary resources.gresource file. This file is in the project root directory as well.
When the file is reviewed it shows that the PNG is indeed part of that binary. The PNG has the size of 64x64 pixels by the way.
gtk4 is imported as gtk. In the application code, the gresource file is loaded and registered as follows:
let gresource = gtk::gio::Resource::load("resources.gresource")
.expect("Failed to load gresources");
gtk::gio::resources_register(&gresource);
When checking the children of each node in the gresource object, the following path exists: /org/myapp/resources/icon.png. As a result, everything seems to work so far.
This icon path is then set to be the window icon later in the code:
// window is of type: gtk::ApplicationWindow
window.set_icon_name(Some("/org/myapp/resources/icon.png"));
Everything compiles well. The problem is that the icon is not displayed as application icon during runtime. I have tried to set it as the icon for a button as well with a similar result: In that case a placeholder icon is shown.
When I use a system icon, e.g. "document-print", instead of "/org/myapp/resources/icon.png", then that application icon is displayed in the task bar.
Aside from trying all sorts of different paths I have researched in many places but nowhere I could find a solution to the problem. I hope somebody here with experience in Rust GTK4 development can tell me what I am missing.