summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/xserver.c67
-rw-r--r--src/xserver.h21
3 files changed, 89 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index a65aa86..7fff59f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,5 @@
SUBDIRS = libvmon
bin_PROGRAMS = vwm
-vwm_SOURCES = clickety.c composite.c context.c desktop.c key.c launch.c logo.c overlay.c screen.c vwm.c window.c xevent.c xwindow.c clickety.h composite.h context.h desktop.h key.h launch.h list.h logo.h overlay.h screen.h util.h vwm.h window.h xevent.h xwindow.h colors.def launchers.def
+vwm_SOURCES = clickety.c composite.c context.c desktop.c key.c launch.c logo.c overlay.c screen.c vwm.c window.c xevent.c xserver.c xwindow.c clickety.h composite.h context.h desktop.h key.h launch.h list.h logo.h overlay.h screen.h util.h vwm.h window.h xevent.h xserver.h xwindow.h colors.def launchers.def
vwm_LDADD = @VWM_LIBS@ libvmon/libvmon.a
vwm_CPPFLAGS = @VWM_CFLAGS@
diff --git a/src/xserver.c b/src/xserver.c
new file mode 100644
index 0000000..114a924
--- /dev/null
+++ b/src/xserver.c
@@ -0,0 +1,67 @@
+#include <X11/Xlib.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "util.h"
+#include "xserver.h"
+
+/* xserver context shared by vwm and vmon.
+ * This is the X part monitor.c interfaces with, so monitor.c can avoid depending
+ * on vwm_t which won't exist in the vmon tool.
+ */
+
+static int errhandler(Display *display, XErrorEvent *err)
+{
+ /* TODO */
+ return 1;
+}
+
+/* open the X display server, initializing *xserver on success. */
+vwm_xserver_t * vwm_xserver_open(void)
+{
+ vwm_xserver_t *xserver;
+
+ if (!(xserver = calloc(sizeof(vwm_xserver_t), 1))) {
+ VWM_ERROR("Cannot allocate vwm_xserver_t");
+ goto _err;
+ }
+
+ if (!(xserver->display = XOpenDisplay(NULL))) {
+ VWM_ERROR("Cannot open display");
+ goto _err_free;
+ }
+
+ /* prevent children from inheriting the X connection */
+ if (fcntl(ConnectionNumber(xserver->display), F_SETFD, FD_CLOEXEC) < 0) {
+ VWM_ERROR("Cannot set FD_CLOEXEC on X connection");
+ goto _err_xclose;
+ }
+
+ XSetErrorHandler(errhandler); /* TODO, this may not belong here. */
+
+ xserver->screen_num = DefaultScreen(xserver->display);
+ xserver->gc = XCreateGC(xserver->display, XSERVER_XROOT(xserver), 0, NULL);
+ xserver->cmap = DefaultColormap(xserver->display, xserver->screen_num);
+
+ return xserver;
+
+
+_err_xclose:
+ XCloseDisplay(xserver->display);
+
+_err_free:
+ free(xserver);
+
+_err:
+ return NULL;
+}
+
+
+/* close on opened xserver */
+void vwm_xserver_close(vwm_xserver_t *xserver)
+{
+ XFlush(xserver->display);
+ XCloseDisplay(xserver->display);
+ free(xserver);
+}
diff --git a/src/xserver.h b/src/xserver.h
new file mode 100644
index 0000000..694513a
--- /dev/null
+++ b/src/xserver.h
@@ -0,0 +1,21 @@
+#ifndef _XSERVER_H
+#define _XSERVER_H
+
+#include <X11/Xlib.h>
+
+#define XSERVER_XROOT(_xserver) RootWindow((_xserver)->display, (_xserver)->screen_num)
+#define XSERVER_XVISUAL(_xserver) DefaultVisual((_xserver)->display, (_xserver)->screen_num)
+#define XSERVER_XDEPTH(_xserver) DefaultDepth((_xserver)->display, (_xserver)->screen_num)
+
+/* bare xserver context, split out for vmon's shared monitoring overlay use sake */
+typedef struct vwm_xserver_t {
+ Display *display;
+ Colormap cmap;
+ int screen_num;
+ GC gc;
+} vwm_xserver_t;
+
+vwm_xserver_t * vwm_xserver_open(void);
+void vwm_xserver_close(vwm_xserver_t *);
+
+#endif
© All Rights Reserved