sc = display_screen_from_root(dpy, mev->event);
if (!sc) break;
w = screen_find_window(sc, mev->window);
- window_show(w);
+ w->show(w);
break;
}
case XCB_UNMAP_NOTIFY:
sc = display_screen_from_root(dpy, mev->event);
if (!sc) break;
w = screen_find_window(sc, mev->window);
- window_hide(w);
+ w->hide(w);
break;
}
default:
if (!move->prev) list->top = move;
}
+void
+list_remove(d_list_t *list, void *data)
+{
+ d_list_it_t *it = list_find(list, data);
+ if (it) list_delete_link(list, it);
+}
+
int
list_length(d_list_t *list)
{
it = it->next;
return it;
}
+
+d_list_it_t*
+list_find(d_list_t *list, void *data)
+{
+ d_list_it_t *it;
+
+ for (it = list->top; it; it = it->next)
+ if (it->data == data) return it;
+ return NULL;
+}
d_list_it_t* list_prepend(d_list_t *list, void *data);
void list_delete_link(d_list_t *list, d_list_it_t *pos);
void list_move_before(d_list_t *list, d_list_it_t *move, d_list_it_t *before);
+void list_remove(d_list_t *list, void *data);
int list_length(d_list_t *list);
d_list_it_t* list_top(d_list_t *list);
d_list_it_t* list_bottom(d_list_t *list);
d_list_it_t* list_nth(d_list_t *list, int n);
+d_list_it_t* list_find(d_list_t *list, void *data);
#endif
printf("screen removed window 0x%x\n", w->id);
g_hash_table_remove(sc->winhash, &w->id);
+ w->become_zombie(w);
window_unref(w);
}
printf("created timestamp %lu\n", (unsigned long) time);
return time;
}
+
+void
+screen_stacking_add(d_screen_t *sc, struct d_window *w)
+{
+ list_prepend(sc->stacking, w);
+}
+
+void
+screen_stacking_remove(d_screen_t *sc, struct d_window *w)
+{
+ list_remove(sc->stacking, w);
+}
struct d_window* screen_find_window(d_screen_t *sc, xcb_window_t id);
+void screen_stacking_add(d_screen_t *sc, struct d_window *w);
+void screen_stacking_remove(d_screen_t *sc, struct d_window *w);
+
#endif
#include "window.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)
{
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);
window_unref(d_window_t *w)
{
if (w && --w->ref == 0) {
+ screen_stacking_remove(w->sc, w);
free(w);
}
}
-void
+static void
window_show(d_window_t *w)
{
if (w->mapped) return;
w->mapped = TRUE;
}
-void
+static void
window_hide(d_window_t *w)
{
if (!w->mapped) return;
w->mapped = FALSE;
}
+
+static void
+window_become_zombie(d_window_t *w)
+{
+ if (w->zombie) return;
+
+ w->zombie = TRUE;
+}
struct d_screen *sc;
gboolean mapped;
+ gboolean zombie;
void (*show)(struct d_window *w);
void (*hide)(struct d_window *w);
+ void (*become_zombie)(struct d_window *w);
} d_window_t;
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);
-void window_show(d_window_t *w);
-void window_hide(d_window_t *w);
-
#endif