split things off into screen.c/h
authorDana Jansens <danakj@orodu.net>
Mon, 3 Mar 2008 04:05:58 +0000 (23:05 -0500)
committerDana Jansens <danakj@orodu.net>
Mon, 3 Mar 2008 04:05:58 +0000 (23:05 -0500)
Makefile
dcompmgr.c
gettext.h [new file with mode: 0644]
screen.c [new file with mode: 0644]
screen.h [new file with mode: 0644]

index 0409160..2be3a3a 100644 (file)
--- 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)
index 84d6a78..9008a16 100644 (file)
@@ -1,79 +1,28 @@
+#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;
@@ -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 (file)
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 (file)
index 0000000..e223467
--- /dev/null
+++ b/screen.c
@@ -0,0 +1,50 @@
+#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;
+    }
+}
diff --git a/screen.h b/screen.h
new file mode 100644 (file)
index 0000000..8bf0902
--- /dev/null
+++ b/screen.h
@@ -0,0 +1,16 @@
+#ifndef dc__screen_h
+#define dc__screen_h
+
+#include <xcb/xcb.h>
+#include <glib.h>
+
+/* 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