Re: Adding an icon to a program



  I'd like to add a custom icon to a program I am writing, so that when
my program is minimized,
that icon will be shown.
How should I do that?

This is what I use:

void GUISetWMIcon(GdkWindow *w, u_int8_t **icon)
{
        GdkPixmap *pixmap;
        GdkBitmap *mask;
        GtkStyle *style;

        if(w == NULL)
            return;

        style = gtk_widget_get_default_style();
        if(style == NULL)
            return;

        pixmap = gdk_pixmap_create_from_xpm_d(
            w, &mask, &style->bg[GTK_STATE_NORMAL], (gchar **)icon
        );

        gdk_window_set_icon(w, NULL, pixmap, mask);
/*      gdk_window_set_icon_name(w, "WMHints Test Icon"); */


        /* Do not unref pixmap and mask. */

        return;
}

A few notes:

The given input icon, needs to be a pointer to XPM format data
either #included or loaded from file at run time.

I didn't set the icon name but it should be settable using
gdk_window_set_icon_name().

The given GdkWindow should be one from your GtkWindow *window's
window->window.

Note that the pixmap is not unref'ed, it will be unrefed when you exit but
if you plan to update the pixmaps for the same window you need to keep a
pointer to it and unref the old one right after you set the new one.

--
Sincerely,                  ,"-_                         \|/
-Capt. Taura M.             ,   O=__                    --X--
..__                         ,_JNMNNEO=_                 /|\
OMNOUMmnne.                  {OMMNNNEEEEOO=_
UOOOBIOOOEOMMn.               'LONMMMMNNEEEOOO=.__..,,..
UUOOEUUOOOOOOOObe              '"=OMMMMWNEEEOOOOO,"=OEEEOO=,._
OOUUUIEEIOONNOIUbe.                "7OMMMMNNNNNWWEEEEOOOOOO"   "'.
EEBNNMMMNWNWWEEIMMNe.             __  7EMMMNNNNNWWWEEEEEEEOO.     " .
NNMMMMWWWMMMWEINMMMNn            "=BBEEEEMMMMMMMMNNNWWWEEOOOOO=._     .
                  http://furry.ao.net/~learfox/





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