0
votes

i'm using gtk+-2.0 in C. and i have to write a digit upon my tray icon. i do it such way:

 static GdkPixbuf * transform_pixbuf(GdkPixbuf *pixbuf) {
    cairo_t *cr;

    int width = gdk_pixbuf_get_width(pixbuf);
    int height = gdk_pixbuf_get_height(pixbuf);

    GdkPixmap *pixmap = gdk_pixmap_new(NULL, width, height, 24);
    cr = gdk_cairo_create(pixmap);
    gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
    cairo_paint(cr);  

    cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, 15.0);
    cairo_set_source_rgb (cr, 1.0, 0, 0); 
    cairo_move_to (cr, 10, 20);
    cairo_show_text (cr, "8");

    cairo_destroy(cr);

    GdkPixbuf *pixbuf_new = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL,
        0, 0, 0, 0, width, height);

    return pixbuf_new;
  }

where GdkPixbuf *pixbuf is GdkPixbuf i want to set in tray. i can draw a digit, but the icon's background became "dancing" - enter image description here.

i guess the problem is in gdk_pixmap_new's depth argument, because the icon has 32bit format, but 32 isn't valid argument for this function. in such case i have followin warning and no icon in the tray:

Gdk-WARNING **: Using Cairo rendering requires the drawable argument to have a specified colormap. All windows have a colormap, however, pixmaps only have colormap by default if they were created with a non-NULL window argument. Otherwise a colormap must be set on them with gdk_drawable_set_colormap

Gdk-WARNING **: /build/buildd/gtk+2.0-2.24.4/gdk/gdkpixbuf-drawable.c:1249: Source drawable has no colormap; either pass in a colormap, or set the colormap on the drawable with gdk_drawable_set_colormap()

Suggest me, please...

1

1 Answers

0
votes

i've solved my problem with workaround. the problem was in creating pixmap - it was "dirty" from it's "born". the solution is in to not use pixmap, but create cairo context via the functions: http://www.gtkforums.com/viewtopic.php?t=5204