7 #include <xcb/composite.h>
9 #define ROOT_MASK (XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | \
10 XCB_EVENT_MASK_STRUCTURE_NOTIFY)
12 #define SELECTION_MASK (XCB_EVENT_MASK_STRUCTURE_NOTIFY | \
13 XCB_EVENT_MASK_PROPERTY_CHANGE)
15 static void screen_init(d_screen_t *sc);
16 static xcb_timestamp_t screen_timestamp(d_screen_t *sc);
19 screen_register(d_screen_t *sc)
23 xcb_intern_atom_cookie_t ack;
24 xcb_intern_atom_reply_t *arep;
25 xcb_get_selection_owner_cookie_t sck;
26 xcb_get_selection_owner_reply_t *srep;
30 w = xcb_generate_id(sc->conn);
31 event_mask = SELECTION_MASK;
32 xcb_create_window(sc->conn, XCB_COPY_FROM_PARENT, w, sc->super.root,
33 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_ONLY,
34 sc->super.root_visual, XCB_CW_EVENT_MASK, &event_mask);
36 name = g_strdup_printf("_NET_WM_CM_S%d", sc->num);
37 ack = xcb_intern_atom(sc->conn, FALSE, strlen(name), name);
38 arep = xcb_intern_atom_reply(sc->conn, ack, NULL);
41 sck = xcb_get_selection_owner(sc->conn, arep->atom);
42 srep = xcb_get_selection_owner_reply(sc->conn, sck, NULL);
43 taken = !!srep->owner;
46 printf(_("screen %d already has a composite manager, skipping\n"),
54 sc->selatom = arep->atom;
56 time = screen_timestamp(sc);
58 xcb_grab_server(sc->conn);
59 xcb_set_selection_owner(sc->conn, w, arep->atom, time);
60 sck = xcb_get_selection_owner(sc->conn, arep->atom);
61 srep = xcb_get_selection_owner_reply(sc->conn, sck, NULL);
62 taken = srep->owner == w;
68 xcb_destroy_window(sc->conn, w);
71 xcb_ungrab_server(sc->conn);
78 window_hash(xcb_window_t *w) { return *w; }
81 window_compare(xcb_window_t *w1, xcb_window_t *w2) { return *w1 == *w2; }
84 screen_init(d_screen_t *sc)
88 sc->winhash = g_hash_table_new((GHashFunc)window_hash,
89 (GCompareFunc)window_compare);
91 // xcb_composite_redirect_subwindows(sc->conn, sc->super.root,
92 // XCB_COMPOSITE_REDIRECT_MANUAL);
94 mask = SELECTION_MASK;
95 xcb_change_window_attributes(sc->conn, sc->selwin,
96 XCB_CW_EVENT_MASK, &mask);
98 xcb_change_window_attributes(sc->conn, sc->super.root,
99 XCB_CW_EVENT_MASK, &mask);
103 screen_add_window(d_screen_t *sc, xcb_create_notify_event_t *cev)
107 w = window_new(cev->window, sc);
108 g_hash_table_insert(sc->winhash, &w->id, w);
110 printf("added window 0x%x\n", w->id);
114 screen_remove_window(d_screen_t *sc, struct d_window *w)
116 printf("removed window 0x%x\n", w->id);
118 g_hash_table_remove(sc->winhash, &w->id);
123 screen_find_window(d_screen_t *sc, xcb_window_t id)
125 return g_hash_table_lookup(sc->winhash, &id);
129 screen_show_window(d_screen_t *sc, struct d_window *w)
134 screen_hide_window(d_screen_t *sc, struct d_window *w)
138 static xcb_timestamp_t
139 screen_timestamp(d_screen_t *sc)
141 xcb_void_cookie_t ck;
142 xcb_timestamp_t time;
144 ck = xcb_change_property(sc->conn, XCB_PROP_MODE_REPLACE, sc->selwin,
145 sc->selatom, sc->selatom, 32, 0, NULL);
148 xcb_generic_event_t *ev;
150 ev = xcb_wait_for_event(sc->conn);
152 printf(_("IO error\n"));
156 /* expect errors.. */
157 if (!ev->response_type) {
158 /* XXX handle error */
163 if (ev->response_type == XCB_PROPERTY_NOTIFY &&
164 ev->full_sequence == ck.sequence)
166 time = ((xcb_property_notify_event_t*)ev)->time;
171 printf("created timestamp %lu\n", (unsigned long) time);