2 * Copyright (c) 2015 Andy Spencer <andy753421@gmail.com>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
23 #include <xcb/xcb_event.h>
24 #include <xcb/xcb_keysyms.h>
25 #include <xcb/xinerama.h>
34 static int border = 2;
35 static int stack = 25;
36 static int no_capture = 0;
38 /* Internal structures */
40 xcb_window_t xcb; // xcb window id
41 xcb_event_mask_t events; // currently watch events
42 int override; // normal vs override redirect
43 int mapped; // window is currently mapped
54 static xcb_connection_t *conn;
55 static xcb_key_symbols_t *keysyms;
56 static xcb_colormap_t colormap;
57 static xcb_window_t root;
58 static xcb_event_mask_t events;
59 static list_t *screens;
61 static xcb_pixmap_t colors[NCOLORS];
62 static unsigned int grabbed;
64 /************************
65 * Conversion functions *
66 ************************/
69 static char *state_map[] = {
90 { EV_PAGEUP, 0xFF55 },
91 { EV_PAGEDOWN, 0xFF56 },
106 /************************
107 * Conversion functions *
108 ************************/
110 static xcb_keycode_t *event_to_keycodes(event_t ev)
112 xcb_keycode_t *codes = NULL;
115 xcb_keysym_t keysym = map_get(keysym_map, ev, ev, sym, ev);
118 if (!(codes = xcb_key_symbols_get_keycode(keysyms, keysym)))
119 warn("no keycode found for %d->%d", ev, keysym);
124 static event_t keycode_to_event(xcb_keycode_t code)
127 xcb_keysym_t keysym = xcb_key_symbols_get_keysym(keysyms, code, 0);
130 return map_get(keysym_map, sym,keysym, ev,keysym);
134 static event_t button_to_event(xcb_button_t btn)
136 return EV_MOUSE0 + btn;
139 static xcb_button_t event_to_button(event_t ev)
141 return ev - EV_MOUSE0;
145 static xcb_mod_mask_t mod_to_mask(mod_t mod)
147 xcb_mod_mask_t mask = 0;
148 if (mod.alt) mask |= XCB_MOD_MASK_1;
149 if (mod.ctrl) mask |= XCB_MOD_MASK_CONTROL;
150 if (mod.shift) mask |= XCB_MOD_MASK_SHIFT;
151 if (mod.win) mask |= XCB_MOD_MASK_4;
155 static mod_t mask_to_mod(xcb_mod_mask_t mask, int up)
157 mod_t mod = { .up = up };
158 if (mask & XCB_MOD_MASK_1) mod.alt = 1;
159 if (mask & XCB_MOD_MASK_CONTROL) mod.ctrl = 1;
160 if (mask & XCB_MOD_MASK_SHIFT) mod.shift = 1;
161 if (mask & XCB_MOD_MASK_4) mod.win = 1;
166 static ptr_t list_to_ptr(int16_t *list)
170 ptr.rx = list[0]; // root_x
171 ptr.ry = list[1]; // root_y
172 ptr.x = list[2]; // event_x
173 ptr.y = list[3]; // event_y
178 /********************
180 ********************/
182 static int win_cmp(const void *_a, const void *_b)
186 if (a->sys->xcb < b->sys->xcb) return -1;
187 if (a->sys->xcb > b->sys->xcb) return 1;
191 static win_t *win_get(xcb_window_t xcb)
193 win_sys_t sys = { .xcb = xcb };
194 win_t key = { .sys = &sys };
196 win_t **win = tfind(&key, &cache, win_cmp);
199 warn("no window for %u", xcb);
210 static int do_query_tree(xcb_window_t win, xcb_window_t **kids)
212 xcb_query_tree_cookie_t cookie =
213 xcb_query_tree(conn, win);
214 if (!cookie.sequence)
215 return warn("do_query_tree: %d - bad cookie", win);
217 xcb_query_tree_reply_t *reply =
218 xcb_query_tree_reply(conn, cookie, NULL);
220 return warn("do_query_tree: %d - no reply", win);
222 int nkids = xcb_query_tree_children_length(reply);
223 *kids = xcb_query_tree_children(reply);
224 printf("do_query_tree: %d - n=%d\n", win, nkids);
228 static int do_get_geometry(xcb_window_t win,
229 int *x, int *y, int *w, int *h)
231 xcb_get_geometry_cookie_t cookie =
232 xcb_get_geometry(conn, win);
233 if (!cookie.sequence)
234 return warn("do_get_geometry: %d - bad cookie", win);
236 xcb_get_geometry_reply_t *reply =
237 xcb_get_geometry_reply(conn, cookie, NULL);
239 return warn("do_get_geometry: %d - no reply", win);
241 printf("do_get_geometry: %d - %dx%d @ %d,%d\n",
242 win, reply->width, reply->height, reply->x, reply->y);
250 static int do_get_window_attributes(xcb_window_t win,
251 int *override, int *mapped)
253 xcb_get_window_attributes_cookie_t cookie =
254 xcb_get_window_attributes(conn, win);
255 if (!cookie.sequence)
256 return warn("do_get_window_attributes: %d - bad cookie", win);
258 xcb_get_window_attributes_reply_t *reply =
259 xcb_get_window_attributes_reply(conn, cookie, NULL);
261 return warn("do_get_window_attributes: %d - no reply ", win);
263 printf("do_get_window_attributes: %d - %d\n",
264 win, reply->override_redirect);
265 *override = reply->override_redirect;
266 *mapped = reply->map_state != XCB_MAP_STATE_UNMAPPED;
270 static int do_xinerama_check(void)
272 const xcb_query_extension_reply_t *data =
273 xcb_get_extension_data(conn, &xcb_xinerama_id);
274 if (!data || !data->present)
275 return warn("do_xinerama_check: no ext");
277 xcb_xinerama_is_active_cookie_t cookie =
278 xcb_xinerama_is_active(conn);
279 if (!cookie.sequence)
280 return warn("do_xinerama_check: no cookie");
282 xcb_xinerama_is_active_reply_t *reply =
283 xcb_xinerama_is_active_reply(conn, cookie, NULL);
285 warn("do_xinerama_check: no reply");
287 printf("do_xinerama_check: %d\n", reply->state);
288 return reply && reply->state;
291 static int do_query_screens(xcb_xinerama_screen_info_t **info)
293 xcb_xinerama_query_screens_cookie_t cookie =
294 xcb_xinerama_query_screens(conn);
295 if (!cookie.sequence)
296 return warn("do_query_screens: bad cookie");
298 xcb_xinerama_query_screens_reply_t *reply =
299 xcb_xinerama_query_screens_reply(conn, cookie, NULL);
301 return warn("do_query_screens: no reply");
303 int ninfo = xcb_xinerama_query_screens_screen_info_length(reply);
304 *info = xcb_xinerama_query_screens_screen_info(reply);
305 printf("do_query_screens: %d screens\n", ninfo);
309 static int do_get_input_focus(void)
311 xcb_get_input_focus_cookie_t cookie =
312 xcb_get_input_focus(conn);
313 if (!cookie.sequence)
314 return warn("do_get_input_focus: bad cookie");
316 xcb_get_input_focus_reply_t *reply =
317 xcb_get_input_focus_reply(conn, cookie, NULL);
319 return warn("do_get_input_focus: no reply");
324 static xcb_pixmap_t do_alloc_color(uint32_t rgb)
326 uint16_t r = (rgb & 0xFF0000) >> 8;
327 uint16_t g = (rgb & 0x00FF00);
328 uint16_t b = (rgb & 0x0000FF) << 8;
329 xcb_alloc_color_cookie_t cookie =
330 xcb_alloc_color(conn, colormap, r, g, b);
331 if (!cookie.sequence)
332 return warn("do_alloc_color: bad cookie");
334 xcb_alloc_color_reply_t *reply =
335 xcb_alloc_color_reply(conn, cookie, NULL);
337 return warn("do_alloc_color: no reply");
339 printf("do_alloc_color: %06x -> %06x\n", rgb, reply->pixel);
343 static void do_grab_pointer(xcb_event_mask_t mask)
346 xcb_grab_pointer(conn, 0, root, mask,
349 0, 0, XCB_CURRENT_TIME);
353 static void do_ungrab_pointer(void)
357 xcb_ungrab_pointer(conn, XCB_CURRENT_TIME);
360 static void do_configure_window(xcb_window_t win,
361 int x, int y, int w, int h,
365 { x, XCB_CONFIG_WINDOW_X },
366 { y, XCB_CONFIG_WINDOW_Y },
367 { w, XCB_CONFIG_WINDOW_WIDTH },
368 { h, XCB_CONFIG_WINDOW_HEIGHT },
369 { b, XCB_CONFIG_WINDOW_BORDER_WIDTH },
370 { s, XCB_CONFIG_WINDOW_SIBLING },
371 { r, XCB_CONFIG_WINDOW_STACK_MODE },
375 uint32_t list[7] = {};
376 for (int i = 0; i < 7; i++) {
377 if (table[i][0] >= 0) {
378 list[i] = table[i][0];
383 xcb_configure_window(conn, win, mask, list);
386 /**************************
387 * Window Manager Helpers *
388 **************************/
390 /* Send event info */
391 static int send_event(event_t ev, xcb_window_t ewin)
393 win_t *win = win_get(ewin);
395 int status = wm_handle_event(win, ev, MOD(), PTR());
400 /* Send event info */
401 static int send_event_info(event_t ev, xcb_mod_mask_t mask, int up, int16_t *pos,
402 xcb_window_t rwin, xcb_window_t ewin, xcb_window_t cwin)
404 xcb_window_t xcb = ewin == rwin ? cwin : ewin;
405 win_t *win = win_get(xcb);
406 mod_t mod = mask_to_mod(mask, up);
407 ptr_t ptr = list_to_ptr(pos);
409 int status = wm_handle_event(win, ev, mod, ptr);
414 /* Send pointer motion info */
415 static int send_pointer(int16_t *pos,
416 xcb_window_t rwin, xcb_window_t ewin, xcb_window_t cwin)
418 xcb_window_t xcb = ewin == rwin ? cwin : ewin;
419 win_t *win = win_get(xcb);
420 ptr_t ptr = list_to_ptr(pos);
422 int status = wm_handle_ptr(win, ptr);
427 /* Send window state info */
428 static int send_state(void)
434 /**********************
435 * X11 Event Handlers *
436 **********************/
438 /* Specific events */
439 static void on_key_event(xcb_key_press_event_t *event, int up)
441 printf("on_key_event: xcb=%-8u\n", event->event);
442 xcb_window_t focus = do_get_input_focus();
443 event_t ev = keycode_to_event(event->detail);
444 send_event_info(ev, event->state, up, &event->root_x,
445 event->root, focus, event->child);
448 static void on_button_event(xcb_button_press_event_t *event, int up)
450 printf("on_button_event: xcb=%-8u\n", event->event);
451 event_t ev = button_to_event(event->detail);
452 if (!send_event_info(ev, event->state, up, &event->root_x,
453 event->root, event->event, event->child))
454 xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time);
456 do_grab_pointer(XCB_EVENT_MASK_POINTER_MOTION |
457 XCB_EVENT_MASK_BUTTON_RELEASE);
463 static void on_motion_notify(xcb_motion_notify_event_t *event)
465 printf("on_motion_notify: xcb=%-8u - %d,%d / %d.%d\n", event->event,
466 event->event_x, event->event_y,
467 event->root_x, event->root_y);
468 send_pointer(&event->root_x, event->root, event->event, event->child);
471 static void on_enter_notify(xcb_enter_notify_event_t *event)
473 if (event->mode != XCB_NOTIFY_MODE_NORMAL)
475 printf("on_enter_notify: xcb=%-8u\n", event->event);
476 send_event_info(EV_ENTER, event->state, 0, &event->root_x,
477 event->root, event->event, event->child);
480 static void on_leave_notify(xcb_leave_notify_event_t *event)
482 if (event->mode != XCB_NOTIFY_MODE_NORMAL)
484 printf("on_leave_notify: xcb=%-8u\n", event->event);
485 send_event_info(EV_LEAVE, event->state, 0, &event->root_x,
486 event->root, event->event, event->child);
489 static void on_focus_in(xcb_focus_in_event_t *event)
491 if (event->mode != XCB_NOTIFY_MODE_NORMAL &&
492 event->mode != XCB_NOTIFY_MODE_WHILE_GRABBED)
494 printf("on_focus_in: xcb=%-8u mode=%d\n", event->event, event->mode);
495 xcb_change_window_attributes(conn, event->event,
496 XCB_CW_BORDER_PIXEL, &colors[CLR_FOCUS]);
497 if (event->mode == XCB_NOTIFY_MODE_NORMAL)
498 send_event(EV_FOCUS, event->event);
501 static void on_focus_out(xcb_focus_out_event_t *event)
503 if (event->mode != XCB_NOTIFY_MODE_NORMAL &&
504 event->mode != XCB_NOTIFY_MODE_WHILE_GRABBED)
506 printf("on_focus_out: xcb=%-8u mode=%d\n", event->event, event->mode);
507 xcb_change_window_attributes(conn, event->event,
508 XCB_CW_BORDER_PIXEL, &colors[CLR_UNFOCUS]);
509 if (event->mode == XCB_NOTIFY_MODE_NORMAL)
510 send_event(EV_UNFOCUS, event->event);
513 static void on_create_notify(xcb_create_notify_event_t *event)
515 win_t *win = new0(win_t);
516 win_sys_t *sys = new0(win_sys_t);
518 printf("on_create_notify: xcb=%-8u -> win=%p\n",
523 win->w = event->width;
524 win->h = event->height;
527 sys->xcb = event->window;
528 sys->override = event->override_redirect;
530 tsearch(win, &cache, win_cmp);
533 static void on_destroy_notify(xcb_destroy_notify_event_t *event)
535 win_t *win = win_get(event->window);
536 printf("on_destroy_notify: xcb=%-8u -> win=%p\n",
540 tdelete(win, &cache, win_cmp);
546 static void on_map_request(xcb_map_request_event_t *event)
548 win_t *win = win_get(event->window);
549 printf("on_map_request: xcb=%-8u -> win=%p\n",
553 if (!win->sys->override && !win->sys->mapped)
555 win->sys->mapped = 1;
557 xcb_map_window(conn, win->sys->xcb);
558 sys_move(win, win->x, win->y, win->w, win->h);
561 static void on_configure_request(xcb_configure_request_event_t *event)
563 win_t *win = win_get(event->window);
564 printf("on_configure_request: xcb=%-8u -> win=%p -- %dx%d @ %d,%d\n",
566 event->width, event->height,
572 win->w = event->width;
573 win->h = event->height;
575 xcb_configure_notify_event_t resp = {
576 .response_type = XCB_CONFIGURE_NOTIFY,
577 .event = win->sys->xcb,
578 .window = win->sys->xcb,
583 .border_width = border,
586 xcb_send_event(conn, 0, win->sys->xcb,
587 XCB_EVENT_MASK_STRUCTURE_NOTIFY,
588 (const char *)&resp);
592 static void on_event(xcb_generic_event_t *event)
594 int type = XCB_EVENT_RESPONSE_TYPE(event);
599 on_key_event((xcb_key_press_event_t *)event, 0);
601 case XCB_KEY_RELEASE:
602 on_key_event((xcb_key_release_event_t *)event, 1);
604 case XCB_BUTTON_PRESS:
605 on_button_event((xcb_button_press_event_t *)event, 0);
607 case XCB_BUTTON_RELEASE:
608 on_button_event((xcb_button_release_event_t *)event, 1);
610 case XCB_MOTION_NOTIFY:
611 on_motion_notify((xcb_motion_notify_event_t *)event);
613 case XCB_ENTER_NOTIFY:
614 on_enter_notify((xcb_enter_notify_event_t *)event);
616 case XCB_LEAVE_NOTIFY:
617 on_leave_notify((xcb_leave_notify_event_t *)event);
620 on_focus_in((xcb_focus_in_event_t *)event);
623 on_focus_out((xcb_focus_out_event_t *)event);
626 /* Window management */
627 case XCB_CREATE_NOTIFY:
628 on_create_notify((xcb_create_notify_event_t *)event);
630 case XCB_DESTROY_NOTIFY:
631 on_destroy_notify((xcb_destroy_notify_event_t *)event);
633 case XCB_MAP_REQUEST:
634 on_map_request((xcb_map_request_event_t *)event);
636 case XCB_CONFIGURE_REQUEST:
637 on_configure_request((xcb_configure_request_event_t *)event);
642 printf("on_event: %d:%02X -> %s\n",
643 XCB_EVENT_SENT(event) != 0,
644 XCB_EVENT_RESPONSE_TYPE(event),
645 xcb_event_get_label(type) ?: "unknown_event");
650 /********************
652 ********************/
654 void sys_move(win_t *win, int x, int y, int w, int h)
656 printf("sys_move: %p - %dx%d @ %d,%d\n",
668 do_configure_window(win->sys->xcb, x, y, w, h, -1, -1, -1);
671 void sys_raise(win_t *win)
673 printf("sys_raise: %p\n", win);
675 uint16_t mask = XCB_CONFIG_WINDOW_STACK_MODE;
676 uint32_t list = XCB_STACK_MODE_ABOVE;
678 xcb_configure_window(conn, win->sys->xcb, mask, &list);
681 void sys_focus(win_t *win)
683 printf("sys_focus: %p\n", win);
684 xcb_window_t xcb = win ? win->sys->xcb : root;
686 xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT,
687 xcb, XCB_CURRENT_TIME);
690 void sys_show(win_t *win, state_t state)
692 printf("sys_show: %p - %s -> %s\n", win,
693 state_map[win->state], state_map[state]);
694 xcb_window_t xcb = win ? win->sys->xcb : root;
697 win_t *screen = NULL;
698 if (state == ST_FULL || state == ST_MAX) {
699 for (list_t *cur = screens; cur; cur = cur->next) {
701 if (win->x >= screen->x && win->x <= screen->x+screen->w &&
702 win->y >= screen->y && win->y <= screen->y+screen->h)
707 /* Change window state */
710 xcb_unmap_window(conn, xcb);
714 xcb_map_window(conn, xcb);
715 do_configure_window(xcb, win->x, win->y,
716 MAX(win->w - 2*border, 1),
717 MAX(win->h - 2*border, 1),
722 xcb_map_window(conn, xcb);
723 do_configure_window(xcb, screen->x, screen->y, screen->w, screen->h,
724 0, -1, XCB_STACK_MODE_ABOVE);
725 xcb_circulate_window(conn, XCB_CIRCULATE_RAISE_LOWEST, xcb);
729 xcb_map_window(conn, xcb);
730 do_configure_window(xcb, screen->x, screen->y,
731 MAX(screen->w - 2*border, 1),
732 MAX(screen->h - 2*border, 1),
733 border, -1, XCB_STACK_MODE_ABOVE);
737 xcb_map_window(conn, xcb);
738 do_configure_window(xcb, -1, -1, -1, stack,
743 xcb_map_window(conn, xcb);
744 do_configure_window(xcb, -1, -1, 100, 100,
749 xcb_kill_client(conn, xcb);
757 void sys_watch(win_t *win, event_t ev, mod_t mod)
759 printf("sys_watch: %p - 0x%X,0x%X\n", win, ev, mod2int(mod));
760 xcb_window_t xcb = win ? win->sys->xcb : root;
761 xcb_event_mask_t *mask = win ? &win->sys->events : &events;
762 xcb_mod_mask_t mods = 0;
763 xcb_button_t btn = 0;
764 xcb_keycode_t *code = 0;
768 *mask |= XCB_EVENT_MASK_ENTER_WINDOW;
769 xcb_change_window_attributes(conn, xcb, XCB_CW_EVENT_MASK, mask);
773 *mask |= XCB_EVENT_MASK_LEAVE_WINDOW;
774 xcb_change_window_attributes(conn, xcb, XCB_CW_EVENT_MASK, mask);
779 *mask |= XCB_EVENT_MASK_FOCUS_CHANGE;
780 xcb_change_window_attributes(conn, xcb, XCB_CW_EVENT_MASK, mask);
783 case EV_MOUSE0...EV_MOUSE7:
784 btn = event_to_button(ev);
785 mods = mod_to_mask(mod);
786 *mask |= mod.up ? XCB_EVENT_MASK_BUTTON_RELEASE
787 : XCB_EVENT_MASK_BUTTON_PRESS;
788 xcb_grab_button(conn, 0, xcb, *mask,
795 code = event_to_keycodes(ev);
796 mods = mod_to_mask(mod);
797 for (int i = 0; code && code[i] != XCB_NO_SYMBOL; i++)
798 xcb_grab_key(conn, 1, xcb, mods, code[i],
800 XCB_GRAB_MODE_ASYNC);
806 void sys_unwatch(win_t *win, event_t ev, mod_t mod)
808 printf("sys_unwatch: %p - 0x%X,0x%X\n", win, ev, mod2int(mod));
811 list_t *sys_info(void)
813 printf("sys_info\n");
815 if (screens == NULL && do_xinerama_check()) {
816 /* Add Xinerama screens */
817 xcb_xinerama_screen_info_t *info = NULL;
818 int ninfo = do_query_screens(&info);
819 for (int i = 0; i < ninfo; i++) {
820 win_t *screen = new0(win_t);
822 screen->x = info[i].x_org;
823 screen->y = info[i].y_org;
824 screen->w = info[i].width;
825 screen->h = info[i].height;
827 screens = list_insert(NULL, screen);
829 printf("sys_info: xinerama screen - %dx%d @ %d,%d\n",
830 screen->w, screen->h,
831 screen->x, screen->y);
835 if (screens == NULL) {
836 /* No xinerama support */
837 const xcb_setup_t *setup = xcb_get_setup(conn);
838 xcb_screen_t *geom = xcb_setup_roots_iterator(setup).data;
840 win_t *screen = new0(win_t);
842 screen->w = geom->width_in_pixels;
843 screen->h = geom->height_in_pixels;
845 screens = list_insert(NULL, screen);
847 printf("sys_info: root screen - %dx%d\n",
848 screen->w, screen->h);
856 printf("sys_init\n");
858 /* Load configuration */
859 stack = conf_get_int("main.stack", stack);
860 border = conf_get_int("main.border", border);
861 no_capture = conf_get_int("main.no-capture", no_capture);
863 /* Connect to display */
864 if (!(conn = xcb_connect(NULL, NULL)))
865 error("xcb connect failed");
866 if (xcb_connection_has_error(conn))
867 error("xcb connection has errors");
869 /* Get root window */
870 const xcb_setup_t *setup = xcb_get_setup(conn);
871 xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup);
872 root = iter.data->root;
873 colormap = iter.data->default_colormap;
875 /* Setup for for ST_CLOSE */
876 xcb_set_close_down_mode(conn, XCB_CLOSE_DOWN_DESTROY_ALL);
878 /* Allocate key symbols */
879 if (!(keysyms = xcb_key_symbols_alloc(conn)))
880 error("cannot allocate key symbols");
882 /* Read color information */
883 colors[CLR_FOCUS] = do_alloc_color(0xFF6060);
884 colors[CLR_UNFOCUS] = do_alloc_color(0xD8D8FF);
885 colors[CLR_URGENT] = do_alloc_color(0xFF0000);
887 /* Request substructure redirect */
888 xcb_void_cookie_t cookie;
889 xcb_generic_error_t *err;
890 events = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
891 XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY;
892 cookie = xcb_change_window_attributes_checked(conn, root,
893 XCB_CW_EVENT_MASK, &events);
894 if ((err = xcb_request_check(conn, cookie)))
895 error("another window manager is already running");
902 /* Add each initial window */
904 xcb_window_t *kids = NULL;
905 int nkids = do_query_tree(root, &kids);
906 for(int i = 0; i < nkids; i++) {
907 win_t *win = new0(win_t);
908 win->sys = new0(win_sys_t);
909 win->sys->xcb = kids[i];
910 do_get_geometry(kids[i], &win->x, &win->y, &win->w, &win->h);
911 do_get_window_attributes(kids[i],
912 &win->sys->override, &win->sys->mapped);
913 tsearch(win, &cache, win_cmp);
914 if (!win->sys->override && win->sys->mapped)
924 xcb_generic_event_t *event;
925 if (!(event = xcb_wait_for_event(conn)))
929 if (!(status = xcb_flush(conn)))
936 printf("sys_exit\n");
938 xcb_disconnect(conn);
944 printf("sys_free\n");
946 xcb_disconnect(conn);