17 all_screens(d_display_t *dpy, d_screen_t **list)
19 static const xcb_setup_t *setup;
20 xcb_screen_iterator_t it;
24 setup = xcb_get_setup(dpy->conn);
27 for (it = xcb_setup_roots_iterator(setup); it.rem; xcb_screen_next(&it)) {
31 if (screen_register(&sc)) {
33 *list = realloc(*list, sizeof(d_screen_t)*count);
34 (*list)[count-1] = sc;
35 printf(_("managing screen %d\n"), sc.num);
42 screen_from_root(d_screen_t *list, int n, xcb_window_t root)
45 for (i = 0; i < n; ++i)
46 if (list->super.root == root) return &list[i];
47 g_assert_not_reached();
52 void read_options(int argc, char **argv, d_options_t *opts)
54 opts->foo = argc && argv;
58 main(int argc, char **argv)
61 d_screen_t *screens = NULL;
63 xcb_generic_event_t *ev;
66 read_options(argc, argv, &opts);
68 dpy = display_open(NULL);
70 printf(_("Unable to connect to display\n"));
74 if (!dpy->composite.present) {
75 printf(_("no composite extension present on the display\n"));
79 if (!dpy->xfixes.present) {
80 printf(_("no xfixes extension present on the display\n"));
84 if (!dpy->damage.present) {
85 printf(_("no damage extension present on the display\n"));
89 if (!dpy->render.present) {
90 printf(_("no render extension present on the display\n"));
95 nscreens = all_screens(dpy, &screens);
97 printf(_("found no screens to run on\n"));
102 while ((ev = xcb_wait_for_event(dpy->conn))) {
103 printf("event %d\n", ev->response_type);
105 if (!ev->response_type) {
106 display_error(dpy, (xcb_generic_error_t*)ev);
111 switch (ev->response_type) {
112 case XCB_CREATE_NOTIFY:
114 xcb_create_notify_event_t *cev;
117 cev = (xcb_create_notify_event_t*)ev;
118 sc = screen_from_root(screens, nscreens, cev->parent);
120 screen_add_window(sc, cev->window);
123 case XCB_DESTROY_NOTIFY:
125 xcb_destroy_notify_event_t *dev;
129 dev = (xcb_destroy_notify_event_t*)ev;
130 sc = screen_from_root(screens, nscreens, dev->event);
132 w = screen_find_window(sc, dev->window);
134 screen_remove_window(sc, w);
137 case XCB_REPARENT_NOTIFY:
139 xcb_reparent_notify_event_t *rev;
143 rev = (xcb_reparent_notify_event_t*)ev;
144 sc = screen_from_root(screens, nscreens, rev->event);
146 w = screen_find_window(sc, rev->window);
147 if (rev->parent == sc->super.root)
148 screen_add_window(sc, rev->window);
151 screen_remove_window(sc, w);
157 xcb_map_notify_event_t *mev;
161 mev = (xcb_map_notify_event_t*)ev;
162 sc = screen_from_root(screens, nscreens, mev->event);
164 w = screen_find_window(sc, mev->window);
168 case XCB_UNMAP_NOTIFY:
170 xcb_unmap_notify_event_t *mev;
174 mev = (xcb_unmap_notify_event_t*)ev;
175 sc = screen_from_root(screens, nscreens, mev->event);
177 w = screen_find_window(sc, mev->window);