#include // Every Xlib program must include this #include // I include this to test return values the lazy way #include // So we got the profile for 10 seconds #include #include #include #define NIL (0) // A name for the void pointer void printBacktrace() { int j, nptrs; #define SIZE 100 void *buffer[100]; char **strings; nptrs = backtrace(buffer, SIZE); printf("backtrace() returned %d addresses\n", nptrs); /* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO) would produce similar output to the following: */ strings = backtrace_symbols(buffer, nptrs); if (strings == NULL) { perror("backtrace_symbols"); exit(EXIT_FAILURE); } for (j = 0; j < nptrs; j++) printf("%s\n", strings[j]); free(strings); } int myIOXError(Display *disp) { printf("ERROR Received a X IO error on display=%x.\n", disp); printBacktrace(); return True; } main() { Display *dpy = XOpenDisplay(NIL); assert(dpy); int blackColor = BlackPixel(dpy, DefaultScreen(dpy)); int whiteColor = WhitePixel(dpy, DefaultScreen(dpy)); // Create the window Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 200, 100, 0, blackColor, blackColor); // We want to get MapNotify events XSelectInput(dpy, w, StructureNotifyMask); // "Map" the window (that is, make it appear on the screen) XMapWindow(dpy, w); // Create a "Graphics Context" GC gc = XCreateGC(dpy, w, 0, NIL); // Tell the GC we draw using the white color XSetForeground(dpy, gc, whiteColor); // register io error handler XSetIOErrorHandler(myIOXError); // Wait for the MapNotify event for(;;) { XEvent e; XNextEvent(dpy, &e); if (e.type == MapNotify) break; } // Draw the line for(;;) { XDrawLine(dpy, w, gc, 10, 60, 180, 20); // Send the "DrawLine" request to the server XFlush(dpy); } // Wait for 10 seconds sleep(10); }