1 # dmenu-4.0 vertical patch
3 # assembled by meillo@marmaro.de
5 # this is a minimal version of fresch's patch
6 # http://schiewek.net/fresch/dmenu-3.9-fresch-3.diff
7 # http://bbs.archlinux.org/viewtopic.php?id=54086
10 diff -up dmenu-4.0/config.mk dmenu-v/config.mk
11 --- dmenu-4.0/config.mk 2009-04-18 13:50:04.000000000 +0200
12 +++ dmenu-v/config.mk 2009-06-03 10:48:35.000000000 +0200
16 +VERSION = 4.0-vertical
18 # Customize below to fit your system
20 diff -up dmenu-4.0/dmenu.1 dmenu-v/dmenu.1
21 --- dmenu-4.0/dmenu.1 2009-04-18 13:50:04.000000000 +0200
22 +++ dmenu-v/dmenu.1 2009-06-03 12:54:25.000000000 +0200
23 @@ -5,6 +5,7 @@ dmenu \- dynamic menu
27 +.RB [ \-l " <lines>"]
29 .RB [ \-nb " <color>"]
30 .RB [ \-nf " <color>"]
31 @@ -26,6 +27,10 @@ makes dmenu match menu entries case inse
33 defines that dmenu appears at the bottom.
36 +activates vertical list mode.
37 +The given number of lines will be displayed. Window height will get adjusted.
42 @@ -57,7 +62,7 @@ dmenu is completely controlled by the ke
43 Appends the character to the text in the input field. This works as a filter:
44 only items containing this text will be displayed.
46 -.B Left/Right (Mod1\-h/Mod1\-l)
47 +.B Left/Right (Up/Down) (Mod1\-h/Mod1\-l)
48 Select the previous/next item.
50 .B PageUp/PageDown (Mod1\-k/Mod1\-j)
51 diff -up dmenu-4.0/dmenu.c dmenu-v/dmenu.c
52 --- dmenu-4.0/dmenu.c 2009-04-18 13:50:04.000000000 +0200
53 +++ dmenu-v/dmenu.c 2009-06-03 12:31:00.000000000 +0200
54 @@ -47,10 +47,12 @@ struct Item {
56 /* forward declarations */
57 static void appenditem(Item *i, Item **list, Item **last);
58 -static void calcoffsets(void);
59 +static void calcoffsetsh(void);
60 +static void calcoffsetsv(void);
61 static char *cistrstr(const char *s, const char *sub);
62 static void cleanup(void);
63 -static void drawmenu(void);
64 +static void drawmenuh(void);
65 +static void drawmenuv(void);
66 static void drawtext(const char *text, unsigned long col[ColLast]);
67 static void eprint(const char *errstr, ...);
68 static unsigned long getcolor(const char *colstr);
69 @@ -88,6 +90,10 @@ static Item *curr = NULL;
70 static Window root, win;
71 static int (*fstrncmp)(const char *, const char *, size_t n) = strncmp;
72 static char *(*fstrstr)(const char *, const char *) = strstr;
73 +static Bool vlist = False;
74 +static unsigned int lines = 0;
75 +static void (*calcoffsets)(void) = calcoffsetsh;
76 +static void (*drawmenu)(void) = drawmenuh;
79 appenditem(Item *i, Item **list, Item **last) {
80 @@ -101,7 +107,7 @@ appenditem(Item *i, Item **list, Item **
89 @@ -127,6 +133,26 @@ calcoffsets(void) {
95 + static unsigned int w;
99 + w = (dc.font.height + 2) * (lines + 1);
100 + for(next = curr; next; next=next->right) {
101 + w -= dc.font.height + 2;
105 + w = (dc.font.height + 2) * (lines + 1);
106 + for(prev = curr; prev && prev->left; prev=prev->left) {
107 + w -= dc.font.height + 2;
114 cistrstr(const char *s, const char *sub) {
116 @@ -171,7 +197,7 @@ cleanup(void) {
125 @@ -212,6 +238,39 @@ drawmenu(void) {
136 + drawtext(NULL, dc.norm);
137 + /* print prompt? */
140 + drawtext(prompt, dc.sel);
143 + dc.w = mw - promptw;
144 + /* print command */
145 + drawtext(text[0] ? text : NULL, dc.norm);
149 + dc.y += dc.font.height + 2;
150 + /* determine maximum items */
151 + for(i = curr; i != next; i=i->right) {
152 + drawtext(i->text, (sel == i) ? dc.sel : dc.norm);
153 + dc.y += dc.font.height + 2;
155 + drawtext(NULL, dc.norm);
157 + XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
162 drawtext(const char *text, unsigned long col[ColLast]) {
164 int i, x, y, h, len, olen;
165 @@ -222,8 +281,8 @@ drawtext(const char *text, unsigned long
169 - h = dc.font.ascent + dc.font.descent;
170 - y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
171 + h = dc.font.height;
172 + y = dc.y + ((h+2) / 2) - (h / 2) + dc.font.ascent;
174 /* shorten text if necessary */
175 for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--);
176 @@ -426,6 +485,7 @@ kpress(XKeyEvent * e) {
181 if(!(sel && sel->left))
184 @@ -457,6 +517,7 @@ kpress(XKeyEvent * e) {
189 if(!(sel && sel->right))
192 @@ -598,6 +659,7 @@ setup(Bool topbar) {
194 /* menu window geometry */
195 mh = dc.font.height + 2;
196 + mh = vlist ? mh * (lines+1) : mh;
198 if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
200 @@ -676,6 +738,12 @@ main(int argc, char *argv[]) {
202 else if(!strcmp(argv[i], "-b"))
204 + else if(!strcmp(argv[i], "-l")) {
206 + calcoffsets = calcoffsetsv;
207 + drawmenu = drawmenuv;
208 + if(++i < argc) lines += atoi(argv[i]);
210 else if(!strcmp(argv[i], "-fn")) {
211 if(++i < argc) font = argv[i];
213 @@ -697,7 +765,7 @@ main(int argc, char *argv[]) {
214 else if(!strcmp(argv[i], "-v"))
215 eprint("dmenu-"VERSION", © 2006-2008 dmenu engineers, see LICENSE for details\n");
217 - eprint("usage: dmenu [-i] [-b] [-fn <font>] [-nb <color>] [-nf <color>]\n"
218 + eprint("usage: dmenu [-i] [-b] [-l <lines>] [-fn <font>] [-nb <color>] [-nf <color>]\n"
219 " [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
220 if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
221 fprintf(stderr, "warning: no locale support\n");