add existing windows on startup
authorDana Jansens <danakj@orodu.net>
Tue, 4 Mar 2008 23:01:39 +0000 (18:01 -0500)
committerDana Jansens <danakj@orodu.net>
Tue, 4 Mar 2008 23:03:19 +0000 (18:03 -0500)
display.c
display.h
screen.c

index 3eefc56..650ef46 100644 (file)
--- a/display.c
+++ b/display.c
@@ -2,6 +2,7 @@
 #include "screen.h"
 #include "gettext.h"
 #include <stdlib.h>
+#include <assert.h>
 #include <string.h>
 #include <stdio.h>
 
@@ -307,8 +308,15 @@ display_screen_from_root(d_display_t *dpy, xcb_window_t root)
 {
     int i;
     for (i = 0; i < dpy->nscreens; ++i)
-        if (dpy->screens[i].super.root == root) return &dpy->screens[i];
-    g_assert_not_reached();
+        if (dpy->screens[i].super.root == root)
+            return &dpy->screens[i];
+    assert(0);
     return NULL;
 }
 
+struct d_screen*
+display_screen_n(d_display_t *dpy, int n)
+{
+    assert(n >= 0 && n < dpy->nscreens);
+    return &dpy->screens[n];
+}
index 41bc4e0..ed0e608 100644 (file)
--- a/display.h
+++ b/display.h
@@ -59,6 +59,7 @@ void display_unref(d_display_t *dpy);
 int display_claim_screens(d_display_t *dpy);
 
 struct d_screen* display_screen_from_root(d_display_t *dpy, xcb_window_t root);
+struct d_screen* display_screen_n(d_display_t *dpy, int n);
 
 void display_error(d_display_t *dpy, xcb_generic_error_t *ev);
 
index e2fdaaf..0c74e72 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -16,6 +16,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 +66,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;
@@ -152,6 +155,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)
 {