NUPUL wrote:
> I wish to write a program that set's the desktop background to the
> desired JPEG/PNG etc file....Is there a way to do this in X?


Sure. You want to set the root window's background image. You can draw
into a Pixmap, and then use XSetWindowBackgroundPixmap() to make that
image be the new background image. After that, X automatically refreshes
any subsequently exposed parts of the root window.

(How do you load the JPEG file's image into a Pixmap? I can't help you
there. I've mostly generated images and saved them; I've never loaded
them from files except for XBM or XPM formats.)

One catch is that when an program exits, all of its resources are normally
freed. Usually that's a good thing, but for a background-setting program
this means the background Pixmap is freed. On pseudocolor displays, all
of the color cells allocated for the image will also be freed. There's
a way around this though: Use XSetCloseDownMode(display, RetainPermanent)
to prevent the Pixmap and its colors from being automatically freed, and
then set the root window's _XSETROOT_ID atom to the Pixmap's ID so that
the next program to change the root image can find the old image and free
it explicitly.

Years ago, I wrote a couple of little programs to generate background
images. You can get the source code from...

ftp://ftp.cs.pdx.edu/pub/elvis/not-elvis/tilemkrs.tgz

The code for setting the X root image is in the file "writex11.c".