aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dmenu.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/dmenu.c b/dmenu.c
index cf5e4a6..d54b1b3 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -57,7 +57,7 @@ static DC *dc;
57static Item *items = NULL; 57static Item *items = NULL;
58static Item *matches, *matchend; 58static Item *matches, *matchend;
59static Item *prev, *curr, *next, *sel; 59static Item *prev, *curr, *next, *sel;
60static Window root, win; 60static Window win;
61 61
62static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; 62static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
63 63
@@ -104,14 +104,14 @@ main(int argc, char *argv[]) {
104 initfont(dc, font); 104 initfont(dc, font);
105 105
106 if(fast) { 106 if(fast) {
107 setup(); 107 grabkeyboard();
108 readstdin(); 108 readstdin();
109 } 109 }
110 else { 110 else {
111 readstdin(); 111 readstdin();
112 setup(); 112 grabkeyboard();
113 } 113 }
114 match(); 114 setup();
115 run(); 115 run();
116 return EXIT_FAILURE; 116 return EXIT_FAILURE;
117 117
@@ -209,7 +209,8 @@ grabkeyboard(void) {
209 int i; 209 int i;
210 210
211 for(i = 0; i < 1000; i++) { 211 for(i = 0; i < 1000; i++) {
212 if(!XGrabKeyboard(dc->dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime)) 212 if(XGrabKeyboard(dc->dpy, DefaultRootWindow(dc->dpy), True,
213 GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess)
213 return; 214 return;
214 usleep(1000); 215 usleep(1000);
215 } 216 }
@@ -487,22 +488,21 @@ run(void) {
487 488
488void 489void
489setup(void) { 490setup(void) {
490 int x, y, screen; 491 int x, y, screen = DefaultScreen(dc->dpy);
492 Window root = RootWindow(dc->dpy, screen);
491 XSetWindowAttributes wa; 493 XSetWindowAttributes wa;
492#ifdef XINERAMA 494#ifdef XINERAMA
493 int n; 495 int n;
494 XineramaScreenInfo *info; 496 XineramaScreenInfo *info;
495#endif 497#endif
496 498
497 screen = DefaultScreen(dc->dpy);
498 root = RootWindow(dc->dpy, screen);
499 utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);
500
501 normcol[ColBG] = getcolor(dc, normbgcolor); 499 normcol[ColBG] = getcolor(dc, normbgcolor);
502 normcol[ColFG] = getcolor(dc, normfgcolor); 500 normcol[ColFG] = getcolor(dc, normfgcolor);
503 selcol[ColBG] = getcolor(dc, selbgcolor); 501 selcol[ColBG] = getcolor(dc, selbgcolor);
504 selcol[ColFG] = getcolor(dc, selfgcolor); 502 selcol[ColFG] = getcolor(dc, selfgcolor);
505 503
504 utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);
505
506 /* menu geometry */ 506 /* menu geometry */
507 bh = dc->font.height + 2; 507 bh = dc->font.height + 2;
508 lines = MAX(lines, 0); 508 lines = MAX(lines, 0);
@@ -539,9 +539,10 @@ setup(void) {
539 DefaultVisual(dc->dpy, screen), 539 DefaultVisual(dc->dpy, screen),
540 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); 540 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
541 541
542 grabkeyboard();
543 resizedc(dc, mw, mh); 542 resizedc(dc, mw, mh);
544 inputw = MIN(inputw, mw/3); 543 inputw = MIN(inputw, mw/3);
545 promptw = prompt ? textw(dc, prompt) : 0; 544 promptw = prompt ? textw(dc, prompt) : 0;
546 XMapRaised(dc->dpy, win); 545 XMapRaised(dc->dpy, win);
546 drawmenu();
547 match();
547} 548}