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)
143 FD_SET(dpy->fd, &fds);
144 max = MAX(max, dpy->fd);
150 struct timeval next, now, *wait;
155 for (it = list_top(dpy->screens); it; it = it->next) {
156 d_screen_t *sc = it->data;
157 if (sc->need_repaint &&
158 (!npaint || time_compare(&sc->next_repaint, &next) < 0))
160 next = sc->next_repaint;
165 gettimeofday(&now, 0);
167 printf("* loop paint %d *\n", npaint);
170 /* wait forever, there is nothing that needs drawing */
172 else if (time_compare(&next, &now) > 0) {
173 /* wait until the next allowed redraw time */
174 time_difference(&next, &now, &next);
178 /* don't wait cuz a redraw is due now already */
184 r = select(max+1, &fds, NULL, NULL, wait);
186 printf("select error\n");
188 printf("select timeout\n");
192 printf("select data\n");
193 /*if (FD_ISSET(dpy->fd, &fds))*/ {
198 if (xcb_connection_has_error(dpy->conn))
204 setup_functions(d_display_t *dpy)
208 for (it = list_top(dpy->screens); it; it = it->next) {
209 d_screen_t *sc = it->data;
210 screen_setup_default_functions(sc);
212 /* these can be plugins.. */
218 cleanup_functions(d_display_t *dpy)
222 for (it = list_top(dpy->screens); it; it = it->next) {
223 d_screen_t *sc = it->data;
225 /* these can be plugins.. */
231 main(int argc, char **argv)
236 read_options(argc, argv, &opts);
238 dpy = display_open(NULL);
240 printf(_("Unable to connect to display\n"));
244 if (!dpy->composite.present) {
245 printf(_("no composite extension present on the display\n"));
249 if (!dpy->xfixes.present) {
250 printf(_("no xfixes extension present on the display\n"));
254 if (!dpy->damage.present) {
255 printf(_("no damage extension present on the display\n"));
259 if (!dpy->render.present) {
260 printf(_("no render extension present on the display\n"));
264 if (dpy->composite.major_version <= 0 && dpy->composite.minor_version < 3)
266 printf(_("composite extension does not support the overlay window"));
271 if (!display_claim_screens(dpy)) {
272 printf(_("found no screens to run on\n"));
277 setup_functions(dpy);
281 cleanup_functions(dpy);