+#include "screen.h"
+#include "gettext.h"
+
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <xcb/xcb.h>
-#define _(a) (a)
-
-/* inherits from xcb_screen_t */
-typedef struct {
- xcb_screen_t super;
- int num;
- xcb_window_t selwin; /* for the selection */
-} d_screen_t;
-
-static xcb_connection_t *conn;
-static const xcb_setup_t *setup;
static d_screen_t *screens = NULL;
-static gboolean
-register_screen (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;
- }
-}
-
static gint
-all_screens()
+all_screens(xcb_connection_t *conn)
{
+ static const xcb_setup_t *setup;
xcb_screen_iterator_t it;
int count, i;
d_screen_t sc;
+ setup = xcb_get_setup(conn);
+
count = i = 0;
for (it = xcb_setup_roots_iterator(setup); it.rem; xcb_screen_next(&it)) {
sc.super = *it.data;
sc.num = i++;
- if (register_screen(&sc)) {
+ if (screen_register(conn, &sc)) {
++count;
screens = g_renew(d_screen_t, screens, count);
screens[count-1] = sc;
int
main(int argc, char **argv)
{
+ xcb_connection_t *conn;
+
conn = xcb_connect(NULL, NULL);
if (!conn) {
printf(_("Unable to connect to display\n"));
return 1;
}
- setup = xcb_get_setup(conn);
- all_screens();
+ all_screens(conn);
xcb_disconnect(conn);
--- /dev/null
+#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;
+ }
+}