diff options
author | Connor Lane Smith <cls@lubutu.com> | 2011-05-15 14:13:31 +0100 |
---|---|---|
committer | Connor Lane Smith <cls@lubutu.com> | 2011-05-15 14:13:31 +0100 |
commit | d0051e7bb858815866fbaf3a8fd5b50319c0c86d (patch) | |
tree | e1984fcdce3f9acb59c56c031993e4f9efbdf250 | |
parent | fb67bd666ed22a28caff505f3319184735e05311 (diff) |
faster grab
-rw-r--r-- | dmenu.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -57,7 +57,7 @@ static DC *dc; | |||
57 | static Item *items = NULL; | 57 | static Item *items = NULL; |
58 | static Item *matches, *matchend; | 58 | static Item *matches, *matchend; |
59 | static Item *prev, *curr, *next, *sel; | 59 | static Item *prev, *curr, *next, *sel; |
60 | static Window root, win; | 60 | static Window win; |
61 | 61 | ||
62 | static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; | 62 | static 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 | ||
488 | void | 489 | void |
489 | setup(void) { | 490 | setup(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 | } |