Unable to set gtk icon for GtkWindow

here is small piece of code for setting my own image as icon. It seems there is a issue with the following code.

#include <gtk/gtk.h>

GtkWidget *window = NULL;

static void activate( GtkApplication *app, gpointer user_data )
{
	window = gtk_application_window_new( app );
	// icon image file is /usr/share/icons/my_own_icon.png
	gtk_window_set_icon_name( GTK_WINDOW( window ), "my_own_icon" );
	gtk_widget_show( window );
}

int main( int argc, char **argv )
{
	GtkApplication *app = gtk_application_new ("my.own.application", G_APPLICATION_FLAGS_NONE);
	if( g_signal_connect( app, "activate", G_CALLBACK( activate ), NULL ) <= 0 )
	{
		fprintf( stderr, "Unable to connect\n" );
		exit(1);
	}
	int status = g_application_run( G_APPLICATION( app ), argc, argv);
	g_object_unref( app );
	return status;
}

can someone help me what is the issue with the code ?

Named icons are not random icons under a random file system path: they are icons that are part of an icon theme.

If you want to ship your own icon assets and access them via names, then you should replicate the icon theme path in your GResource file, instead of installing icons in random places. You can follow the tutorial on the GNOME developer documentation website.

Incidentally, this function will only do something on X11. For your application’s window you should always define the icon in your desktop file, and make sure that your application id is the same has the base name of your desktop file.

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