aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dmenu.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/dmenu.c b/dmenu.c
index d0ed966..a8a6290 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -27,9 +27,9 @@ static void calcoffsets(void);
27static void drawmenu(void); 27static void drawmenu(void);
28static char *fstrstr(const char *s, const char *sub); 28static char *fstrstr(const char *s, const char *sub);
29static void grabkeyboard(void); 29static void grabkeyboard(void);
30static void insert(const char *s, ssize_t n); 30static void insert(const char *str, ssize_t n);
31static void keypress(XKeyEvent *ev); 31static void keypress(XKeyEvent *ev);
32static void match(void); 32static void match(Bool sub);
33static size_t nextrune(int incr); 33static size_t nextrune(int incr);
34static void paste(void); 34static void paste(void);
35static void readstdin(void); 35static void readstdin(void);
@@ -218,14 +218,14 @@ grabkeyboard(void) {
218} 218}
219 219
220void 220void
221insert(const char *s, ssize_t n) { 221insert(const char *str, ssize_t n) {
222 if(strlen(text) + n > sizeof text - 1) 222 if(strlen(text) + n > sizeof text - 1)
223 return; 223 return;
224 memmove(&text[cursor + n], &text[cursor], sizeof text - cursor - MAX(n, 0)); 224 memmove(&text[cursor + n], &text[cursor], sizeof text - cursor - MAX(n, 0));
225 if(n > 0) 225 if(n > 0)
226 memcpy(&text[cursor], s, n); 226 memcpy(&text[cursor], str, n);
227 cursor += n; 227 cursor += n;
228 match(); 228 match(n > 0);
229} 229}
230 230
231void 231void
@@ -269,7 +269,7 @@ keypress(XKeyEvent *ev) {
269 break; 269 break;
270 case XK_k: /* delete right */ 270 case XK_k: /* delete right */
271 text[cursor] = '\0'; 271 text[cursor] = '\0';
272 match(); 272 match(False);
273 break; 273 break;
274 case XK_n: 274 case XK_n:
275 ksym = XK_Down; 275 ksym = XK_Down;
@@ -375,30 +375,31 @@ keypress(XKeyEvent *ev) {
375 return; 375 return;
376 strncpy(text, sel->text, sizeof text); 376 strncpy(text, sel->text, sizeof text);
377 cursor = strlen(text); 377 cursor = strlen(text);
378 match(); 378 match(True);
379 break; 379 break;
380 } 380 }
381 drawmenu(); 381 drawmenu();
382} 382}
383 383
384void 384void
385match(void) { 385match(Bool sub) {
386 size_t len = strlen(text); 386 size_t len = strlen(text);
387 Item *item, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend; 387 Item *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend;
388 Item *item, *next = NULL;
388 389
389 matches = lexact = lprefix = lsubstr = matchend = exactend = prefixend = substrend = NULL; 390 lexact = lprefix = lsubstr = exactend = prefixend = substrend = NULL;
390 for(item = items; item && item->text; item++) 391 for(item = sub ? matches : items; item && item->text; item = next) {
392 next = sub ? item->right : item + 1;
391 if(!fstrncmp(text, item->text, len + 1)) 393 if(!fstrncmp(text, item->text, len + 1))
392 appenditem(item, &lexact, &exactend); 394 appenditem(item, &lexact, &exactend);
393 else if(!fstrncmp(text, item->text, len)) 395 else if(!fstrncmp(text, item->text, len))
394 appenditem(item, &lprefix, &prefixend); 396 appenditem(item, &lprefix, &prefixend);
395 else if(fstrstr(item->text, text)) 397 else if(fstrstr(item->text, text))
396 appenditem(item, &lsubstr, &substrend); 398 appenditem(item, &lsubstr, &substrend);
397
398 if(lexact) {
399 matches = lexact;
400 matchend = exactend;
401 } 399 }
400 matches = lexact;
401 matchend = exactend;
402
402 if(lprefix) { 403 if(lprefix) {
403 if(matchend) { 404 if(matchend) {
404 matchend->right = lprefix; 405 matchend->right = lprefix;
@@ -498,8 +499,8 @@ setup(void) {
498 499
499 normcol[ColBG] = getcolor(dc, normbgcolor); 500 normcol[ColBG] = getcolor(dc, normbgcolor);
500 normcol[ColFG] = getcolor(dc, normfgcolor); 501 normcol[ColFG] = getcolor(dc, normfgcolor);
501 selcol[ColBG] = getcolor(dc, selbgcolor); 502 selcol[ColBG] = getcolor(dc, selbgcolor);
502 selcol[ColFG] = getcolor(dc, selfgcolor); 503 selcol[ColFG] = getcolor(dc, selfgcolor);
503 504
504 utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False); 505 utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);
505 506
@@ -532,7 +533,7 @@ setup(void) {
532 } 533 }
533 inputw = MIN(inputw, mw/3); 534 inputw = MIN(inputw, mw/3);
534 promptw = prompt ? textw(dc, prompt) : 0; 535 promptw = prompt ? textw(dc, prompt) : 0;
535 match(); 536 match(False);
536 537
537 /* menu window */ 538 /* menu window */
538 wa.override_redirect = True; 539 wa.override_redirect = True;