8 #include <xcb/composite.h>
10 #define ROOT_MASK (XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | \
11 XCB_EVENT_MASK_STRUCTURE_NOTIFY)
13 #define SELECTION_MASK (XCB_EVENT_MASK_STRUCTURE_NOTIFY | \
14 XCB_EVENT_MASK_PROPERTY_CHANGE)
16 static void screen_init(d_screen_t *sc);
17 static xcb_timestamp_t screen_timestamp(d_screen_t *sc);
20 screen_register(d_screen_t *sc)
24 xcb_intern_atom_cookie_t ack;
25 xcb_intern_atom_reply_t *arep;
26 xcb_get_selection_owner_cookie_t sck;
27 xcb_get_selection_owner_reply_t *srep;
31 w = xcb_generate_id(sc->conn);
32 event_mask = SELECTION_MASK;
33 xcb_create_window(sc->conn, XCB_COPY_FROM_PARENT, w, sc->super.root,
34 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_ONLY,
35 sc->super.root_visual, XCB_CW_EVENT_MASK, &event_mask);
37 name = g_strdup_printf("_NET_WM_CM_S%d", sc->num);
38 ack = xcb_intern_atom(sc->conn, FALSE, strlen(name), name);
39 arep = xcb_intern_atom_reply(sc->conn, ack, NULL);
42 sck = xcb_get_selection_owner(sc->conn, arep->atom);
43 srep = xcb_get_selection_owner_reply(sc->conn, sck, NULL);
44 taken = !!srep->owner;
47 printf(_("screen %d already has a composite manager, skipping\n"),
55 sc->selatom = arep->atom;
57 time = screen_timestamp(sc);
59 xcb_grab_server(sc->conn);
60 xcb_set_selection_owner(sc->conn, w, arep->atom, time);
61 sck = xcb_get_selection_owner(sc->conn, arep->atom);
62 srep = xcb_get_selection_owner_reply(sc->conn, sck, NULL);
63 taken = srep->owner == w;
69 xcb_destroy_window(sc->conn, w);
72 xcb_ungrab_server(sc->conn);
79 window_hash(xcb_window_t *w) { return *w; }
82 window_compare(xcb_window_t *w1, xcb_window_t *w2) { return *w1 == *w2; }
85 screen_init(d_screen_t *sc)
89 sc->winhash = g_hash_table_new((GHashFunc)window_hash,
90 (GCompareFunc)window_compare);
92 // xcb_composite_redirect_subwindows(sc->conn, sc->super.root,
93 // XCB_COMPOSITE_REDIRECT_MANUAL);
95 mask = SELECTION_MASK;
96 xcb_change_window_attributes(sc->conn, sc->selwin,
97 XCB_CW_EVENT_MASK, &mask);
99 xcb_change_window_attributes(sc->conn, sc->super.root,
100 XCB_CW_EVENT_MASK, &mask);
104 screen_add_window(d_screen_t *sc, xcb_window_t wid)
108 /* XXX xgetwindowattributes - size and tings */
110 w = window_new(wid, sc);
111 g_hash_table_insert(sc->winhash, &w->id, w);
113 printf("added window 0x%x\n", w->id);
117 screen_remove_window(d_screen_t *sc, struct d_window *w)
119 printf("removed window 0x%x\n", w->id);
121 g_hash_table_remove(sc->winhash, &w->id);
126 screen_find_window(d_screen_t *sc, xcb_window_t id)
128 return g_hash_table_lookup(sc->winhash, &id);
131 static xcb_timestamp_t
132 screen_timestamp(d_screen_t *sc)
134 xcb_void_cookie_t ck;
135 xcb_timestamp_t time;
137 ck = xcb_change_property(sc->conn, XCB_PROP_MODE_REPLACE, sc->selwin,
138 sc->selatom, sc->selatom, 32, 0, NULL);
141 xcb_generic_event_t *ev;
143 ev = xcb_wait_for_event(sc->conn);
145 printf(_("IO error\n"));
149 /* expect errors.. */
150 if (!ev->response_type) {
151 error(sc->conn, (xcb_generic_error_t*)ev);
156 if (ev->response_type == XCB_PROPERTY_NOTIFY &&
157 ev->full_sequence == ck.sequence)
159 time = ((xcb_property_notify_event_t*)ev)->time;
164 printf("created timestamp %lu\n", (unsigned long) time);