#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <locale.h>

Display *d;
Window w;
Screen s;

int main(void)
{
   XSizeHints *hints;
   XEvent evt;
   char s[80];
   XFontStruct *fontInfo;
   GC gc;
   XChar2b *ws;
   XSetWindowAttributes attr;
   int i, vis;

   setlocale(LC_ALL, "");

   d = XOpenDisplay(NULL);

   w = XCreateSimpleWindow(d, DefaultRootWindow(d), 100, 100,
       500, 375, 0, BlackPixel(d, 0), WhitePixel(d, 0));

   attr.event_mask = KeyPressMask | StructureNotifyMask;
   XChangeWindowAttributes(d, w, CWEventMask, &attr);
   XStoreName(d, w, "Draw String");

   if (! w) {
       printf("Error creating window!\n");
       exit(1);
   }

   hints = XAllocSizeHints();
   hints->flags = USPosition;
   hints->x = 100; hints->y = 100;
   XSetNormalHints(d, w, hints);
   XMapWindow(d, w);

   while(1) {
       while(XPending(d)) {
           XNextEvent(d, &evt);
           switch(evt.type) {
               case ConfigureNotify: {
                   XConfigureEvent *cevt = (XConfigureEvent *) &evt;
                   fprintf(stderr, "cevt->x: %d  cevt->y: %d\n",
                           cevt->x, cevt->y);
               }
                   break;
               case KeyPress:
                   exit(0);
                   break;
           }
       }
       usleep(1000);
   }
}