windows are added and created on create/destroy/reparent
authorDana Jansens <danakj@orodu.net>
Mon, 3 Mar 2008 05:22:31 +0000 (00:22 -0500)
committerDana Jansens <danakj@orodu.net>
Mon, 3 Mar 2008 05:22:31 +0000 (00:22 -0500)
dcompmgr.c
screen.c
screen.h
window.c
window.h

index db14b2d..9126010 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <glib.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <xcb/xcb.h>
 
@@ -63,24 +64,59 @@ main(int argc, char **argv)
         return 0;
     }
 
-    while (ev = xcb_wait_for_event(conn)) {
-        printf("event\n");
-        switch (ev->response_type & ~0x80) {
-        case XCB_CREATE_WINDOW:
+    while ((ev = xcb_wait_for_event(conn))) {
+        printf("event %d\n", ev->response_type);
+
+        if (!ev->response_type) {
+            /* XXX handle error */
+            free(ev);
+            continue;
+        }
+
+        switch (ev->response_type) {
+        case XCB_CREATE_NOTIFY:
         {
-            xcb_create_notify_event_t *cev = (xcb_create_notify_event_t*)ev;
-            d_screen_t *sc = screen_from_root(screens, nscreens, cev->parent);
-            screen_add_window(sc, cev);
+            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_WINDOW:
+        case XCB_DESTROY_NOTIFY:
         {
-            xcb_destroy_notify_event_t *dev = (xcb_destroy_notify_event_t*)ev;
-            d_screen_t *sc = screen_from_root(screens, nscreens, dev->event);
-            d_window_t *w = screen_find_window(sc, dev->window);
-            screen_hide_window(sc, w);
+            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_REPARENT_WINDOW:
         default:
             break;
         }
index 684d6c5..5ffae1f 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -100,11 +100,13 @@ screen_init(d_screen_t *sc)
 }
 
 void
-screen_add_window(d_screen_t *sc, xcb_create_notify_event_t *cev)
+screen_add_window(d_screen_t *sc, xcb_window_t wid)
 {
     d_window_t *w;
 
-    w = window_new(cev->window, sc);
+    /* XXX xgetwindowattributes - size and tings */
+
+    w = window_new(wid, sc);
     g_hash_table_insert(sc->winhash, &w->id, w);
 
     printf("added window 0x%x\n", w->id);
@@ -125,16 +127,6 @@ screen_find_window(d_screen_t *sc, xcb_window_t id)
     return g_hash_table_lookup(sc->winhash, &id);
 }
 
-void
-screen_show_window(d_screen_t *sc, struct d_window *w)
-{
-}
-
-void
-screen_hide_window(d_screen_t *sc, struct d_window *w)
-{
-}
-
 static xcb_timestamp_t
 screen_timestamp(d_screen_t *sc)
 {
index 20daed3..4abfcb7 100644 (file)
--- a/screen.h
+++ b/screen.h
@@ -23,12 +23,9 @@ typedef struct d_screen {
 */
 gboolean screen_register(d_screen_t *sc);
 
-void screen_add_window(d_screen_t *sc, xcb_create_notify_event_t *cev);
+void screen_add_window(d_screen_t *sc, xcb_window_t wid);
 void screen_remove_window(d_screen_t *sc, struct d_window *w);
 
 struct d_window* screen_find_window(d_screen_t *sc, xcb_window_t id);
 
-void screen_show_window(d_screen_t *sc, struct d_window *w);
-void screen_hide_window(d_screen_t *sc, struct d_window *w);
-
 #endif
index 3e83634..269b60d 100644 (file)
--- a/window.c
+++ b/window.c
@@ -1,6 +1,9 @@
 #include "window.h"
 #include <glib.h>
 
+static void window_show(d_window_t *w);
+static void window_hide(d_window_t *w);
+
 d_window_t*
 window_new(xcb_window_t id, struct d_screen *sc)
 {
@@ -10,6 +13,11 @@ window_new(xcb_window_t id, struct d_screen *sc)
     w->id = id;
     w->ref = 1;
     w->sc = sc;
+
+    /* default functions */
+    w->show = window_show;
+    w->hide = window_hide;
+
     return w;
 }
 
@@ -26,3 +34,13 @@ window_unref(d_window_t *w)
         g_free(w);
     }
 }
+
+static void
+window_show(d_window_t *w)
+{
+}
+
+static void
+window_hide(d_window_t *w)
+{
+}
index 5b0d9ae..e03623b 100644 (file)
--- a/window.h
+++ b/window.h
@@ -9,6 +9,9 @@ typedef struct d_window {
     xcb_window_t     id;
     int              ref;
     struct d_screen *sc;
+
+    void (*show)(struct d_window *w);
+    void (*hide)(struct d_window *w);
 } d_window_t;
 
 d_window_t* window_new(xcb_window_t id, struct d_screen *sc);
@@ -16,4 +19,5 @@ d_window_t* window_new(xcb_window_t id, struct d_screen *sc);
 void window_ref(d_window_t *w);
 void window_unref(d_window_t *w);
 
+
 #endif