-int main(int argc, char **argv)
+#include "screen.h"
+#include "window.h"
+#include "display.h"
+#include "gettext.h"
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <xcb/xcb.h>
+
+typedef struct {
+ int foo;
+} d_options_t;
+
+static gint
+all_screens(d_display_t *dpy, d_screen_t **list)
{
+ static const xcb_setup_t *setup;
+ xcb_screen_iterator_t it;
+ int count, i;
+ d_screen_t sc;
+
+ setup = xcb_get_setup(dpy->conn);
+
+ count = i = 0;
+ for (it = xcb_setup_roots_iterator(setup); it.rem; xcb_screen_next(&it)) {
+ sc.super = *it.data;
+ sc.dpy = dpy;
+ sc.num = i++;
+ if (screen_register(&sc)) {
+ ++count;
+ *list = realloc(*list, sizeof(d_screen_t)*count);
+ (*list)[count-1] = sc;
+ printf(_("managing screen %d\n"), sc.num);
+ }
+ }
+ return count;
+}
+
+static d_screen_t*
+screen_from_root(d_screen_t *list, int n, xcb_window_t root)
+{
+ int i;
+ for (i = 0; i < n; ++i)
+ if (list->super.root == root) return &list[i];
+ g_assert_not_reached();
+ return NULL;
+}
+
+static
+void read_options(int argc, char **argv, d_options_t *opts)
+{
+ opts->foo = argc && argv;
+}
+
+int
+main(int argc, char **argv)
+{
+ d_display_t *dpy;
+ d_screen_t *screens = NULL;
+ int nscreens;
+ xcb_generic_event_t *ev;
+ d_options_t opts;
+
+ read_options(argc, argv, &opts);
+
+ dpy = display_open(NULL);
+ if (!dpy) {
+ printf(_("Unable to connect to display\n"));
+ return 1;
+ }
+
+ nscreens = all_screens(dpy, &screens);
+ if (nscreens < 1) {
+ printf(_("found no screens to run on\n"));
+ display_unref(dpy);
+ return 0;
+ }
+
+ while ((ev = xcb_wait_for_event(dpy->conn))) {
+ printf("event %d\n", ev->response_type);
+
+ if (!ev->response_type) {
+ display_error(dpy, (xcb_generic_error_t*)ev);
+ free(ev);
+ continue;
+ }
+
+ switch (ev->response_type) {
+ case XCB_CREATE_NOTIFY:
+ {
+ xcb_create_notify_event_t *cev;
+ d_screen_t *sc;
+
+ cev = (xcb_create_notify_event_t*)ev;
+ sc = screen_from_root(screens, nscreens, cev->parent);
+ if (!sc) break;
+ screen_add_window(sc, cev->window);
+ break;
+ }
+ case XCB_DESTROY_NOTIFY:
+ {
+ xcb_destroy_notify_event_t *dev;
+ d_screen_t *sc;
+ d_window_t *w;
+
+ dev = (xcb_destroy_notify_event_t*)ev;
+ sc = screen_from_root(screens, nscreens, dev->event);
+ if (!sc) break;
+ w = screen_find_window(sc, dev->window);
+ w->hide(w);
+ screen_remove_window(sc, w);
+ break;
+ }
+ case XCB_REPARENT_NOTIFY:
+ {
+ xcb_reparent_notify_event_t *rev;
+ d_screen_t *sc;
+ d_window_t *w;
+
+ rev = (xcb_reparent_notify_event_t*)ev;
+ sc = screen_from_root(screens, nscreens, rev->event);
+ if (!sc) break;
+ w = screen_find_window(sc, rev->window);
+ if (rev->parent == sc->super.root)
+ screen_add_window(sc, rev->window);
+ else {
+ w->hide(w);
+ screen_remove_window(sc, w);
+ }
+ break;
+ }
+ case XCB_MAP_NOTIFY:
+ {
+ xcb_map_notify_event_t *mev;
+ d_screen_t *sc;
+ d_window_t *w;
+
+ mev = (xcb_map_notify_event_t*)ev;
+ sc = screen_from_root(screens, nscreens, mev->event);
+ if (!sc) break;
+ w = screen_find_window(sc, mev->window);
+ window_show(w);
+ break;
+ }
+ case XCB_UNMAP_NOTIFY:
+ {
+ xcb_unmap_notify_event_t *mev;
+ d_screen_t *sc;
+ d_window_t *w;
+
+ mev = (xcb_unmap_notify_event_t*)ev;
+ sc = screen_from_root(screens, nscreens, mev->event);
+ if (!sc) break;
+ w = screen_find_window(sc, mev->window);
+ window_hide(w);
+ break;
+ }
+ default:
+ break;
+ }
+ free(ev);
+ }
+
+ display_unref(dpy);
+ return 0;
}