Not sure how useful this will be, but I altered dmenu so it can grab the
X keyboard before reading input from stdin.

It works well on my netbook, where occasionally dmenu_run can take up to
a second to grab the keyboard, meaning I end up typing a load of
jibberish into the focused window, expecting it to go into dmenu.

Just an itch it scratches really.

Cheers,
Rob.
diff -r a79e4a9cb167 dmenu.c
--- a/dmenu.c	Sat Nov 20 09:25:08 2010 +0000
+++ b/dmenu.c	Fri Feb 18 04:24:31 2011 +0000
@@ -66,6 +68,7 @@
 int
 main(int argc, char *argv[]) {
 	int i;
+	Bool fastgrab = False;
 
 	progname = "dmenu";
 	for(i = 1; i < argc; i++)
@@ -78,6 +81,10 @@
 			topbar = False;
 		else if(!strcmp(argv[i], "-i"))
 			fstrncmp = strncasecmp;
+		else if(!strcmp(argv[i], "-f"))
+			fastgrab = True;
 		else if(i == argc-1)
 			usage();
 		/* double flags */
@@ -101,15 +108,61 @@
 			usage();
 
 	dc = initdc();
 	initfont(dc, font);
+
+	if(fastgrab)
+		setup(); /* grab X _now_ */
+
 	readstdin();
-	setup();
+
+	if(!fastgrab)
+		setup();
+	else
+		match(); /* need to re-match now we've read the input */
+
 	run();
 
 	return EXIT_FAILURE;  /* should not reach */
 }
@@ -536,7 +594,7 @@
 
 void
 usage(void) {
-	fputs("usage: dmenu [-b] [-i] [-l lines] [-m monitor] [-p prompt] [-fn font]\n"
+	fputs("usage: dmenu [-b] [-i] [-q] [-l lines] [-m monitor] [-p prompt] [-fn font]\n"
 	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr);
 	exit(EXIT_FAILURE);
 }

Reply via email to