Hello X Windowers,

I'm having trouble with the Xpm function XpmReadFileToImage(). My aim is
to read some image data (a .xpm file) into an XImage structure, then place
the image data into NET_WM_ICON with XChangeProperty.

Here's my code:

static Atom NET_WM_ICON, CARDINAL;
Display * display;
XImage *p;
XImage *mask;
XpmAttributes attributes;
int rtn;

display = XOpenDisplay (0);
if (display == NULL) {
printerr ("display was null");
} else {

/* Set these up for later call to XChangeProperty */
if (!NET_WM_ICON)
NET_WM_ICON = XInternAtom (display, "_NET_WM_ICON", True);
if (!CARDINAL)
CARDINAL = XInternAtom (display, "CARDINAL", True);

/* Need to set this before calling XpmReadFileToImage */
attributes.valuemask = 0;

/* I'm not sure if I need to malloc memory for p and p->data. Doesn't
sees to make any difference */
p=g_malloc0(sizeof(XImage));
p->data=g_malloc0(4096 * sizeof(unsigned char));

rtn = XpmReadFileToImage (display,
"/etc/persistent/hc/gnome-terminal.xpm",
&p,
&mask,
&attributes);

/* Returns 0: */
printerr ("XpmReadFileToImage() returns %d (zero means good)\n", rtn);

/* Returns 1: */
printerr ("XInitImage(p) returns %d (nonzero means good)\n",
XInitImage(p));


/* Shows numerous sensible values for width, height etc */
printerr ("p->(width=%d height=%d depth=%d bpp=%d bm_unit=%d bm_bo=%d
red_mask=0x%lx\n",
p->width,
p->height,
p->depth,
p->bits_per_pixel,
p->bitmap_unit,
p->bitmap_bit_order,
p->red_mask);

/* strlen(p->data) == 0!? */
printerr ("length of data is %d\n", strlen(p->data));

/* Prints: "The actual data, p->data = ''" ?! */
printerr ("The actual data, p->data = '%s'\n", p->data);

/* This call puts nothing in NET_WM_ICON, because strlen(p->data) == 0 */
XChangeProperty (display, (Window)x_window_id,
NET_WM_ICON, CARDINAL,
32,
PropModeReplace,
(unsigned char*)p->data,
strlen(p->data)/4);
}

Does anyone know how I can successfully read my .xpm file into an XImage
so that I can set NET_WM_ICON??

Thanks for any pointers,

Seb James
WML - Innovate Technology
http://www.wmltd.co.uk