Icon / mime association..

Magnus Bergman magnus.bergman at observer.net
Tue Oct 17 16:59:05 EEST 2006


On Mon, 16 Oct 2006 19:46:41 +0300
Kustaa Nyholm <feedback2 at sparetimelabs.com> wrote:

> Now Magnus Bergman wrote on this subject:
> 
>  >Yes. Modify the application to look up the same iconname in the way
>  >specified in the icon theme (some toolkits lite GTK+ can do this by
>  >itself). In that way the same icon will be found, even if some theme
>  >provides an alternative icon for your application, that will be used
>  >both for the launcher and the running application.
> 
> But I still can't figure this out, could some please spell out an
> example for me?

Using GTK+ it can look something like this:

#include <gtk/gtk.h>

int main(int argc,char** argv){
  GtkWidget* window;
  GtkIconTheme* theme;
  GdkPixbuf* icon;

  gtk_init(&argc,&argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  g_signal_connect(window,"destroy",gtk_main_quit,NULL);

  theme = gtk_icon_theme_get_default();
  icon = gtk_icon_theme_load_icon(theme,"my_application",48,0,NULL);
  if(icon){
    gtk_window_set_icon(GTK_WINDOW(window),icon);
    g_object_unref(icon);
  }

  gtk_widget_show(window);
  gtk_main();
}

Note that gtk_icon_theme_get_default() means "get the theme from the
default display", and not get the default theme (hicolor). If you use
some other toolkit there probably some function similar to
gtk_theme_load_icon(). If not, there is some pseudo code [1] in the icon
theme spec you can use.

[1]
http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html#icon_lookup



More information about the xdg mailing list