read all the available events at once
[dana/dcompmgr.git] / window.c
1 #include "window.h"
2 #include "screen.h"
3 #include <stdlib.h>
4 #include <stdio.h>
5
6 static void window_show(d_window_t *w);
7 static void window_hide(d_window_t *w);
8
9 static void window_become_zombie(d_window_t *w);
10
11 d_window_t*
12 window_new(xcb_window_t id, struct d_screen *sc)
13 {
14     d_window_t *w;
15
16     w = malloc(sizeof(d_window_t));
17     w->id = id;
18     w->ref = 1;
19     w->sc = sc;
20     w->mapped = FALSE;
21     w->zombie = FALSE;
22
23     /* default functions */
24     w->show = window_show;
25     w->hide = window_hide;
26     w->become_zombie = window_become_zombie;
27
28     screen_stacking_add(sc, w);
29
30     printf("new window 0x%x\n", w->id);
31
32     return w;
33 }
34
35 void
36 window_ref(d_window_t *w)
37 {
38     ++w->ref;
39 }
40
41 void
42 window_unref(d_window_t *w)
43 {
44     if (w && --w->ref == 0) {
45         screen_stacking_remove(w->sc, w);
46         free(w);
47     }
48 }
49
50 static void
51 window_show(d_window_t *w)
52 {
53     if (w->mapped) return;
54
55     printf("show window 0x%x\n", w->id);
56
57     w->mapped = TRUE;
58 }
59
60 static void
61 window_hide(d_window_t *w)
62 {
63     if (!w->mapped) return;
64
65     printf("hide window 0x%x\n", w->id);
66
67     w->mapped = FALSE;
68 }
69
70 static void
71 window_become_zombie(d_window_t *w)
72 {
73     if (w->zombie) return;
74
75     w->zombie = TRUE;
76 }