read all the available events at once
[dana/dcompmgr.git] / dcompmgr.c
index c03393c..40d983a 100644 (file)
@@ -25,89 +25,90 @@ event(d_display_t *dpy)
 {
     xcb_generic_event_t *ev;
 
-    ev = xcb_poll_for_event(dpy->conn);
-    printf("event %d\n", ev->response_type);
+    while ((ev = xcb_poll_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);
-        return;
-    }
+        if (!ev->response_type) {
+            display_error(dpy, (xcb_generic_error_t*)ev);
+            free(ev);
+            return;
+        }
 
-    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 = display_screen_from_root(dpy, 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 = display_screen_from_root(dpy, 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 = display_screen_from_root(dpy, 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 {
+        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 = display_screen_from_root(dpy, 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 = display_screen_from_root(dpy, dev->event);
+            if (!sc) break;
+            w = screen_find_window(sc, dev->window);
             w->hide(w);
             screen_remove_window(sc, w);
+            break;
         }
-        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 = display_screen_from_root(dpy, mev->event);
-        if (!sc) break;
-        w = screen_find_window(sc, mev->window);
-        w->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 = display_screen_from_root(dpy, mev->event);
-        if (!sc) break;
-        w = screen_find_window(sc, mev->window);
-        w->hide(w);
-        break;
-    }
-    default:
-        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 = display_screen_from_root(dpy, 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 = display_screen_from_root(dpy, mev->event);
+            if (!sc) break;
+            w = screen_find_window(sc, mev->window);
+            w->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 = display_screen_from_root(dpy, mev->event);
+            if (!sc) break;
+            w = screen_find_window(sc, mev->window);
+            w->hide(w);
+            break;
+        }
+        default:
+            break;
+        }
+        free(ev);
     }
-    free(ev);
 }
 
 static void