aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnselm R Garbe <garbeam@gmail.com>2008-03-12 15:41:19 +0000
committerAnselm R Garbe <garbeam@gmail.com>2008-03-12 15:41:19 +0000
commit540a78761b26b2af4f47e46d27ad6406548c8a1c (patch)
tree55b3420e409efb6f5f58587f96a9601cdf930bd7
parent7804354106e713871f9e341d74d81eb0b1b00176 (diff)
removed ido-matching, changed behavior of -i meaning case insensitive matching now, commented -x, -y, -w arguments in dmenu.1
-rw-r--r--LICENSE2
-rw-r--r--config.h2
-rw-r--r--dmenu.116
-rw-r--r--dmenu.c53
4 files changed, 37 insertions, 36 deletions
diff --git a/LICENSE b/LICENSE
index 85970bb..2039f2a 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
1MIT/X Consortium License 1MIT/X Consortium License
2 2
3© 2006-2007 Anselm R. Garbe <garbeam at gmail dot com> 3© 2006-2008 Anselm R. Garbe <garbeam at gmail dot com>
4© 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com> 4© 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
5© 2006-2007 Michał Janeczek <janeczek at gmail dot com> 5© 2006-2007 Michał Janeczek <janeczek at gmail dot com>
6 6
diff --git a/config.h b/config.h
index 07e28e4..1afae6f 100644
--- a/config.h
+++ b/config.h
@@ -1,7 +1,7 @@
1/* See LICENSE file for copyright and license details. */ 1/* See LICENSE file for copyright and license details. */
2 2
3/* appearance */ 3/* appearance */
4#define FONT "-*-terminus-medium-*-*-*-*-*-*-*-*-*-*-*" 4#define FONT "-*-terminus-medium-r-normal-*-14-*-*-*-*-*-*-*"
5#define NORMBGCOLOR "#cccccc" 5#define NORMBGCOLOR "#cccccc"
6#define NORMFGCOLOR "#000000" 6#define NORMFGCOLOR "#000000"
7#define SELBGCOLOR "#0066ff" 7#define SELBGCOLOR "#0066ff"
diff --git a/dmenu.1 b/dmenu.1
index a8cd0fd..f772634 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -3,8 +3,10 @@
3dmenu \- dynamic menu 3dmenu \- dynamic menu
4.SH SYNOPSIS 4.SH SYNOPSIS
5.B dmenu 5.B dmenu
6.RB [ \-b ]
7.RB [ \-i ] 6.RB [ \-i ]
7.RB [ \-x " <x>"]
8.RB [ \-y " <y>"]
9.RB [ \-w " <width>"]
8.RB [ \-fn " <font>"] 10.RB [ \-fn " <font>"]
9.RB [ \-nb " <color>"] 11.RB [ \-nb " <color>"]
10.RB [ \-nf " <color>"] 12.RB [ \-nf " <color>"]
@@ -20,11 +22,17 @@ It manages huge amounts (up to 10.000 and more) of user defined menu items
20efficiently. 22efficiently.
21.SS Options 23.SS Options
22.TP 24.TP
23.B \-b 25.B \-x
24makes dmenu appear at the screen bottom (by default it appears at the screen top). 26defines the x coordinate dmenu appears at (0 by default).
27.TP
28.B \-y
29defines the y coordinate dmenu appears at (0 by default).
30.TP
31.B \-w
32defines the width of the dmenu window (screen width by default).
25.TP 33.TP
26.B \-i 34.B \-i
27makes dmenu match menu entries with ignoring intermediate characters. 35makes dmenu match menu entries case insensitively.
28.TP 36.TP
29.B \-fn <font> 37.B \-fn <font>
30defines the font. 38defines the font.
diff --git a/dmenu.c b/dmenu.c
index 3256f9c..864c8f0 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -56,8 +56,7 @@ void kpress(XKeyEvent * e);
56void match(char *pattern); 56void match(char *pattern);
57void readstdin(void); 57void readstdin(void);
58void run(void); 58void run(void);
59void setup(Bool bottom); 59void setup(int x, int y, int w);
60int strcaseido(const char *text, const char *pattern);
61char *cistrstr(const char *s, const char *sub); 60char *cistrstr(const char *s, const char *sub);
62unsigned int textnw(const char *text, unsigned int len); 61unsigned int textnw(const char *text, unsigned int len);
63unsigned int textw(const char *text); 62unsigned int textw(const char *text);
@@ -80,7 +79,6 @@ unsigned int mw, mh;
80unsigned int promptw = 0; 79unsigned int promptw = 0;
81unsigned int nitem = 0; 80unsigned int nitem = 0;
82unsigned int numlockmask = 0; 81unsigned int numlockmask = 0;
83Bool idomatch = False;
84Bool running = True; 82Bool running = True;
85Display *dpy; 83Display *dpy;
86DC dc = {0}; 84DC dc = {0};
@@ -91,6 +89,7 @@ Item *next = NULL;
91Item *prev = NULL; 89Item *prev = NULL;
92Item *curr = NULL; 90Item *curr = NULL;
93Window root, win; 91Window root, win;
92char *(*fstrstr)(const char *, const char *) = strstr;
94 93
95Item * 94Item *
96appenditem(Item *i, Item *last) { 95appenditem(Item *i, Item *last) {
@@ -512,12 +511,8 @@ match(char *pattern) {
512 if(!i->matched && !strncasecmp(pattern, i->text, plen)) 511 if(!i->matched && !strncasecmp(pattern, i->text, plen))
513 j = appenditem(i, j); 512 j = appenditem(i, j);
514 for(i = allitems; i; i = i->next) 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 j = appenditem(i, j); 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 curr = prev = next = sel = item; 516 curr = prev = next = sel = item;
522 calcoffsets(); 517 calcoffsets();
523} 518}
@@ -569,7 +564,7 @@ run(void) {
569} 564}
570 565
571void 566void
572setup(Bool bottom) { 567setup(int x, int y, int w) {
573 unsigned int i, j; 568 unsigned int i, j;
574 XModifierKeymap *modmap; 569 XModifierKeymap *modmap;
575 XSetWindowAttributes wa; 570 XSetWindowAttributes wa;
@@ -595,10 +590,9 @@ setup(Bool bottom) {
595 wa.override_redirect = 1; 590 wa.override_redirect = 1;
596 wa.background_pixmap = ParentRelative; 591 wa.background_pixmap = ParentRelative;
597 wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; 592 wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
598 mw = DisplayWidth(dpy, screen); 593 mw = w ? w : DisplayWidth(dpy, screen);
599 mh = dc.font.height + 2; 594 mh = dc.font.height + 2;
600 win = XCreateWindow(dpy, root, 0, 595 win = XCreateWindow(dpy, root, x, y, mw, mh, 0,
601 bottom ? DisplayHeight(dpy, screen) - mh : 0, mw, mh, 0,
602 DefaultDepth(dpy, screen), CopyFromParent, 596 DefaultDepth(dpy, screen), CopyFromParent,
603 DefaultVisual(dpy, screen), 597 DefaultVisual(dpy, screen),
604 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); 598 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
@@ -622,14 +616,6 @@ setup(Bool bottom) {
622 XMapRaised(dpy, win); 616 XMapRaised(dpy, win);
623} 617}
624 618
625int
626strcaseido(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
633char * 619char *
634cistrstr(const char *s, const char *sub) { 620cistrstr(const char *s, const char *sub) {
635 int c, csub; 621 int c, csub;
@@ -671,16 +657,13 @@ textw(const char *text) {
671 657
672int 658int
673main(int argc, char *argv[]) { 659main(int argc, char *argv[]) {
674 Bool bottom = False; 660 int x = 0, y = 0, w = 0;
675 unsigned int i; 661 unsigned int i;
676 662
677 /* command line args */ 663 /* command line args */
678 for(i = 1; i < argc; i++) 664 for(i = 1; i < argc; i++)
679 if(!strcmp(argv[i], "-b")) { 665 if(!strcmp(argv[i], "-i"))
680 bottom = True; 666 fstrstr = cistrstr;
681 }
682 else if(!strcmp(argv[i], "-i"))
683 idomatch = True;
684 else if(!strcmp(argv[i], "-fn")) { 667 else if(!strcmp(argv[i], "-fn")) {
685 if(++i < argc) font = argv[i]; 668 if(++i < argc) font = argv[i];
686 } 669 }
@@ -699,11 +682,21 @@ main(int argc, char *argv[]) {
699 else if(!strcmp(argv[i], "-sf")) { 682 else if(!strcmp(argv[i], "-sf")) {
700 if(++i < argc) selfg = argv[i]; 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 else if(!strcmp(argv[i], "-v")) 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 else 696 else
705 eprint("usage: dmenu [-b] [-i] [-fn <font>] [-nb <color>] [-nf <color>]\n" 697 eprint("usage: dmenu [-i] [-fn <font>] [-nb <color>] [-nf <color>]\n"
706 " [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n"); 698 " [-p <prompt>] [-sb <color>] [-sf <color>]\n"
699 " [-x <x>] [-y <y>] [-w <w>] [-v]\n");
707 setlocale(LC_CTYPE, ""); 700 setlocale(LC_CTYPE, "");
708 dpy = XOpenDisplay(0); 701 dpy = XOpenDisplay(0);
709 if(!dpy) 702 if(!dpy)
@@ -720,7 +713,7 @@ main(int argc, char *argv[]) {
720 readstdin(); 713 readstdin();
721 } 714 }
722 715
723 setup(bottom); 716 setup(x, y, w);
724 drawmenu(); 717 drawmenu();
725 XSync(dpy, False); 718 XSync(dpy, False);
726 run(); 719 run();