diff --git a/Makefile b/Makefile
index 8b0f0aa..e71f41d 100644
--- a/Makefile
+++ b/Makefile
@@ -20,8 +20,8 @@ V = 0.0
XCB_INCS = -I/usr/X11R6/include
XCB_LIBS = -L/usr/X11R6/lib -lxcb
-HDR = err.h
-OBJ = err.o main.o
+HDR = err.h wm.h
+OBJ = err.o main.o wm.o
SRC = ${OBJ:.o=.c}
DIST_FILES = COPYING Makefile THANKS ${HDR} ${SRC}
diff --git a/main.c b/main.c
index c1c1254..30d000d 100644
--- a/main.c
+++ b/main.c
@@ -13,30 +13,13 @@
* .
*/
+#include
#include
#include
#include
#include "err.h"
-
-static struct {
- xcb_connection_t *conn;
-} wm;
-
-static void
-wm_setup(void)
-{
-}
-
-static void
-wm_print_info(void)
-{
-}
-
-static void
-wm_teardown(void)
-{
-}
+#include "wm.h"
static void
usage(void)
@@ -48,12 +31,14 @@ usage(void)
int
main(int argc, char *argv[])
{
+ struct wm wm;
+
if (argc != 1)
usage();
- wm_setup();
- wm_print_info();
- wm_teardown();
+ wm_setup(&wm);
+ wm_print_screen_info(stderr, &wm);
+ wm_teardown(&wm);
return 0;
}
diff --git a/wm.c b/wm.c
new file mode 100644
index 0000000..c95d129
--- /dev/null
+++ b/wm.c
@@ -0,0 +1,63 @@
+/*
+ * orcawm - XCB window manager
+ *
+ * Written in 2020 by Lucas
+ *
+ * To the extent possible under law, the author(s) have dedicated all
+ * copyright and related and neighboring rights to this software to the
+ * public domain worldwide. This software is distributed without any
+ * warranty.
+ *
+ * You should have received a copy of the CC0 Public Domain Dedication
+ * along with this software. If not, see
+ * .
+ */
+
+#include
+#include
+
+#include "err.h"
+#include "wm.h"
+
+static int
+detect_other_window_manager(const struct wm *wm)
+{
+ return 0;
+}
+
+void
+wm_setup(struct wm *wm)
+{
+ wm->conn = xcb_connect(NULL, &wm->screen);
+ if (xcb_connection_has_error(wm->conn))
+ errx(1, "Error connecting to X server");
+ if (detect_other_window_manager(wm))
+ errx(1, "Another window manager is already running");
+}
+
+void
+wm_print_screen_info(FILE *fp, const struct wm *wm)
+{
+ const xcb_setup_t *setup;
+ xcb_screen_t *screen;
+ xcb_screen_iterator_t iter;
+ int i;
+
+ setup = xcb_get_setup(wm->conn);
+ iter = xcb_setup_roots_iterator(setup);
+ for (i = 0; i < wm->screen; i++)
+ xcb_screen_next(&iter);
+
+ if ((screen = iter.data) != NULL)
+ fprintf(fp, "[%d] %08" PRIx32 " %" PRIu16 "x%" PRIu16 "\n",
+ wm->screen, screen->root, screen->width_in_pixels,
+ screen->height_in_pixels);
+ else
+ fprintf(fp, "[%d] NO_DATA\n", wm->screen);
+}
+
+void
+wm_teardown(struct wm *wm)
+{
+ xcb_disconnect(wm->conn);
+}
diff --git a/wm.h b/wm.h
new file mode 100644
index 0000000..13d2c7f
--- /dev/null
+++ b/wm.h
@@ -0,0 +1,25 @@
+/*
+ * orcawm - XCB window manager
+ *
+ * Written in 2020 by Lucas
+ *
+ * To the extent possible under law, the author(s) have dedicated all
+ * copyright and related and neighboring rights to this software to the
+ * public domain worldwide. This software is distributed without any
+ * warranty.
+ *
+ * You should have received a copy of the CC0 Public Domain Dedication
+ * along with this software. If not, see
+ * .
+ */
+
+#include
+
+struct wm {
+ xcb_connection_t *conn;
+ int screen;
+};
+
+void wm_setup(struct wm *);
+void wm_print_screen_info(FILE *, const struct wm *);
+void wm_teardown(struct wm *);