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