xlib transparent icons - Xwindows

This is a discussion on xlib transparent icons - Xwindows ; I've been trying to set a window's icon from an array of ARGB quads. So far, I've come up with the following, which creates an image, draws it to a pixmap and then assigns the pixmap to be the window's ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: xlib transparent icons

  1. xlib transparent icons

    I've been trying to set a window's icon from an array of ARGB quads. So
    far, I've come up with the following, which creates an image, draws it
    to a pixmap and then assigns the pixmap to be the window's icon:

    x_image = XCreateImage(g_display, CopyFromParent, 24,
    ZPixmap, 0, bytes, 16, 16, 32, 0);
    icon_pixmap = XCreatePixmap(g_display, sw->wnd, 16, 16, 24);
    XPutImage(g_display, icon_pixmap, g_gc, x_image, 0, 0, 0, 0, 16, 16);

    win_hints = XAllocWMHints();
    win_hints->flags = IconPixmapHint;
    win_hints->icon_pixmap = icon_pixmap;
    XSetWMHints(g_display, sw->wnd, win_hints);

    That works (though it's probably not the most elegant way of doing
    things and it's hard-coded to only work for a 16x16 image), but I've run
    into a block with transparency. I can't figure out how to set pixels to
    be transparent - they're just coming up black. I've tried using
    XAllocNamedColor() and friends to get a blank or transparent colour and
    then manually draw that over the right pixels in x_image with
    XPutPixel(), but didn't have any luck. How would I go about setting
    certain pixels in the pixmap to be transparent?

    Cheers,

    John.

  2. Re: xlib transparent icons

    John Smith wrote:

    > I've been trying to set a window's icon from an array of ARGB quads.
    > ... I can't figure out how to set pixels to
    > be transparent - they're just coming up black. I've tried using
    > XAllocNamedColor() and friends to get a blank or transparent colour and
    > then manually draw that over the right pixels in x_image with
    > XPutPixel(), but didn't have any luck. How would I go about setting
    > certain pixels in the pixmap to be transparent?


    You must also set win_hints->icon_mask to a second Pixmap, one containing
    the alpha mask. (Actually, the mask Pixmap uses a single bit per pixel
    to make each pixel either totally transparent or totally opaque so don't
    expect cool transluscent effects.)

    One way to do this is with the XPM library. The XpmCreatePixmapFromData()
    function creates both of the Pixmaps you need. Use your favorite search
    engine to search for "xpm library manual", but basically the way to call
    it is...

    #include
    #include "myimage.xpm"
    /* ... */
    Pixmap image, shape;
    XWMHints win_hints;
    XpmCreatePixmapFromData(g_display, sw->wnd,
    myimage, &image, &shaperef, NULL);
    win_hints = XAllocWMHints();
    win_hints->flags = IconPixmapHint|IconMaskHint;
    win_hints->icon_pixmap = image;
    win_hints->icon_mask = shape;
    XSetWMHints(g_display, sw->wnd, win_hints);

    .... and then add -lXpm to your link list. The "myimage.xpm" file would
    contain an XPM image. The XPM file format is simply C source code that
    defines an array of strings describing the image. Traditionally the
    name of the array is the same as the file's basename, so the "myimage.xpm"
    file should define an array named "myimage".

    There's a simple program named "pixmap" which can be used to edit XPM files.
    If you use it, be aware that on many systems it doesn't work correctly if
    you have NumLock or CapsLock switched on. There are also many other,
    fancier programs out there, and the NetPBM utilities include some programs
    that read or write XPM files.

    I hope that helps. Have fun.

  3. Re: xlib transparent icons

    Steve Kirkendall wrote:
    > I hope that helps. Have fun.


    Exactly what I was looking for, thanks for your help.

    John.

+ Reply to Thread