From b47f752af3108325141fbe603fbc66424ec62296 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Sun, 2 Mar 2008 23:05:58 -0500 Subject: [PATCH] split things off into screen.c/h --- Makefile | 5 +++-- dcompmgr.c | 72 ++++++++++---------------------------------------------------- gettext.h | 7 ++++++ screen.c | 50 +++++++++++++++++++++++++++++++++++++++++++ screen.h | 16 ++++++++++++++ 5 files changed, 87 insertions(+), 63 deletions(-) create mode 100644 gettext.h create mode 100644 screen.c create mode 100644 screen.h diff --git a/Makefile b/Makefile index 0409160..2be3a3a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ sources = $(wildcard *.c) objs = $(sources:.c=.o) +headers = $(wildcard *.h) CFLAGS=$(shell pkg-config --cflags xcb-composite glib-2.0) -ggdb LIBS=$(shell pkg-config --libs xcb-composite glib-2.0) @@ -7,5 +8,5 @@ LIBS=$(shell pkg-config --libs xcb-composite glib-2.0) dcompmgr: $(objs) $(CC) -o $@ $^ $(LIBS) $(LDFLAGS) -.c.o: - $(CC) -c -o $@ $^ $(CFLAGS) +%.o: %.c $(headers) + $(CC) -c -o $@ $< $(CFLAGS) diff --git a/dcompmgr.c b/dcompmgr.c index 84d6a78..9008a16 100644 --- a/dcompmgr.c +++ b/dcompmgr.c @@ -1,79 +1,28 @@ +#include "screen.h" +#include "gettext.h" + #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() +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; @@ -86,14 +35,15 @@ all_screens() 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); diff --git a/gettext.h b/gettext.h new file mode 100644 index 0000000..679a2d2 --- /dev/null +++ b/gettext.h @@ -0,0 +1,7 @@ +#ifndef dc__gettext_h +#define dc__gettext_h + +/* stub for now.. */ +#define _(a) (a) + +#endif diff --git a/screen.c b/screen.c new file mode 100644 index 0000000..e223467 --- /dev/null +++ b/screen.c @@ -0,0 +1,50 @@ +#include "screen.h" +#include "gettext.h" +#include +#include + +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; + } +} diff --git a/screen.h b/screen.h new file mode 100644 index 0000000..8bf0902 --- /dev/null +++ b/screen.h @@ -0,0 +1,16 @@ +#ifndef dc__screen_h +#define dc__screen_h + +#include +#include + +/* inherits from xcb_screen_t */ +typedef struct { + xcb_screen_t super; + int num; + xcb_window_t selwin; /* for the selection */ +} d_screen_t; + +gboolean screen_register(xcb_connection_t *conn, d_screen_t *sc); + +#endif -- 1.9.1