read all the available events at once
[dana/dcompmgr.git] / window.c
index 269b60d..83efdf3 100644 (file)
--- a/window.c
+++ b/window.c
@@ -1,22 +1,33 @@
 #include "window.h"
-#include <glib.h>
+#include "screen.h"
+#include <stdlib.h>
+#include <stdio.h>
 
 static void window_show(d_window_t *w);
 static void window_hide(d_window_t *w);
 
+static void window_become_zombie(d_window_t *w);
+
 d_window_t*
 window_new(xcb_window_t id, struct d_screen *sc)
 {
     d_window_t *w;
 
-    w = g_new(d_window_t, 1);
+    w = malloc(sizeof(d_window_t));
     w->id = id;
     w->ref = 1;
     w->sc = sc;
+    w->mapped = FALSE;
+    w->zombie = FALSE;
 
     /* default functions */
     w->show = window_show;
     w->hide = window_hide;
+    w->become_zombie = window_become_zombie;
+
+    screen_stacking_add(sc, w);
+
+    printf("new window 0x%x\n", w->id);
 
     return w;
 }
@@ -31,16 +42,35 @@ void
 window_unref(d_window_t *w)
 {
     if (w && --w->ref == 0) {
-        g_free(w);
+        screen_stacking_remove(w->sc, w);
+        free(w);
     }
 }
 
 static void
 window_show(d_window_t *w)
 {
+    if (w->mapped) return;
+
+    printf("show window 0x%x\n", w->id);
+
+    w->mapped = TRUE;
 }
 
 static void
 window_hide(d_window_t *w)
 {
+    if (!w->mapped) return;
+
+    printf("hide window 0x%x\n", w->id);
+
+    w->mapped = FALSE;
+}
+
+static void
+window_become_zombie(d_window_t *w)
+{
+    if (w->zombie) return;
+
+    w->zombie = TRUE;
 }