/* * cc -o testclose -g testclose.c $(pkg-config --cflags --libs x11) */ #include #include #include #include #include #include #include #include #include #include #include #define BASE_WIDTH 800 #define BASE_HEIGHT 600 static const unsigned char xlib_spinning_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, 0xfc, 0x3b, 0x00, 0x00, 0x7c, 0x38, 0x00, 0x00, 0x6c, 0x54, 0x00, 0x00, 0xc4, 0xdc, 0x00, 0x00, 0xc0, 0x44, 0x00, 0x00, 0x80, 0x39, 0x00, 0x00, 0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const unsigned char xlib_spinning_mask_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfe, 0x3b, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x00, 0xee, 0xff, 0x01, 0x00, 0xe4, 0xff, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, 0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static Cursor cursorCreateSpinning (Display * dpy) { Pixmap cursor; Pixmap mask; XColor fg, bg; Cursor xcursor; fg.pixel = 0; fg.red = 0; fg.green = 0; fg.blue = 0; fg.flags = 0xf; bg.pixel = 0xffffffff; bg.red = 0xffff; bg.green = 0xffff; bg.blue = 0xffff; bg.flags = 0xf; cursor = XCreatePixmapFromBitmapData (dpy, DefaultRootWindow(dpy), (char *) xlib_spinning_bits, 32, 32, 0xffffffff, 0x0, 1); mask = XCreatePixmapFromBitmapData (dpy, DefaultRootWindow(dpy), (char *) xlib_spinning_mask_bits, 32, 32, 0xffffffff, 0x0, 1); xcursor = XCreatePixmapCursor (dpy, cursor, mask, &fg, &bg, 2, 2); XFreePixmap (dpy, mask); XFreePixmap (dpy, cursor); return xcursor; } static Window create_win (Display * dpy) { XSetWindowAttributes attributes; Window win; attributes.background_pixel = WhitePixel (dpy, DefaultScreen (dpy)); win = XCreateWindow(dpy, DefaultRootWindow(dpy), 100, 100, BASE_WIDTH, BASE_HEIGHT, 0, DefaultDepth (dpy, DefaultScreen (dpy)), InputOutput, DefaultVisual (dpy, DefaultScreen (dpy)), CWBackPixel, &attributes); XSelectInput(dpy, win, ExposureMask | StructureNotifyMask | PointerMotionMask); XDefineCursor(dpy, win, cursorCreateSpinning (dpy)); return win; } int main (int argc, char *argv[]) { int wstatus; for (;;) { pid_t pid; int nbytes; if ((pid = fork ()) == -1) { perror ("fork"); exit (1); } if (!pid) { /* Child */ Display *dpy; Window win; XEvent event; int nevents; dpy = XOpenDisplay (NULL); win = create_win (dpy); XMapWindow (dpy, win); XFlush (dpy); nevents = 0; while (nevents < 10) { XNextEvent (dpy, &event); nevents++; } kill (getpid(), SIGINT); } else { waitpid(pid, &wstatus, 0); usleep (5000); } } return 0; }