From 482cefea6abc66d1488c7071aff1f656b318a592 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Sun, 2 Mar 2008 22:58:45 -0500 Subject: [PATCH] take the selecton for the screens that we will be managing, and skip the ones where a CM is already running --- Makefile | 4 +-- dcompmgr.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 12968a4..0409160 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ sources = $(wildcard *.c) objs = $(sources:.c=.o) -CFLAGS=$(shell pkg-config --cflags xcb-composite) -LIBS=$(shell pkg-config --libs xcb-composite) +CFLAGS=$(shell pkg-config --cflags xcb-composite glib-2.0) -ggdb +LIBS=$(shell pkg-config --libs xcb-composite glib-2.0) dcompmgr: $(objs) $(CC) -o $@ $^ $(LIBS) $(LDFLAGS) diff --git a/dcompmgr.c b/dcompmgr.c index 679284e..84d6a78 100644 --- a/dcompmgr.c +++ b/dcompmgr.c @@ -1,3 +1,101 @@ -int main(int argc, char **argv) +#include +#include +#include +#include + +#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() +{ + xcb_screen_iterator_t it; + int count, i; + d_screen_t sc; + + 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)) { + ++count; + screens = g_renew(d_screen_t, screens, count); + screens[count-1] = sc; + printf(_("managing screen %d\n"), sc.num); + } + } + return count; +} + +int +main(int argc, char **argv) +{ + conn = xcb_connect(NULL, NULL); + if (!conn) { + printf(_("Unable to connect to display\n")); + return 1; + } + setup = xcb_get_setup(conn); + + all_screens(); + + + xcb_disconnect(conn); + return 0; } -- 1.9.1