11 #include <sys/select.h>
21 read_options(int argc, char **argv, d_options_t *opts)
23 opts->foo = argc && argv;
27 event(d_display_t *dpy)
29 xcb_generic_event_t *ev;
31 while ((ev = xcb_poll_for_event(dpy->conn))) {
32 printf("event %d\n", ev->response_type);
34 if (!ev->response_type) {
35 display_error(dpy, (xcb_generic_error_t*)ev);
40 switch (ev->response_type) {
41 case XCB_CREATE_NOTIFY:
43 xcb_create_notify_event_t *cev;
46 cev = (xcb_create_notify_event_t*)ev;
47 sc = display_screen_from_root(dpy, cev->parent);
49 screen_add_window(sc, cev->window);
52 case XCB_DESTROY_NOTIFY:
54 xcb_destroy_notify_event_t *dev;
58 dev = (xcb_destroy_notify_event_t*)ev;
59 sc = display_screen_from_root(dpy, dev->event);
61 w = screen_find_window(sc, dev->window);
63 screen_remove_window(sc, w);
64 printf("** refresh needed **\n");
68 case XCB_REPARENT_NOTIFY:
70 xcb_reparent_notify_event_t *rev;
74 rev = (xcb_reparent_notify_event_t*)ev;
75 sc = display_screen_from_root(dpy, rev->event);
77 w = screen_find_window(sc, rev->window);
78 if (rev->parent == sc->super.root)
79 screen_add_window(sc, rev->window);
82 screen_remove_window(sc, w);
88 xcb_map_notify_event_t *mev;
92 mev = (xcb_map_notify_event_t*)ev;
93 sc = display_screen_from_root(dpy, mev->event);
95 w = screen_find_window(sc, mev->window);
99 case XCB_UNMAP_NOTIFY:
101 xcb_unmap_notify_event_t *mev;
105 mev = (xcb_unmap_notify_event_t*)ev;
106 sc = display_screen_from_root(dpy, mev->event);
108 w = screen_find_window(sc, mev->window);
120 paint(d_display_t *dpy)
125 gettimeofday(&now, NULL);
127 for (it = list_top(dpy->screens); it; it = it->next) {
128 d_screen_t *sc = it->data;
130 if (time_compare(&sc->next_repaint, &now) <= 0)
131 sc->screen_paint(sc);
136 run(d_display_t *dpy)
144 struct timeval next, now, *wait;
150 for (it = list_top(dpy->screens); it; it = it->next) {
151 d_screen_t *sc = it->data;
152 if (sc->need_repaint &&
153 (!npaint || time_compare(&sc->next_repaint, &next) < 0))
155 next = sc->next_repaint;
160 gettimeofday(&now, 0);
163 /* wait forever, there is nothing that needs drawing */
165 else if (time_compare(&next, &now) > 0) {
166 /* wait until the next allowed redraw time */
167 time_difference(&next, &now, &next);
171 /* don't wait cuz a redraw is due now already */
178 FD_SET(dpy->fd, &fds);
180 r = select(dpy->fd+1, &fds, NULL, NULL, wait);
182 printf("select error\n");
184 printf("select timeout\n");
188 printf("select data\n");
189 /*if (FD_ISSET(dpy->fd, &fds))*/ {
194 if (xcb_connection_has_error(dpy->conn))
197 xcb_flush(dpy->conn);
202 setup_functions(d_display_t *dpy)
206 for (it = list_top(dpy->screens); it; it = it->next) {
207 d_screen_t *sc = it->data;
208 screen_setup_default_functions(sc);
210 /* these can be plugins.. */
216 cleanup_functions(d_display_t *dpy)
220 for (it = list_top(dpy->screens); it; it = it->next) {
221 d_screen_t *sc = it->data;
223 /* these can be plugins.. */
229 main(int argc, char **argv)
234 read_options(argc, argv, &opts);
236 dpy = display_open(NULL);
238 printf(_("Unable to connect to display\n"));
242 if (!dpy->composite.present) {
243 printf(_("no composite extension present on the display\n"));
247 if (!dpy->xfixes.present) {
248 printf(_("no xfixes extension present on the display\n"));
252 if (!dpy->damage.present) {
253 printf(_("no damage extension present on the display\n"));
257 if (!dpy->render.present) {
258 printf(_("no render extension present on the display\n"));
262 if (dpy->composite.major_version <= 0 && dpy->composite.minor_version < 3)
264 printf(_("composite extension does not support the overlay window"));
269 if (!display_claim_screens(dpy)) {
270 printf(_("found no screens to run on\n"));
275 setup_functions(dpy);
279 cleanup_functions(dpy);