
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

main()
{
    Display *display;
    Status status;
    XVisualInfo vinfo;
    Window rootWindow;
    int screenNum;
    Colormap colormap;
    XColor color;

    display = XOpenDisplay( NULL );
    if ( display == NULL )
    {
       fprintf( stderr, "Error opening display.\n" );
       exit( 1 );
    }

    screenNum = DefaultScreen(display);
    rootWindow = DefaultRootWindow(display);

    status = XMatchVisualInfo( display, screenNum, 5, PseudoColor, &vinfo );
    if ( status == 0 )
    {
       fprintf( stderr, "Overlay visual not found.\n" );
       exit( 1 );
    }

    colormap = XCreateColormap( display, rootWindow, vinfo.visual, AllocNone );

    color.red   = 0;
    color.green = 0;
    color.blue  = 0;
    color.flags = DoRed | DoGreen | DoBlue;
    XAllocColor( display, colormap, &color );
    printf( "r/g/b: %hd/%hd/%hd, pixel: %ld.\n",
       color.red, color.green, color.blue, color.pixel );
}

