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 nscreens = all_screens(dpy, &screens);
76 printf(_("found no screens to run on\n"));
81 while ((ev = xcb_wait_for_event(dpy->conn))) {
82 printf("event %d\n", ev->response_type);
84 if (!ev->response_type) {
85 display_error(dpy, (xcb_generic_error_t*)ev);
90 switch (ev->response_type) {
91 case XCB_CREATE_NOTIFY:
93 xcb_create_notify_event_t *cev;
96 cev = (xcb_create_notify_event_t*)ev;
97 sc = screen_from_root(screens, nscreens, cev->parent);
99 screen_add_window(sc, cev->window);
102 case XCB_DESTROY_NOTIFY:
104 xcb_destroy_notify_event_t *dev;
108 dev = (xcb_destroy_notify_event_t*)ev;
109 sc = screen_from_root(screens, nscreens, dev->event);
111 w = screen_find_window(sc, dev->window);
113 screen_remove_window(sc, w);
116 case XCB_REPARENT_NOTIFY:
118 xcb_reparent_notify_event_t *rev;
122 rev = (xcb_reparent_notify_event_t*)ev;
123 sc = screen_from_root(screens, nscreens, rev->event);
125 w = screen_find_window(sc, rev->window);
126 if (rev->parent == sc->super.root)
127 screen_add_window(sc, rev->window);
130 screen_remove_window(sc, w);
136 xcb_map_notify_event_t *mev;
140 mev = (xcb_map_notify_event_t*)ev;
141 sc = screen_from_root(screens, nscreens, mev->event);
143 w = screen_find_window(sc, mev->window);
147 case XCB_UNMAP_NOTIFY:
149 xcb_unmap_notify_event_t *mev;
153 mev = (xcb_unmap_notify_event_t*)ev;
154 sc = screen_from_root(screens, nscreens, mev->event);
156 w = screen_find_window(sc, mev->window);