aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/main.c b/main.c
index 29b313b..0f07773 100644
--- a/main.c
+++ b/main.c
@@ -110,7 +110,7 @@ drawmenu(void) {
110 110
111static void 111static void
112grabkeyboard(void) { 112grabkeyboard(void) {
113 while(XGrabKeyboard(dpy, win, True, GrabModeAsync, 113 while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
114 GrabModeAsync, CurrentTime) != GrabSuccess) 114 GrabModeAsync, CurrentTime) != GrabSuccess)
115 usleep(1000); 115 usleep(1000);
116} 116}
@@ -454,6 +454,24 @@ 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);
457 /* style */ 475 /* style */
458 dc.norm[ColBG] = initcolor(normbg); 476 dc.norm[ColBG] = initcolor(normbg);
459 dc.norm[ColFG] = initcolor(normfg); 477 dc.norm[ColFG] = initcolor(normfg);
@@ -477,27 +495,6 @@ main(int argc, char *argv[]) {
477 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); 495 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
478 if(!dc.font.set) 496 if(!dc.font.set)
479 XSetFont(dpy, dc.gc, dc.font.xfont->fid); 497 XSetFont(dpy, dc.gc, dc.font.xfont->fid);
480 drawmenu();
481 XMapRaised(dpy, win);
482 XMaskEvent(dpy, ExposureMask, &ev);
483 drawmenu();
484 if(isatty(STDIN_FILENO)) {
485 maxname = readstdin();
486 grabkeyboard();
487 }
488 else { /* prevent keypress loss */
489 grabkeyboard();
490 maxname = readstdin();
491 }
492 /* init modifier map */
493 modmap = XGetModifierMapping(dpy);
494 for(i = 0; i < 8; i++)
495 for(j = 0; j < modmap->max_keypermod; j++) {
496 if(modmap->modifiermap[i * modmap->max_keypermod + j]
497 == XKeysymToKeycode(dpy, XK_Num_Lock))
498 numlockmask = (1 << i);
499 }
500 XFreeModifiermap(modmap);
501 if(maxname) 498 if(maxname)
502 cmdw = textw(maxname); 499 cmdw = textw(maxname);
503 if(cmdw > mw / 3) 500 if(cmdw > mw / 3)
@@ -508,6 +505,7 @@ main(int argc, char *argv[]) {
508 promptw = mw / 5; 505 promptw = mw / 5;
509 text[0] = 0; 506 text[0] = 0;
510 match(text); 507 match(text);
508 XMapRaised(dpy, win);
511 drawmenu(); 509 drawmenu();
512 XSync(dpy, False); 510 XSync(dpy, False);
513 511
@@ -519,6 +517,10 @@ main(int argc, char *argv[]) {
519 case KeyPress: 517 case KeyPress:
520 kpress(&ev.xkey); 518 kpress(&ev.xkey);
521 break; 519 break;
520 case Expose:
521 if(ev.xexpose.count == 0)
522 drawmenu();
523 break;
522 } 524 }
523 525
524 /* cleanup */ 526 /* cleanup */