aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--config.h8
-rw-r--r--daemonic.c21
2 files changed, 26 insertions, 3 deletions
diff --git a/config.h b/config.h
index 1a802ec..65e0766 100644
--- a/config.h
+++ b/config.h
@@ -1,8 +1,10 @@
+// Shell
+static char shell[] = "sh";
-#define MOD Mod1Mask
+#define MOD Mod1Mask|ShiftMask
static Key keys[] = {
- { MOD | ShiftMask, XK_y, "notify-send hello" },
- { MOD | ShiftMask, XK_z, "sh -c '~/scripts/notify.sh wow'" },
+ { MOD, XK_y, "notify-send hello" },
+ { MOD, XK_z, "~/scripts/notify.sh wow" },
};
diff --git a/daemonic.c b/daemonic.c
index c70996a..23a50c2 100644
--- a/daemonic.c
+++ b/daemonic.c
@@ -1,6 +1,8 @@
#include<stdio.h>
+#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
+#include <unistd.h>
typedef struct Key {
unsigned int mod;
@@ -28,6 +30,21 @@ int error_handler(Display *disp, XErrorEvent *xe) {
return 1;
}
+void spawn(char ** command) {
+ if (fork() == 0) {
+ setsid();
+ execvp(command[0], command);
+ fprintf(stderr, "dwm: execvp %s", command[0]);
+ perror(" failed");
+ exit(0);
+ }
+}
+
+void run(char *command) {
+ char* cmd[] = {shell, "-c", command, NULL};
+ spawn(cmd);
+}
+
void keypress(Display *dpy, XKeyEvent *ev) {
unsigned int i;
KeySym keysym = XKeycodeToKeysym(dpy, (KeyCode) ev->keycode, 0);
@@ -35,10 +52,12 @@ void keypress(Display *dpy, XKeyEvent *ev) {
for (i = 0; i < LENGTH(keys); i++) {
if (keysym == keys[i].key && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) && keys[i].command) {
printf("Executin: %s\n", keys[i].command);
+ run(keys[i].command);
}
}
}
+
int main() {
XSetErrorHandler(error_handler);
@@ -53,6 +72,8 @@ int main() {
bind_key(dpy, root, keys[i].mod, keys[i].key);
}
+ /*spawn({"sh", "-c", "~/scripts/notify.sh 'wow'"});*/
+
XSelectInput(dpy, root, KeyPressMask);
/* main event loop */