f268ede045d19fd8b98fc7b9722de7eb246fd6a1
[dana/dcompmgr.git] / screen.c
1 #include "screen.h"
2 #include "gettext.h"
3 #include <string.h>
4 #include <stdio.h>
5
6 #define ROOT_MASK (XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY)
7
8 gboolean
9 screen_register(xcb_connection_t *conn, d_screen_t *sc)
10 {
11     char *name;
12     int len, s;
13     xcb_window_t w;
14     xcb_intern_atom_cookie_t ack;
15     xcb_intern_atom_reply_t *arep;
16     xcb_get_selection_owner_cookie_t sck;
17     xcb_get_selection_owner_reply_t *srep;
18     gboolean taken;
19
20     w = xcb_generate_id(conn);
21     xcb_create_window(conn, XCB_COPY_FROM_PARENT, w, sc->super.root,
22                       0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_ONLY,
23                       sc->super.root_visual, 0, NULL);
24
25     name = g_strdup_printf("_NET_WM_CM_S%d", sc->num);
26     ack = xcb_intern_atom(conn, FALSE, strlen(name), name);
27     arep = xcb_intern_atom_reply(conn, ack, NULL);
28     g_free(name);
29
30     sck = xcb_get_selection_owner(conn, arep->atom);
31     srep = xcb_get_selection_owner_reply(conn, sck, NULL);
32     taken = !!srep->owner;
33     free(srep);
34     if (taken) {
35         printf(_("screen %d already has a composite manager, skipping\n"),
36                sc->num);
37         return FALSE;
38     }
39
40     xcb_set_selection_owner(conn, w, arep->atom, XCB_CURRENT_TIME);
41     sck = xcb_get_selection_owner(conn, arep->atom);
42     srep = xcb_get_selection_owner_reply(conn, sck, NULL);
43     taken = srep->owner == w;
44     if (taken) {
45         sc->selwin = w;
46         return TRUE;
47     }
48     else {
49         xcb_destroy_window(conn, w);
50         return FALSE;
51     }
52 }
53
54 void screen_listen(xcb_connection_t *conn, d_screen_t *sc)
55 {
56     const uint32_t mask = ROOT_MASK;
57     xcb_change_window_attributes(conn, sc->super.root,
58                                  XCB_CW_EVENT_MASK, &mask);
59 }