| 56 |
56 |
|
void match(char *pattern); |
| 57 |
57 |
|
void readstdin(void); |
| 58 |
58 |
|
void run(void); |
| 59 |
|
- |
void setup(Bool bottom); |
| 60 |
|
- |
int strcaseido(const char *text, const char *pattern); |
|
59 |
+ |
void setup(int x, int y, int w); |
| 61 |
60 |
|
char *cistrstr(const char *s, const char *sub); |
| 62 |
61 |
|
unsigned int textnw(const char *text, unsigned int len); |
| 63 |
62 |
|
unsigned int textw(const char *text); |
|
| 80 |
79 |
|
unsigned int promptw = 0; |
| 81 |
80 |
|
unsigned int nitem = 0; |
| 82 |
81 |
|
unsigned int numlockmask = 0; |
| 83 |
|
- |
Bool idomatch = False; |
| 84 |
82 |
|
Bool running = True; |
| 85 |
83 |
|
Display *dpy; |
| 86 |
84 |
|
DC dc = {0}; |
|
| 91 |
89 |
|
Item *prev = NULL; |
| 92 |
90 |
|
Item *curr = NULL; |
| 93 |
91 |
|
Window root, win; |
|
92 |
+ |
char *(*fstrstr)(const char *, const char *) = strstr; |
| 94 |
93 |
|
|
| 95 |
94 |
|
Item * |
| 96 |
95 |
|
appenditem(Item *i, Item *last) { |
|
| 512 |
511 |
|
if(!i->matched && !strncasecmp(pattern, i->text, plen)) |
| 513 |
512 |
|
j = appenditem(i, j); |
| 514 |
513 |
|
for(i = allitems; i; i = i->next) |
| 515 |
|
- |
if(!i->matched && cistrstr(i->text, pattern)) |
|
514 |
+ |
if(!i->matched && fstrstr(i->text, pattern)) |
| 516 |
515 |
|
j = appenditem(i, j); |
| 517 |
|
- |
if(idomatch) |
| 518 |
|
- |
for(i = allitems; i; i = i->next) |
| 519 |
|
- |
if(!i->matched && strcaseido(i->text, pattern)) |
| 520 |
|
- |
j = appenditem(i, j); |
| 521 |
516 |
|
curr = prev = next = sel = item; |
| 522 |
517 |
|
calcoffsets(); |
| 523 |
518 |
|
} |
|
| 569 |
564 |
|
} |
| 570 |
565 |
|
|
| 571 |
566 |
|
void |
| 572 |
|
- |
setup(Bool bottom) { |
|
567 |
+ |
setup(int x, int y, int w) { |
| 573 |
568 |
|
unsigned int i, j; |
| 574 |
569 |
|
XModifierKeymap *modmap; |
| 575 |
570 |
|
XSetWindowAttributes wa; |
|
| 595 |
590 |
|
wa.override_redirect = 1; |
| 596 |
591 |
|
wa.background_pixmap = ParentRelative; |
| 597 |
592 |
|
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; |
| 598 |
|
- |
mw = DisplayWidth(dpy, screen); |
|
593 |
+ |
mw = w ? w : DisplayWidth(dpy, screen); |
| 599 |
594 |
|
mh = dc.font.height + 2; |
| 600 |
|
- |
win = XCreateWindow(dpy, root, 0, |
| 601 |
|
- |
bottom ? DisplayHeight(dpy, screen) - mh : 0, mw, mh, 0, |
|
595 |
+ |
win = XCreateWindow(dpy, root, x, y, mw, mh, 0, |
| 602 |
596 |
|
DefaultDepth(dpy, screen), CopyFromParent, |
| 603 |
597 |
|
DefaultVisual(dpy, screen), |
| 604 |
598 |
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); |
|
| 621 |
615 |
|
match(text); |
| 622 |
616 |
|
XMapRaised(dpy, win); |
| 623 |
617 |
|
} |
| 624 |
|
- |
|
| 625 |
|
- |
int |
| 626 |
|
- |
strcaseido(const char *text, const char *pattern) { |
| 627 |
|
- |
for(; *text && *pattern; text++) |
| 628 |
|
- |
if(tolower((int)*text) == tolower((int)*pattern)) |
| 629 |
|
- |
pattern++; |
| 630 |
|
- |
return !*pattern; |
| 631 |
|
- |
} |
| 632 |
618 |
|
|
| 633 |
619 |
|
char * |
| 634 |
620 |
|
cistrstr(const char *s, const char *sub) { |
|
| 671 |
657 |
|
|
| 672 |
658 |
|
int |
| 673 |
659 |
|
main(int argc, char *argv[]) { |
| 674 |
|
- |
Bool bottom = False; |
|
660 |
+ |
int x = 0, y = 0, w = 0; |
| 675 |
661 |
|
unsigned int i; |
| 676 |
662 |
|
|
| 677 |
663 |
|
/* command line args */ |
| 678 |
664 |
|
for(i = 1; i < argc; i++) |
| 679 |
|
- |
if(!strcmp(argv[i], "-b")) { |
| 680 |
|
- |
bottom = True; |
| 681 |
|
- |
} |
| 682 |
|
- |
else if(!strcmp(argv[i], "-i")) |
| 683 |
|
- |
idomatch = True; |
|
665 |
+ |
if(!strcmp(argv[i], "-i")) |
|
666 |
+ |
fstrstr = cistrstr; |
| 684 |
667 |
|
else if(!strcmp(argv[i], "-fn")) { |
| 685 |
668 |
|
if(++i < argc) font = argv[i]; |
| 686 |
669 |
|
} |
|
| 699 |
682 |
|
else if(!strcmp(argv[i], "-sf")) { |
| 700 |
683 |
|
if(++i < argc) selfg = argv[i]; |
| 701 |
684 |
|
} |
|
685 |
+ |
else if(!strcmp(argv[i], "-x")) { |
|
686 |
+ |
if(++i < argc) x = atoi(argv[i]); |
|
687 |
+ |
} |
|
688 |
+ |
else if(!strcmp(argv[i], "-y")) { |
|
689 |
+ |
if(++i < argc) y = atoi(argv[i]); |
|
690 |
+ |
} |
|
691 |
+ |
else if(!strcmp(argv[i], "-w")) { |
|
692 |
+ |
if(++i < argc) w = atoi(argv[i]); |
|
693 |
+ |
} |
| 702 |
694 |
|
else if(!strcmp(argv[i], "-v")) |
| 703 |
|
- |
eprint("dmenu-"VERSION", © 2006-2007 Anselm R. Garbe, Sander van Dijk, Michał Janeczek\n"); |
|
695 |
+ |
eprint("dmenu-"VERSION", © 2006-2008 dmenu engineers, see LICENSE for details\n"); |
| 704 |
696 |
|
else |
| 705 |
|
- |
eprint("usage: dmenu [-b] [-i] [-fn <font>] [-nb <color>] [-nf <color>]\n" |
| 706 |
|
- |
" [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n"); |
|
697 |
+ |
eprint("usage: dmenu [-i] [-fn <font>] [-nb <color>] [-nf <color>]\n" |
|
698 |
+ |
" [-p <prompt>] [-sb <color>] [-sf <color>]\n" |
|
699 |
+ |
" [-x <x>] [-y <y>] [-w <w>] [-v]\n"); |
| 707 |
700 |
|
setlocale(LC_CTYPE, ""); |
| 708 |
701 |
|
dpy = XOpenDisplay(0); |
| 709 |
702 |
|
if(!dpy) |
|
| 720 |
713 |
|
readstdin(); |
| 721 |
714 |
|
} |
| 722 |
715 |
|
|
| 723 |
|
- |
setup(bottom); |
|
716 |
+ |
setup(x, y, w); |
| 724 |
717 |
|
drawmenu(); |
| 725 |
718 |
|
XSync(dpy, False); |
| 726 |
719 |
|
run(); |