faster grab
d0051e7b
1 file(s) · +12 −11
| 57 | 57 | static Item *items = NULL; |
|
| 58 | 58 | static Item *matches, *matchend; |
|
| 59 | 59 | static Item *prev, *curr, *next, *sel; |
|
| 60 | - | static Window root, win; |
|
| 60 | + | static Window win; |
|
| 61 | 61 | ||
| 62 | 62 | static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; |
|
| 63 | 63 | ||
| 104 | 104 | initfont(dc, font); |
|
| 105 | 105 | ||
| 106 | 106 | if(fast) { |
|
| 107 | - | setup(); |
|
| 107 | + | grabkeyboard(); |
|
| 108 | 108 | readstdin(); |
|
| 109 | 109 | } |
|
| 110 | 110 | else { |
|
| 111 | 111 | readstdin(); |
|
| 112 | - | setup(); |
|
| 112 | + | grabkeyboard(); |
|
| 113 | 113 | } |
|
| 114 | - | match(); |
|
| 114 | + | setup(); |
|
| 115 | 115 | run(); |
|
| 116 | 116 | return EXIT_FAILURE; |
|
| 117 | 117 | ||
| 209 | 209 | int i; |
|
| 210 | 210 | ||
| 211 | 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 | 214 | return; |
|
| 214 | 215 | usleep(1000); |
|
| 215 | 216 | } |
|
| 487 | 488 | ||
| 488 | 489 | void |
|
| 489 | 490 | setup(void) { |
|
| 490 | - | int x, y, screen; |
|
| 491 | + | int x, y, screen = DefaultScreen(dc->dpy); |
|
| 492 | + | Window root = RootWindow(dc->dpy, screen); |
|
| 491 | 493 | XSetWindowAttributes wa; |
|
| 492 | 494 | #ifdef XINERAMA |
|
| 493 | 495 | int n; |
|
| 494 | 496 | XineramaScreenInfo *info; |
|
| 495 | 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 | 499 | normcol[ColBG] = getcolor(dc, normbgcolor); |
|
| 502 | 500 | normcol[ColFG] = getcolor(dc, normfgcolor); |
|
| 503 | 501 | selcol[ColBG] = getcolor(dc, selbgcolor); |
|
| 504 | 502 | selcol[ColFG] = getcolor(dc, selfgcolor); |
|
| 503 | + | ||
| 504 | + | utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False); |
|
| 505 | 505 | ||
| 506 | 506 | /* menu geometry */ |
|
| 507 | 507 | bh = dc->font.height + 2; |
|
| 539 | 539 | DefaultVisual(dc->dpy, screen), |
|
| 540 | 540 | CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); |
|
| 541 | 541 | ||
| 542 | - | grabkeyboard(); |
|
| 543 | 542 | resizedc(dc, mw, mh); |
|
| 544 | 543 | inputw = MIN(inputw, mw/3); |
|
| 545 | 544 | promptw = prompt ? textw(dc, prompt) : 0; |
|
| 546 | 545 | XMapRaised(dc->dpy, win); |
|
| 546 | + | drawmenu(); |
|
| 547 | + | match(); |
|
| 547 | 548 | } |
|