read all the available events at once
[dana/dcompmgr.git] / screen.c
index e2fdaaf..e238bc7 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -2,6 +2,7 @@
 #include "display.h"
 #include "list.h"
 #include "window.h"
+#include "render.h"
 #include "gettext.h"
 #include <string.h>
 #include <stdlib.h>
@@ -16,6 +17,7 @@
 
 static gboolean screen_init(d_screen_t *sc);
 static xcb_timestamp_t screen_timestamp(d_screen_t *sc);
+static void screen_add_existing_windows(d_screen_t *sc);
 
 gboolean
 screen_register(struct d_display *dpy, int num, d_screen_t *sc)
@@ -65,8 +67,10 @@ screen_register(struct d_display *dpy, int num, d_screen_t *sc)
         sck = xcb_get_selection_owner(sc->dpy->conn, arep->atom);
         srep = xcb_get_selection_owner_reply(sc->dpy->conn, sck, NULL);
         taken = srep->owner == w;
-        if (taken && screen_init(sc))
+        if (taken && screen_init(sc)) {
+            screen_add_existing_windows(sc);
             ret = TRUE;
+        }
         else {
             xcb_destroy_window(sc->dpy->conn, w);
             ret = FALSE;
@@ -126,6 +130,9 @@ screen_init(d_screen_t *sc)
     xcb_change_window_attributes(sc->dpy->conn, sc->super.root,
                                  XCB_CW_EVENT_MASK, &mask);
 
+    /* use the render backend */
+    sc->paint = render_paint_screen;
+
     sc->winhash = g_hash_table_new((GHashFunc)xcb_window_hash,
                                    (GCompareFunc)xcb_window_compare);
     sc->stacking = list_new();
@@ -152,6 +159,26 @@ screen_add_window(d_screen_t *sc, xcb_window_t wid)
     printf("screen added window 0x%x\n", w->id);
 }
 
+static void
+screen_add_existing_windows(d_screen_t *sc)
+{
+    xcb_query_tree_cookie_t ck;
+    xcb_query_tree_reply_t *rep;
+
+    ck = xcb_query_tree(sc->dpy->conn, sc->super.root);
+    rep = xcb_query_tree_reply(sc->dpy->conn, ck, NULL);
+    if (rep) {
+        xcb_window_iterator_t it;
+
+        printf("query\n");
+        it = xcb_query_tree_children_iterator(rep);
+        for (; it.rem; xcb_window_next(&it))
+            screen_add_window(sc, *it.data);
+
+        free(rep);
+    }
+}
+
 void
 screen_remove_window(d_screen_t *sc, struct d_window *w)
 {