#include #include #include int main( int argc, char *argv[] ) { if( argc != 5 ) { fprintf( stderr, "Usage: %s \n", argv[0] ); exit(EXIT_FAILURE); } int x = atoi( argv[1] ); unsigned width = atoi( argv[2] ); unsigned red_height = atoi( argv[3] ); unsigned green_height = atoi( argv[4] ); Display *display = XOpenDisplay( NULL ); int screen = DefaultScreen( display ); Window window = XCreateSimpleWindow( display, RootWindow( display, screen ), x, 0, width, red_height + green_height, 0, WhitePixel( display, screen ), WhitePixel( display, screen ) ); XSelectInput( display, window, ExposureMask ); XMapWindow( display, window ); GC gc; gc = XCreateGC( display, window, 0, NULL ); unsigned long red; unsigned long green; { XWindowAttributes attrs; XColor col; XGetWindowAttributes( display, window, &attrs ); XAllocNamedColor( display, attrs.colormap, "#f00", &col, &col ); red = col.pixel; XAllocNamedColor( display, attrs.colormap, "#0f0", &col, &col ); green = col.pixel; } while( 1 ) { XEvent event; XNextEvent( display, &event ); switch( event.type ) { case Expose: // Draw XClearWindow( display, window ); XSetForeground( display, gc, red ); XFillRectangle( display, window, gc, 0, 0, width, red_height ); XSetForeground( display, gc, green ); XFillRectangle( display, window, gc, 0, red_height, width, green_height ); break; default: // Do nothing break; } } }