+#include "screen.h"
+#include "gettext.h"
+#include <string.h>
+#include <stdio.h>
+
+gboolean
+screen_register(xcb_connection_t *conn, d_screen_t *sc)
+{
+ char *name;
+ int len, s;
+ xcb_window_t w;
+ xcb_intern_atom_cookie_t ack;
+ xcb_intern_atom_reply_t *arep;
+ xcb_get_selection_owner_cookie_t sck;
+ xcb_get_selection_owner_reply_t *srep;
+ gboolean taken;
+
+ w = xcb_generate_id(conn);
+ xcb_create_window(conn, XCB_COPY_FROM_PARENT, w, sc->super.root,
+ 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_ONLY,
+ sc->super.root_visual, 0, NULL);
+
+ name = g_strdup_printf("_NET_WM_CM_S%d", sc->num);
+ ack = xcb_intern_atom(conn, FALSE, strlen(name), name);
+ arep = xcb_intern_atom_reply(conn, ack, NULL);
+ g_free(name);
+
+ sck = xcb_get_selection_owner(conn, arep->atom);
+ srep = xcb_get_selection_owner_reply(conn, sck, NULL);
+ taken = !!srep->owner;
+ free(srep);
+ if (taken) {
+ printf(_("screen %d already has a composite manager, skipping\n"),
+ sc->num);
+ return FALSE;
+ }
+
+ xcb_set_selection_owner(conn, w, arep->atom, XCB_CURRENT_TIME);
+ sck = xcb_get_selection_owner(conn, arep->atom);
+ srep = xcb_get_selection_owner_reply(conn, sck, NULL);
+ taken = srep->owner == w;
+ if (taken) {
+ sc->selwin = w;
+ return TRUE;
+ }
+ else {
+ xcb_destroy_window(conn, w);
+ return FALSE;
+ }
+}