/* This should compile using: gcc X11_testAPI.c-o X11_test -I /usr/include/X11 -L /usr/X11/lib -lX11 */ // X11 header files. #include #include #include // Declare X11 globals Display *display; /* X11 display type */ int screen; /* X11 - client screen */ Window win; /* X11 Window type */ GC gc; /* X11 GC (graphic context) type */ /** Function declarations. */ void window_init(); void close_window(); void redraw(); /** Main */ int main() { window_init(); // Basic setup for events and keypress keys XEvent event; /* XEvent declaration. */ KeySym key; /* KeyPress event key */ char text[255]; /* Buffer for KeyPress events */ _Bool run = 1; while(run) { XNextEvent(display, &event); if (event.type==Expose && event.xexpose.count==0) { /* The window was exposed, redraw it */ redraw(); } XSetForeground(display, gc, 100); // 100 is a color XFillRectangle(display, win, gc, 30, 30, 200, 200); } } /* END MAIN */ /** Function definitions. */ /* window_init creates and manages a window and it's structures.*/ void window_init() { unsigned long black, white; display=XOpenDisplay((char *)0); screen=DefaultScreen(display); black=BlackPixel(display, screen), white=WhitePixel(display, screen); win=XCreateSimpleWindow(display,DefaultRootWindow(display), 50, 50, 500, 500, 5, black, white); XSetStandardProperties(display, win, "zeta","zeta", None, NULL, 0, NULL); // NOTE: At minimum, we have to select the ExposureMask in order for draw // functions to produce output (draw) to the window. XSelectInput(display, win, ExposureMask|ButtonPressMask|KeyPressMask); gc=XCreateGC(display, win, 0, 0); XSetBackground(display, gc, white); XSetForeground(display, gc, black); XClearWindow(display, win); XMapRaised(display, win); }; void close_window() { XFreeGC(display, gc); XDestroyWindow(display, win); XCloseDisplay(display); }; void redraw() { XClearWindow(display, win); };