Or any other way.I want to make an application to make my desktop pretty.

  • What do you mean with "c/c++" code? Changing background is nothing more than use a command (called gsettings) to point to an image.
    – Rinzwind
    Oct 12, 2014 at 11:40
  • 2
    Use the GSettings API: developer.gnome.org/gio/stable/GSettings.html
    – muru
    Oct 12, 2014 at 12:29
  • Another option, which I think is what the OP is looking for, is to get the root window and draw that surface. The question is addressed on SO somewhere. I remember reading it, but my 5 second search didn't turn it up. Uptick to @muru though for changing the setting. Doing it to the root window lets it work even on desktops that don't draw wallpaper like i3wm. Oct 12, 2014 at 12:32
  • And my google-fu is stronger than my stackexchange-search-fu stackoverflow.com/questions/1220826/… Oct 12, 2014 at 12:39

1 Answer 1


Blatant copy paste from here

Though the question was gnome-specific, there's also a way to deal with the wallpaper that is not depepndant on the higher layer toolkits. 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 = 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;
        XFreePixmap(dpy, pix);
    XClearWindow(dpy, root);
    unsave_past = 1;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.