diff options
-rw-r--r-- | main.c | 41 |
1 files changed, 20 insertions, 21 deletions
@@ -110,7 +110,7 @@ drawmenu(void) { | |||
110 | 110 | ||
111 | static void | 111 | static void |
112 | grabkeyboard(void) { | 112 | grabkeyboard(void) { |
113 | while(XGrabKeyboard(dpy, root, True, GrabModeAsync, | 113 | while(XGrabKeyboard(dpy, win, True, GrabModeAsync, |
114 | GrabModeAsync, CurrentTime) != GrabSuccess) | 114 | GrabModeAsync, CurrentTime) != GrabSuccess) |
115 | usleep(1000); | 115 | usleep(1000); |
116 | } | 116 | } |
@@ -454,24 +454,6 @@ main(int argc, char *argv[]) { | |||
454 | eprint("dmenu: cannot open display\n"); | 454 | eprint("dmenu: cannot open display\n"); |
455 | screen = DefaultScreen(dpy); | 455 | screen = DefaultScreen(dpy); |
456 | root = RootWindow(dpy, screen); | 456 | root = RootWindow(dpy, screen); |
457 | if(isatty(STDIN_FILENO)) { | ||
458 | maxname = readstdin(); | ||
459 | grabkeyboard(); | ||
460 | } | ||
461 | else { /* prevent keypress loss */ | ||
462 | grabkeyboard(); | ||
463 | maxname = readstdin(); | ||
464 | } | ||
465 | /* init modifier map */ | ||
466 | modmap = XGetModifierMapping(dpy); | ||
467 | for (i = 0; i < 8; i++) { | ||
468 | for (j = 0; j < modmap->max_keypermod; j++) { | ||
469 | if(modmap->modifiermap[i * modmap->max_keypermod + j] | ||
470 | == XKeysymToKeycode(dpy, XK_Num_Lock)) | ||
471 | numlockmask = (1 << i); | ||
472 | } | ||
473 | } | ||
474 | XFreeModifiermap(modmap); | ||
475 | /* style */ | 457 | /* style */ |
476 | dc.norm[ColBG] = initcolor(normbg); | 458 | dc.norm[ColBG] = initcolor(normbg); |
477 | dc.norm[ColFG] = initcolor(normfg); | 459 | dc.norm[ColFG] = initcolor(normfg); |
@@ -495,6 +477,25 @@ main(int argc, char *argv[]) { | |||
495 | XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); | 477 | XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); |
496 | if(!dc.font.set) | 478 | if(!dc.font.set) |
497 | XSetFont(dpy, dc.gc, dc.font.xfont->fid); | 479 | XSetFont(dpy, dc.gc, dc.font.xfont->fid); |
480 | drawmenu(); | ||
481 | XMapRaised(dpy, win); | ||
482 | if(isatty(STDIN_FILENO)) { | ||
483 | maxname = readstdin(); | ||
484 | grabkeyboard(); | ||
485 | } | ||
486 | else { /* prevent keypress loss */ | ||
487 | grabkeyboard(); | ||
488 | maxname = readstdin(); | ||
489 | } | ||
490 | /* init modifier map */ | ||
491 | modmap = XGetModifierMapping(dpy); | ||
492 | for(i = 0; i < 8; i++) | ||
493 | for(j = 0; j < modmap->max_keypermod; j++) { | ||
494 | if(modmap->modifiermap[i * modmap->max_keypermod + j] | ||
495 | == XKeysymToKeycode(dpy, XK_Num_Lock)) | ||
496 | numlockmask = (1 << i); | ||
497 | } | ||
498 | XFreeModifiermap(modmap); | ||
498 | if(maxname) | 499 | if(maxname) |
499 | cmdw = textw(maxname); | 500 | cmdw = textw(maxname); |
500 | if(cmdw > mw / 3) | 501 | if(cmdw > mw / 3) |
@@ -505,8 +506,6 @@ main(int argc, char *argv[]) { | |||
505 | promptw = mw / 5; | 506 | promptw = mw / 5; |
506 | text[0] = 0; | 507 | text[0] = 0; |
507 | match(text); | 508 | match(text); |
508 | XMapRaised(dpy, win); | ||
509 | drawmenu(); | ||
510 | XSync(dpy, False); | 509 | XSync(dpy, False); |
511 | 510 | ||
512 | /* main event loop */ | 511 | /* main event loop */ |