aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/main.c b/main.c
index cd0e2b5..210792a 100644
--- a/main.c
+++ b/main.c
@@ -108,6 +108,13 @@ drawmenu(void) {
108 XFlush(dpy); 108 XFlush(dpy);
109} 109}
110 110
111static void
112grabkeyboard(void) {
113 while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
114 GrabModeAsync, CurrentTime) != GrabSuccess)
115 usleep(1000);
116}
117
111static unsigned long 118static unsigned long
112initcolor(const char *colstr) { 119initcolor(const char *colstr) {
113 Colormap cmap = DefaultColormap(dpy, screen); 120 Colormap cmap = DefaultColormap(dpy, screen);
@@ -418,12 +425,6 @@ main(int argc, char *argv[]) {
418 XModifierKeymap *modmap; 425 XModifierKeymap *modmap;
419 XSetWindowAttributes wa; 426 XSetWindowAttributes wa;
420 427
421 if(argc == 2 && !strncmp("-v", argv[1], 3))
422 eprint("dmenu-"VERSION", (C)opyright MMVI-MMVII Anselm R. Garbe\n");
423 else if(isatty(STDIN_FILENO)) {
424 fputs("error: dmenu can't run in an interactive shell\n", stdout);
425 usage();
426 }
427 /* command line args */ 428 /* command line args */
428 for(i = 1; i < argc; i++) 429 for(i = 1; i < argc; i++)
429 if(!strncmp(argv[i], "-b", 3)) { 430 if(!strncmp(argv[i], "-b", 3)) {
@@ -447,6 +448,8 @@ main(int argc, char *argv[]) {
447 else if(!strncmp(argv[i], "-sf", 4)) { 448 else if(!strncmp(argv[i], "-sf", 4)) {
448 if(++i < argc) selfg = argv[i]; 449 if(++i < argc) selfg = argv[i];
449 } 450 }
451 else if(!strncmp(argv[i], "-v", 3))
452 eprint("dmenu-"VERSION", (C)opyright MMVI-MMVII Anselm R. Garbe\n");
450 else 453 else
451 usage(); 454 usage();
452 setlocale(LC_CTYPE, ""); 455 setlocale(LC_CTYPE, "");
@@ -455,10 +458,14 @@ main(int argc, char *argv[]) {
455 eprint("dmenu: cannot open display\n"); 458 eprint("dmenu: cannot open display\n");
456 screen = DefaultScreen(dpy); 459 screen = DefaultScreen(dpy);
457 root = RootWindow(dpy, screen); 460 root = RootWindow(dpy, screen);
458 while(XGrabKeyboard(dpy, root, True, GrabModeAsync, 461 if(isatty(STDIN_FILENO)) {
459 GrabModeAsync, CurrentTime) != GrabSuccess) 462 maxname = readstdin();
460 usleep(1000); 463 grabkeyboard();
461 maxname = readstdin(); 464 }
465 else { /* prevent keypress loss */
466 grabkeyboard();
467 maxname = readstdin();
468 }
462 /* init modifier map */ 469 /* init modifier map */
463 modmap = XGetModifierMapping(dpy); 470 modmap = XGetModifierMapping(dpy);
464 for (i = 0; i < 8; i++) { 471 for (i = 0; i < 8; i++) {