proper xorg background setting in my program
by jr_bob_dobbs from LinuxQuestions.org on (#4S7K0)
So I've written a program and part what what said program does is set a picture to be the background wallpaper in xorg. This works, with one oddity: programs like urxvt do not correctly show my background through their transparency. If I set the background wallpaper using feh, then that background shows through. In fact, if I first set the wallpaper to one picture with feh and *then* set the wallpaper to a second picture using my program, the wallpaper will change to the second picture, but a subsequent run of urxvt will show the first picture within its transparent window!
I've looked at the source for feh and was confused. :o
My theory is that there is more than one way to set the background wallpaper and, while the way I am doing it works, it is not the proper way.
Web searching has not revealed anything, oddly enough.
Here is a snippit of the wallpaper-setting part of my program:
Code:int wall_it(fn)
char *fn; /* file to read and wall */
{
/* file is assumed to be same width and height as screen:
behavior is undefined otherwise */
Imlib_Image img;
Display *dpy;
Pixmap pix;
Window root;
Screen *scn;
int wi_width, wi_height;
/* open up imlib / x-windows stuff */
img = imlib_load_image(fn);
if (!img) {
fprintf(stderr, "wall_it: error loading image\n");
return(DOOPS);
}
imlib_context_set_image(img);
/* get image dimensions */
wi_width = imlib_image_get_width();
wi_height = imlib_image_get_height();
dpy = XOpenDisplay(NULL);
if (!dpy) {
fprintf(stderr, "wall_it: XOpenDisplay error\n");
return(DOOPS);
}
scn = DefaultScreenOfDisplay(dpy);
root = DefaultRootWindow(dpy);
pix = XCreatePixmap(
dpy, root, wi_width, wi_height,
DefaultDepthOfScreen(scn)
);
imlib_context_set_display(dpy);
imlib_context_set_visual(DefaultVisualOfScreen(scn));
imlib_context_set_colormap(DefaultColormapOfScreen(scn));
imlib_context_set_drawable(pix);
/* actually wall that picture */
imlib_render_image_on_drawable(0, 0);
XSetWindowBackgroundPixmap(dpy, root, pix);
XClearWindow(dpy, root);
while (XPending(dpy)) {
XEvent ev;
XNextEvent(dpy, &ev);
}
/* clean up */
XFreePixmap(dpy, pix);
imlib_free_image();
XCloseDisplay(dpy);
/* done */
return(OKDOKEY);
}Again, my program actually works, in that I see the picture become the new background wallpaper.
Thank you.


I've looked at the source for feh and was confused. :o
My theory is that there is more than one way to set the background wallpaper and, while the way I am doing it works, it is not the proper way.
Web searching has not revealed anything, oddly enough.
Here is a snippit of the wallpaper-setting part of my program:
Code:int wall_it(fn)
char *fn; /* file to read and wall */
{
/* file is assumed to be same width and height as screen:
behavior is undefined otherwise */
Imlib_Image img;
Display *dpy;
Pixmap pix;
Window root;
Screen *scn;
int wi_width, wi_height;
/* open up imlib / x-windows stuff */
img = imlib_load_image(fn);
if (!img) {
fprintf(stderr, "wall_it: error loading image\n");
return(DOOPS);
}
imlib_context_set_image(img);
/* get image dimensions */
wi_width = imlib_image_get_width();
wi_height = imlib_image_get_height();
dpy = XOpenDisplay(NULL);
if (!dpy) {
fprintf(stderr, "wall_it: XOpenDisplay error\n");
return(DOOPS);
}
scn = DefaultScreenOfDisplay(dpy);
root = DefaultRootWindow(dpy);
pix = XCreatePixmap(
dpy, root, wi_width, wi_height,
DefaultDepthOfScreen(scn)
);
imlib_context_set_display(dpy);
imlib_context_set_visual(DefaultVisualOfScreen(scn));
imlib_context_set_colormap(DefaultColormapOfScreen(scn));
imlib_context_set_drawable(pix);
/* actually wall that picture */
imlib_render_image_on_drawable(0, 0);
XSetWindowBackgroundPixmap(dpy, root, pix);
XClearWindow(dpy, root);
while (XPending(dpy)) {
XEvent ev;
XNextEvent(dpy, &ev);
}
/* clean up */
XFreePixmap(dpy, pix);
imlib_free_image();
XCloseDisplay(dpy);
/* done */
return(OKDOKEY);
}Again, my program actually works, in that I see the picture become the new background wallpaper.
Thank you.