aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dmenu.c65
1 files changed, 29 insertions, 36 deletions
diff --git a/dmenu.c b/dmenu.c
index 5f16894..6177906 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -52,6 +52,7 @@ static void calcoffsetsh(void);
52static void calcoffsetsv(void); 52static void calcoffsetsv(void);
53static char *cistrstr(const char *s, const char *sub); 53static char *cistrstr(const char *s, const char *sub);
54static void cleanup(void); 54static void cleanup(void);
55static void drawcursor(void);
55static void drawmenu(void); 56static void drawmenu(void);
56static void drawmenuh(void); 57static void drawmenuh(void);
57static void drawmenuv(void); 58static void drawmenuv(void);
@@ -247,9 +248,7 @@ drawmenuh(void) {
247 dc.x += dc.w; 248 dc.x += dc.w;
248 /* determine maximum items */ 249 /* determine maximum items */
249 for(i = curr; i != next; i=i->right) { 250 for(i = curr; i != next; i=i->right) {
250 dc.w = textw(i->text); 251 dc.w = MIN(textw(i->text), mw / 3);
251 if(dc.w > mw / 3)
252 dc.w = mw / 3;
253 drawtext(i->text, (sel == i) ? dc.sel : dc.norm); 252 drawtext(i->text, (sel == i) ? dc.sel : dc.norm);
254 dc.x += dc.w; 253 dc.x += dc.w;
255 } 254 }
@@ -395,7 +394,8 @@ kpress(XKeyEvent * e) {
395 switch (ksym) { 394 switch (ksym) {
396 default: /* ignore other control sequences */ 395 default: /* ignore other control sequences */
397 return; 396 return;
398 case XK_bracketleft: 397 case XK_c:
398 case XK_C:
399 ksym = XK_Escape; 399 ksym = XK_Escape;
400 break; 400 break;
401 case XK_h: 401 case XK_h:
@@ -414,18 +414,16 @@ kpress(XKeyEvent * e) {
414 case XK_U: 414 case XK_U:
415 text[0] = 0; 415 text[0] = 0;
416 match(text); 416 match(text);
417 drawmenu();
418 break; 417 break;
419 case XK_w: 418 case XK_w:
420 case XK_W: 419 case XK_W:
421 if(len) { 420 if(cursor > 0) {
422 i = len - 1; 421 i = cursor;
423 while(i >= 0 && text[i] == ' ') 422 while(i-- > 0 && text[i] == ' ');
424 text[i--] = 0; 423 while(i-- > 0 && text[i] != ' ');
425 while(i >= 0 && text[i] != ' ') 424 memmove(text + i + 1, text + cursor, sizeof text - cursor);
426 text[i--] = 0; 425 cursor = i + 1;
427 match(text); 426 match(text);
428 drawmenu();
429 } 427 }
430 break; 428 break;
431 } 429 }
@@ -473,14 +471,14 @@ kpress(XKeyEvent * e) {
473 num = MIN(num, sizeof text - cursor); 471 num = MIN(num, sizeof text - cursor);
474 if(num && !iscntrl((int) buf[0])) { 472 if(num && !iscntrl((int) buf[0])) {
475 memmove(text + cursor + num, text + cursor, sizeof text - cursor - num); 473 memmove(text + cursor + num, text + cursor, sizeof text - cursor - num);
476 memmove(text + cursor, buf, num); 474 memcpy(text + cursor, buf, num);
477 cursor+=num; 475 cursor+=num;
478 match(text); 476 match(text);
479 } 477 }
480 break; 478 break;
481 case XK_BackSpace: 479 case XK_BackSpace:
482 if(cursor > 0) { 480 if(cursor > 0) {
483 memmove(text + cursor + -1, text + cursor, sizeof text - cursor); 481 memmove(text + cursor - 1, text + cursor, sizeof text - cursor + 1);
484 cursor--; 482 cursor--;
485 match(text); 483 match(text);
486 } 484 }
@@ -490,8 +488,10 @@ kpress(XKeyEvent * e) {
490 match(text); 488 match(text);
491 break; 489 break;
492 case XK_End: 490 case XK_End:
493 if(!item) 491 if(cursor < len) {
494 return; 492 cursor = len;
493 break;
494 }
495 while(next) { 495 while(next) {
496 sel = curr = next; 496 sel = curr = next;
497 calcoffsets(); 497 calcoffsets();
@@ -504,8 +504,10 @@ kpress(XKeyEvent * e) {
504 running = False; 504 running = False;
505 break; 505 break;
506 case XK_Home: 506 case XK_Home:
507 if(!item) 507 if(sel == item) {
508 return; 508 cursor = 0;
509 break;
510 }
509 sel = curr = item; 511 sel = curr = item;
510 calcoffsets(); 512 calcoffsets();
511 break; 513 break;
@@ -536,12 +538,10 @@ kpress(XKeyEvent * e) {
536 calcoffsets(); 538 calcoffsets();
537 break; 539 break;
538 case XK_Return: 540 case XK_Return:
539 if((e->state & ShiftMask) && *text) 541 if((e->state & ShiftMask) || !sel)
540 fprintf(stdout, "%s", text); 542 fprintf(stdout, "%s", text);
541 else if(sel) 543 else
542 fprintf(stdout, "%s", sel->text); 544 fprintf(stdout, "%s", sel->text);
543 else if(*text)
544 fprintf(stdout, "%s", text);
545 fflush(stdout); 545 fflush(stdout);
546 running = False; 546 running = False;
547 break; 547 break;
@@ -567,9 +567,6 @@ kpress(XKeyEvent * e) {
567 match(text); 567 match(text);
568 break; 568 break;
569 } 569 }
570 len = strlen(text);
571 cursor = MIN(cursor, len);
572 cursor = MAX(cursor, 0);
573 drawmenu(); 570 drawmenu();
574} 571}
575 572
@@ -620,13 +617,13 @@ readstdin(void) {
620 unsigned int len = 0, max = 0; 617 unsigned int len = 0, max = 0;
621 Item *i, *new; 618 Item *i, *new;
622 619
623 i = 0; 620 i = NULL;
624 while(fgets(buf, sizeof buf, stdin)) { 621 while(fgets(buf, sizeof buf, stdin)) {
625 len = strlen(buf); 622 len = strlen(buf);
626 if (buf[len - 1] == '\n') 623 if(buf[len-1] == '\n')
627 buf[len - 1] = 0; 624 buf[--len] = '\0';
628 if(!(p = strdup(buf))) 625 if(!(p = strdup(buf)))
629 eprint("fatal: could not strdup() %u bytes\n", strlen(buf)); 626 eprint("fatal: could not strdup() %u bytes\n", len);
630 if(max < len) { 627 if(max < len) {
631 maxname = p; 628 maxname = p;
632 max = len; 629 max = len;
@@ -734,13 +731,9 @@ setup(Bool topbar) {
734 if(!dc.font.set) 731 if(!dc.font.set)
735 XSetFont(dpy, dc.gc, dc.font.xfont->fid); 732 XSetFont(dpy, dc.gc, dc.font.xfont->fid);
736 if(maxname) 733 if(maxname)
737 cmdw = textw(maxname); 734 cmdw = MIN(textw(maxname), mw / 3);
738 if(cmdw > mw / 3)
739 cmdw = mw / 3;
740 if(prompt) 735 if(prompt)
741 promptw = textw(prompt); 736 promptw = MIN(textw(prompt), mw / 5);
742 if(promptw > mw / 5)
743 promptw = mw / 5;
744 text[0] = 0; 737 text[0] = 0;
745 match(text); 738 match(text);
746 XMapRaised(dpy, win); 739 XMapRaised(dpy, win);
@@ -799,7 +792,7 @@ main(int argc, char *argv[]) {
799 if(++i < argc) selfgcolor = argv[i]; 792 if(++i < argc) selfgcolor = argv[i];
800 } 793 }
801 else if(!strcmp(argv[i], "-v")) 794 else if(!strcmp(argv[i], "-v"))
802 eprint("dmenu-"VERSION", © 2006-2009 dmenu engineers, see LICENSE for details\n"); 795 eprint("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n");
803 else 796 else
804 eprint("usage: dmenu [-i] [-b] [-l <lines>] [-fn <font>] [-nb <color>] [-nf <color>]\n" 797 eprint("usage: dmenu [-i] [-b] [-l <lines>] [-fn <font>] [-nb <color>] [-nf <color>]\n"
805 " [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n"); 798 " [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");