static int getWindowColor( Display *display, XColor *color, int x, int y )
{
Window target_window;
XImage *ximage;
int rev;
XGetInputFocus( display, &target_window, &rev );
if (target_window == (Window) NULL) {
printf( "target window is null\n" );
return(0);
}
ximage = XGetImage( display, target_window, x, y, 1, 1, AllPlanes, ZPixmap);
if ( ximage == (XImage *) NULL ) {
printf( "ximage is null\n" );
return(0);
}
color->pixel = XGetPixel( ximage, 0, 0 );
XDestroyImage( ximage );
return(1);
}
The point behind that function is (more or less) to get information about a pixel at a given x,y coordinates relative to the window containing the current focus.
This is not what I want.
I want to select the window on top, not the window that has focus. Is there a way to do this? I don't want to give that window focus first.

what if you give it the root window ?
Then it pulls up the data for the pixel in the root window. IE: the background.
What I think needs to happen is query the root_window, get a list of child windows, maybe check the ZAxis? Figure out what window is on top from there.
This sounds great in my head, but I don't know if it's technically correct.
I don't know an easy way to do this, but you might be able to determine the top level window by walking the window tree using XQueryTree(), which you can then pass to XGetImage.