0

I am completely new to writing programs for Ubuntu and using the available api. But I wish to write a desktop background changer of my own in C. Are there any api available which would help me write my code. I want the direction to take the first step. Any help in this regard will be greatly appreciated :)

Thank You for your read !!

3
  • the easiest way i can think of is to make a window containing the background you want with no border and set it to always on bottom. not the best solution, but it works quickly and you can use gtk/pygtk to get it done. Feb 17, 2012 at 6:47
  • exact duplicate: stackoverflow.com/questions/1220826/… Feb 17, 2012 at 7:00
  • adding the comment to check on activity. Have you solved the issue another way? or is it an abandoned question? Mar 30, 2012 at 20:11

1 Answer 1

3

Here are the contents of the accepted answer for the same question on SO:

You should be able to deal with the root window (which the wallpaper is, in fact) by studying the source of xsetroot.c, the most interesting part of which I copypaste here:

static void
SetBackgroundToBitmap(Pixmap bitmap, unsigned int width, unsigned int height)
{
    Pixmap pix;
    GC gc;
    XGCValues gc_init;

    gc_init.foreground = NameToPixel(fore_color, BlackPixel(dpy, screen));
    gc_init.background = NameToPixel(back_color, WhitePixel(dpy, screen));
    if (reverse) {
        unsigned long temp=gc_init.foreground;
        gc_init.foreground=gc_init.background;
        gc_init.background=temp;
    }
    gc = XCreateGC(dpy, root, GCForeground|GCBackground, &gc_init);
    pix = XCreatePixmap(dpy, root, width, height,
                        (unsigned int)DefaultDepth(dpy, screen));
    XCopyPlane(dpy, bitmap, pix, gc, 0, 0, width, height, 0, 0, (unsigned long)1);
    XSetWindowBackgroundPixmap(dpy, root, pix);
    XFreeGC(dpy, gc);
    XFreePixmap(dpy, bitmap);
    if (save_colors)
        save_pixmap = pix;
    else
        XFreePixmap(dpy, pix);
    XClearWindow(dpy, root);
    unsave_past = 1;
}

Not the answer you're looking for? Browse other questions tagged .