Re: How to set application icon



Here's how I make it work (not sure if this is the "right" way):

int register_stock_icon(GtkIconFactory *icon_factory, const char
*name, const char *filename)
{
      GdkPixbuf *pixbuf;
      gchar *pathname;
      GError *error = NULL;

      pathname = g_strdup_printf("%s%s%s", PACKAGE_PIXMAPS_DIR,
G_DIR_SEPARATOR_S, filename);
      pixbuf = gdk_pixbuf_new_from_file(pathname, &error);
      g_free(pathname);

      if (pixbuf == NULL) return -1;

      gtk_icon_theme_add_builtin_icon(name, -1, pixbuf);
      g_object_unref(pixbuf);

      return 0;
}

void add_icons()
{
      GtkIconFactory *icon_factory;

      icon_factory = gtk_icon_factory_new();
      register_stock_icon(icon_factory, "gtkdisplay-main-icon",
"display_icon24.png");
      register_stock_icon(icon_factory, "gtkdisplay-main-icon-large",
"display_icon48.png");

      gtk_icon_factory_add_default(icon_factory);
}

My makefile is set up so that PACKAGE_PIXMAPS_DIR points to
/usr/local/share/pixmaps/<appname>

I call add_icons before I create my window.

Finally, in glade-2, I set the named icon to "gtkdisplay-main-icon",
which is equivalent to calling gtk_window_set_icon_name.

The advantage of this, over using gtk_window_set_icon_from_file is
that you can add multiple images at different sizes into the icon
factory under the same name, and GTK will pick the appropriate one to
display.

-Jim

(sorry, I sent this to tomas first, instead of the list)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]