about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--dwm.c47
1 files changed, 21 insertions, 26 deletions
diff --git a/dwm.c b/dwm.c
index d497f4c..cd7c9e5 100644
--- a/dwm.c
+++ b/dwm.c
@@ -129,7 +129,6 @@ static void mappingnotify(XEvent *e);
 static void maprequest(XEvent *e);
 static void propertynotify(XEvent *e);
 static void unmapnotify(XEvent *e);
-static void grabkeys(void);
 static unsigned int idxoftag(const char *tag);
 static void floating(void); /* default floating layout */
 static void applyrules(Client *c);
@@ -1070,9 +1069,26 @@ keypress(XEvent *e) {
 	KEYS
 	unsigned int len = sizeof keys / sizeof keys[0];
 	unsigned int i;
+	KeyCode code;
 	KeySym keysym;
-	XKeyEvent *ev = &e->xkey;
-
+	XKeyEvent *ev;
+
+	if(!e) { /* grabkeys */
+		XUngrabKey(dpy, AnyKey, AnyModifier, root);
+		for(i = 0; i < len; i++) {
+			code = XKeysymToKeycode(dpy, keys[i].keysym);
+			XGrabKey(dpy, code, keys[i].mod, root, True,
+					GrabModeAsync, GrabModeAsync);
+			XGrabKey(dpy, code, keys[i].mod | LockMask, root, True,
+					GrabModeAsync, GrabModeAsync);
+			XGrabKey(dpy, code, keys[i].mod | numlockmask, root, True,
+					GrabModeAsync, GrabModeAsync);
+			XGrabKey(dpy, code, keys[i].mod | numlockmask | LockMask, root, True,
+					GrabModeAsync, GrabModeAsync);
+		}
+		return;
+	}
+	ev = &e->xkey;
 	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
 	for(i = 0; i < len; i++)
 		if(keysym == keys[i].keysym
@@ -1099,7 +1115,7 @@ mappingnotify(XEvent *e) {
 
 	XRefreshKeyboardMapping(ev);
 	if(ev->request == MappingKeyboard)
-		grabkeys();
+		keypress(NULL);
 }
 
 static void
@@ -1152,27 +1168,6 @@ unmapnotify(XEvent *e) {
 		unmanage(c);
 }
 
-static void
-grabkeys(void) {
-	KEYS
-	unsigned int len = sizeof keys / sizeof keys[0];
-	unsigned int i;
-	KeyCode code;
-
-	XUngrabKey(dpy, AnyKey, AnyModifier, root);
-	for(i = 0; i < len; i++) {
-		code = XKeysymToKeycode(dpy, keys[i].keysym);
-		XGrabKey(dpy, code, keys[i].mod, root, True,
-				GrabModeAsync, GrabModeAsync);
-		XGrabKey(dpy, code, keys[i].mod | LockMask, root, True,
-				GrabModeAsync, GrabModeAsync);
-		XGrabKey(dpy, code, keys[i].mod | numlockmask, root, True,
-				GrabModeAsync, GrabModeAsync);
-		XGrabKey(dpy, code, keys[i].mod | numlockmask | LockMask, root, True,
-				GrabModeAsync, GrabModeAsync);
-	}
-}
-
 static unsigned int
 idxoftag(const char *tag) {
 	unsigned int i;
@@ -1546,7 +1541,7 @@ setup(void) {
 	wa.cursor = cursor[CurNormal];
 	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
 	XSelectInput(dpy, root, wa.event_mask);
-	grabkeys();
+	keypress(NULL); /* grabkeys */
 	compileregs();
 	for(ntags = 0; tags[ntags]; ntags++);
 	seltags = emallocz(sizeof(Bool) * ntags);
class="cm"> * See LICENSE file for license details. */ #include "dwm.h" #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <sys/wait.h> #include <unistd.h> /* extern */ void * emallocz(unsigned int size) { void *res = calloc(1, size); if(!res) eprint("fatal: could not malloc() %u bytes\n", size); return res; } void eprint(const char *errstr, ...) { va_list ap; va_start(ap, errstr); vfprintf(stderr, errstr, ap); va_end(ap); exit(EXIT_FAILURE); } void spawn(Arg *arg) { static char *shell = NULL; if(!shell && !(shell = getenv("SHELL"))) shell = "/bin/sh"; if(!arg->cmd) return; /* The double-fork construct avoids zombie processes and keeps the code * clean from stupid signal handlers. */ if(fork() == 0) { if(fork() == 0) { if(dpy) close(ConnectionNumber(dpy)); setsid(); execl(shell, shell, "-c", arg->cmd, (char *)NULL); fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd); perror(" failed"); } exit(0); } wait(0); }