aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile40
-rw-r--r--TODO.md5
-rw-r--r--config.h8
-rw-r--r--config.mk23
-rw-r--r--daemonic.c65
6 files changed, 143 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..627c86e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+daemonic
+*.o
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..c655b67
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,40 @@
+# daemonic - dynamic window manager
+# See LICENSE file for copyright and license details.
+
+include config.mk
+
+SRC = daemonic.c
+OBJ = ${SRC:.c=.o}
+
+all: clean options daemonic
+
+options:
+ @echo daemonic build options:
+ @echo "CFLAGS = ${CFLAGS}"
+ @echo "LDFLAGS = ${LDFLAGS}"
+ @echo "CC = ${CC}"
+
+.c.o:
+ ${CC} -c ${CFLAGS} $<
+
+${OBJ}: config.mk
+
+daemonic: ${OBJ}
+ ${CC} -o $@ ${OBJ} ${LDFLAGS}
+
+clean:
+ rm -f daemonic ${OBJ}
+
+install: all
+ mkdir -p ${DESTDIR}${PREFIX}/bin
+ cp -f daemonic ${DESTDIR}${PREFIX}/bin
+ chmod 755 ${DESTDIR}${PREFIX}/bin/daemonic
+ mkdir -p ${DESTDIR}${MANPREFIX}/man1
+ sed "s/VERSION/${VERSION}/g" < daemonic.1 > ${DESTDIR}${MANPREFIX}/man1/daemonic.1
+ chmod 644 ${DESTDIR}${MANPREFIX}/man1/daemonic.1
+
+uninstall:
+ rm -f ${DESTDIR}${PREFIX}/bin/daemonic\
+ ${DESTDIR}${MANPREFIX}/man1/daemonic.1
+
+.PHONY: all options clean dist install uninstall
diff --git a/TODO.md b/TODO.md
new file mode 100644
index 0000000..4fb2d18
--- /dev/null
+++ b/TODO.md
@@ -0,0 +1,5 @@
+# TODO
+ - [ ] Add modes
+ - [ ] Clean up build system
+ - [ ] Fix installation
+ - [ ] Create man page
diff --git a/config.h b/config.h
new file mode 100644
index 0000000..1a802ec
--- /dev/null
+++ b/config.h
@@ -0,0 +1,8 @@
+
+#define MOD Mod1Mask
+
+static Key keys[] = {
+ { MOD | ShiftMask, XK_y, "notify-send hello" },
+ { MOD | ShiftMask, XK_z, "sh -c '~/scripts/notify.sh wow'" },
+};
+
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..ecd08e1
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,23 @@
+# dwm version
+VERSION = 6.2
+
+# Customize below to fit your system
+
+# paths
+PREFIX = /usr/local
+MANPREFIX = ${PREFIX}/share/man
+
+X11INC = /usr/X11R6/include
+X11LIB = /usr/X11R6/lib
+
+# includes and libs
+INCS = -I${X11INC}
+LIBS = -L${X11LIB} -lX11
+
+# flags
+CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\"
+CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS}
+LDFLAGS = ${LIBS}
+
+# compiler and linker
+CC = cc
diff --git a/daemonic.c b/daemonic.c
new file mode 100644
index 0000000..b025224
--- /dev/null
+++ b/daemonic.c
@@ -0,0 +1,65 @@
+#include<stdio.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+typedef struct Key {
+ unsigned int mod;
+ KeySym key;
+ char* command;
+} Key;
+
+#include "config.h"
+
+#define LENGTH(X) (sizeof X / sizeof X[0])
+
+void
+bind_key(Display *dpy, Window win, unsigned int mod, KeySym key)
+{
+ int keycode = XKeysymToKeycode(dpy, key);
+
+ XGrabKey(dpy, keycode, mod, win, False, GrabModeAsync, GrabModeAsync);
+}
+
+int
+error_handler(Display *disp, XErrorEvent *xe)
+{
+ if (xe->error_code == BadAccess) {
+ printf("daemonic: [BadAccess] Cant grab key binding. Already grabbed\n");
+ return 0;
+ }
+
+ printf("daemonic: Something went wrong");
+ return 1;
+}
+
+int
+main()
+{
+ int running = 10;
+ XSetErrorHandler(error_handler);
+
+ Display *dpy = XOpenDisplay(0);
+ Window root = DefaultRootWindow(dpy);
+
+ // Grab keys
+ int i;
+ for (i = 0; i < LENGTH(keys); i++) {
+ bind_key(dpy, root, keys[i].mod, keys[i].key);
+ }
+
+ XSelectInput(dpy, root, KeyPressMask);
+
+ /* main event loop */
+ XEvent ev;
+ XSync(dpy, False);
+ while (running && !XNextEvent(dpy, &ev)) {
+ if (ev.type == KeyPress) {
+ printf("Key: %d\n", ev.xkey.keycode);
+
+ running--;
+ }
+ }
+
+ XCloseDisplay(dpy);
+}
+