

You've got to set border_pixel in your window attributes. The default
is CopyFromParent which gives the BadMatch. Do this:

   ...
   unsigned long valuemask;
   ...
   /*
    * if border_width is non-zero you'd better alloc a colour from cmap
    * rather than use any old pixel value. Also, use valuemask, it makes
    * the code more obvious.
    */
   attr.colormap = cmap;
   attr.border_pixel = 0;
   valuemask = CWColormap | CWBorderPixel;
   win = XCreateWindow(
           dpy,
           DefaultRootWindow(dpy),
           10,10,
           width,height,
           0,		         /* border width. see comment below */
           8,                    /* depth */
           InputOutput,          /* class */
           vinfo.visual,         /* visual */
           valuemask,
           &attr
         );

A note on border_width: your code looked like this:


border_width set to CopyFromParent works but doesn't make sense.
border_width should be an unsigned int. You get away with it because
CopyFromParent is #define'ed to be zero in X.h. If it happened to be
defined as -1 you'd get a very interesting looking window!