-int main(int argc, char *argv[])
-{
- char buf[32];
- char *username;
- int num, screen;
-
- unsigned int len;
- bool running = true;
-
- /* By default, fork, don’t beep and don’t turn off monitor */
- bool dont_fork = false;
- bool beep = false;
- bool dpms = false;
- bool xpm_image = false;
- bool tiling = false;
- char xpm_image_path[256];
- char color[7] = "ffffff"; // white
-
- unsigned char *curs = NULL;
- unsigned char *mask = NULL;
- unsigned int curs_w, curs_h;
-
- Cursor cursor;
- Display *dpy;
- KeySym ksym;
- Pixmap px_curs;
- Pixmap px_mask;
- Window root, w;
- XColor black, white, dummy;
- XEvent ev;
- XSetWindowAttributes wa;
-
- pam_handle_t *handle;
- struct pam_conv conv = {conv_callback, NULL};
-
- char opt;
- int optind = 0;
- static struct option long_options[] = {
- {"version", no_argument, NULL, 'v'},
- {"nofork", no_argument, NULL, 'n'},
- {"beep", no_argument, NULL, 'b'},
- {"dpms", no_argument, NULL, 'd'},
- {"image", required_argument, NULL, 'i'},
- {"color", required_argument, NULL, 'c'},
- {"tiling", no_argument, NULL, 't'},
- {"pointer", required_argument, NULL , 'p'},
- {NULL, no_argument, NULL, 0}
- };
- curs = curs_invisible_bits;
- mask = curs_invisible_bits;
- curs_w = curs_invisible_width;
- curs_h = curs_invisible_height;
-
- while ((opt = getopt_long(argc, argv, "vnbdi:c:tp:", long_options, &optind)) != -1) {
- switch (opt) {
- case 'v':
- errx(0, "i3lock-"VERSION", © 2009 Michael Stapelberg\n"
- "based on slock, which is © 2006-2008 Anselm R Garbe\n");
- case 'n':
- dont_fork = true;
- break;
- case 'b':
- beep = true;
- break;
- case 'd':
- dpms = true;
- break;
- case 'i':
- strncpy(xpm_image_path, optarg, 255);
- xpm_image = true;
- break;
- case 'c':
- {
- char *arg = optarg;
- /* Skip # if present */
- if (arg[0] == '#')
- arg++;
-
- if (strlen(arg) != 6 || sscanf(arg, "%06[0-9a-fA-F]", color) != 1)
- errx(1, "color is invalid, color must be given in 6-byte format: rrggbb\n");
-
- break;
- }
- case 't':
- tiling = true;
- break;
- case 'p':
- if (!strcmp(optarg, "default")) {
- curs = NULL;
- break;
- }
- if (!strcmp(optarg, "win")) {
- curs = curs_windows_bits;
- mask = mask_windows_bits;
- curs_w = curs_windows_width;
- curs_h = curs_windows_height;
- break;
- }
- break;
- default:
- errx(1, "i3lock: Unknown option. Syntax: i3lock [-v] [-n] [-b] [-d] [-i image.xpm] [-c color] [-t] [-p win|default]\n");
- }
+/*
+ * Instead of polling the X connection socket we leave this to
+ * xcb_poll_for_event() which knows better than we can ever know.
+ *
+ */
+static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
+ xcb_generic_event_t *event;
+
+ while ((event = xcb_poll_for_event(conn)) != NULL) {
+ if (event->response_type == 0) {
+ xcb_generic_error_t *error = (xcb_generic_error_t*)event;
+ if (debug_mode)
+ fprintf(stderr, "X11 Error received! sequence 0x%x, error_code = %d\n",
+ error->sequence, error->error_code);
+ free(event);
+ continue;