Permanently changing the background

To be finished.

  1. Not relevant to writing a screensaver module, only somewhat related.
  2. create a pixmap as large as the screen;
      /* create a pixmap as large as the root window */
      pix = XCreatePixmap (dpy, root, wa.width, wa.height, wa.depth);
    
  3. clear the pixmap
      /* clear the pixmap (not done by default) */
      XSetForeground(dpy, g, WhitePixelOfScreen(DefaultScreenOfDisplay(dpy)) );
      XFillRectangle (dpy, pix, g, 0, 0, wa.width, wa.height);
    
  4. draw into it (use the same functions for drawing into a window but XClearArea and XClearWindow
      /* draw in the pixmap */
      for(i=0; i<500; i++) {
          /* set a random foreground color */
          XSetForeground(dpy, g, xcolors[random()%NCOLORS].pixel);
    
    
          /* draw a square */
          XFillRectangle (dpy, pix, g, random()%(wa.width-50),
                          random()%(wa.height-40), 50, 40);
      }
    
  5. set it as the background of the root window
      /* set the pixmap as the background of the root window */
      XSetWindowBackgroundPixmap (dpy, root, pix);
    
  6. clear the window (the background is not displayed unless some redrawing has to be made)
      /* clear the root window to make the pixmap visible */
      XClearWindow (dpy, root);
    
Complete code: background.c