Almost this very same question has been asked here: Change Xlib window background color with C++ But in that anwser it only tells how to set the bg color in the initial setup. I would want to change the bg color after that. (The same way the comment in that anwser puts it).
Here is my code:
#include <X11/Xlib.h>
#include <unistd.h>
#define NIL (0)
void graphic(int color1, int color2){
Display *dpy = XOpenDisplay(NIL);
Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 500, 500, 0, color1, color2);
XMapWindow(dpy, w);
XClearWindow(dpy, w);
GC gc = XCreateGC(dpy, w, 0, NIL);
XFlush(dpy);
}
int main(){
graphic(100,100);
sleep(10);
}
You probably want XChangeWindowAttributes. This is described in chapter 3. Window Functions in the XLib reference.
And if you intend to do X11 programming on this level, you should plan to have that manual as bedtime reading for the next few months. :)