#include #include #include #include #include #include #include #define ARRAY_LENGTH(a) (sizeof (a) / sizeof ((a)[0])) static const int width = 400; static const int height = 300; static void draw (Display *dpy, Drawable drawable, GC gc) { XPoint points0[] = { { -10, 20 }, { 20, -10 }, { 40, 20 }, { 60, -20 }, }; XPoint points1[] = { { -2, 40 }, { 0, 42 }, { 2, 40 }, { 4, 42 }, { 6, 40 }, }; XPoint points2[] = { { -2, 50 }, { 0, 52 }, { 2, 50 }, { 4, 52 }, { 6, 50 }, }; XDrawLines (dpy, drawable, gc, points0, ARRAY_LENGTH (points0), CoordModeOrigin); XDrawLines (dpy, drawable, gc, points1, ARRAY_LENGTH (points1), CoordModeOrigin); XDrawLines (dpy, drawable, gc, points2, ARRAY_LENGTH (points2), CoordModeOrigin); } int main (int argc, char **argv) { Display *display; Window win; unsigned long event_mask; GC gc; Visual *visual; Colormap cmap; XEvent xev; XGCValues gcv; XSetWindowAttributes attributes; int scr, depth; const char *display_name; display_name = getenv ("DISPLAY"); display = XOpenDisplay (display_name); if (display == NULL) { fprintf (stderr, "Failed to open display: %s\n", display_name); return 1; } scr = DefaultScreen (display); cmap = DefaultColormap (display, scr); visual = DefaultVisual (display, scr); depth = DefaultDepth (display, scr); attributes.background_pixel = WhitePixel(display, scr); win = XCreateWindow (display, RootWindow (display, scr), 0, 0, width, height, 0, depth, InputOutput, visual, CWBackPixel, &attributes); gcv.foreground = BlackPixel(display, scr); gc = XCreateGC(display, win, GCForeground, &gcv); event_mask = (KeyPressMask | StructureNotifyMask | ExposureMask); XSelectInput (display, win, event_mask); XMapWindow (display, win); while (1) { XNextEvent (display, &xev); switch (xev.xany.type) { case KeyPress: if (XKeycodeToKeysym (display, xev.xkey.keycode, 0) == XK_q) goto out; break; case ConfigureNotify: case Expose: draw (display, win, gc); break; } } out: XFreeGC (display, gc); XDestroyWindow (display, win); XCloseDisplay (display); return 0; }