wait_for_event (struct wrapper *bc) { struct timeval timeout; fd_set fds; bool handled_p = false; int fd; fd = XConnectionNumber (bc->dpy); do { while (!XPending (bc->dpy)) { FD_ZERO (&fds); FD_SET (fd, &fds); struct timeval *timeout_ptr; timeout.tv_usec = 0; timeout.tv_sec = 1; timeout_ptr = &timeout; if ((select (fd + 1, &fds, NULL, NULL, timeout_ptr)) <= 0) printf ("signal\n"); } XNextEvent (bc->dpy, &bc->event); switch (bc->event.type) { case KeyPress: XBell (bc->dpy, 100); handled_p = true; break;