For the record and any souls that come looking for answers after me.
I managed to solve the issue.
The answer is:
if (g_file_test("assets", G_FILE_TEST_IS_DIR)) {
gtk_window_set_icon_from_file(window, "assets/img/icon.png", NULL); // For debug mode
} else {
gtk_window_set_icon_from_file(window, (getExecutablePath() + "/data/flutter_assets/assets/img/icon.png").c_str(), NULL); // For launcher mode
}
Sourced from: https://github.com/flutter/flutter/issues/53229#issuecomment-1703233957
Note that the solution from the github comment does not work because the relative path for the image is wrong, due to the way shells work.
So I solved that by crafting an absolute path. Which is the following function (source attributed).
static std::string getExecutablePath() {
// code taken from https://cplusplus.com/forum/unices/14780/
std::string fullFileName = "";
std::string path = "";
pid_t pid = getpid();
char buf[20] = {0};
sprintf(buf,"%d",pid);
std::string _link = "/proc/";
_link.append( buf );
_link.append( "/exe");
char proc[512];
int ch = readlink(_link.c_str(),proc,512);
if (ch != -1) {
proc[ch] = 0;
path = proc;
std::string::size_type t = path.find_last_of("/");
path = path.substr(0,t);
}
fullFileName = path + std::string("/");
return fullFileName;
}