]> git.pld-linux.org Git - packages/dmenu.git/blob - dmenu-vertical.patch
- xmms patch, based on http://tools.suckless.org/dmenu/patches/dmenu_xmms.diff
[packages/dmenu.git] / dmenu-vertical.patch
1 # dmenu-4.0 vertical patch
2 #
3 # assembled by meillo@marmaro.de
4 #
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
8
9
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
13 @@ -1,5 +1,5 @@
14  # dmenu version
15 -VERSION = 4.0
16 +VERSION = 4.0-vertical
17  
18  # Customize below to fit your system
19  
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
24  .B dmenu
25  .RB [ \-i ]
26  .RB [ \-b ]
27 +.RB [ \-l " <lines>"]
28  .RB [ \-fn " <font>"]
29  .RB [ \-nb " <color>"]
30  .RB [ \-nf " <color>"]
31 @@ -26,6 +27,10 @@ makes dmenu match menu entries case inse
32  .B \-b
33  defines that dmenu appears at the bottom.
34  .TP
35 +.B \-l <lines>
36 +activates vertical list mode.
37 +The given number of lines will be displayed. Window height will get adjusted.
38 +.TP
39  .B \-fn <font>
40  defines the font.
41  .TP
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.
45  .TP
46 -.B Left/Right (Mod1\-h/Mod1\-l)
47 +.B Left/Right (Up/Down) (Mod1\-h/Mod1\-l)
48  Select the previous/next item.
49  .TP
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 {
55  
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;
77  
78  void
79  appenditem(Item *i, Item **list, Item **last) {
80 @@ -101,7 +107,7 @@ appenditem(Item *i, Item **list, Item **
81  }
82  
83  void
84 -calcoffsets(void) {
85 +calcoffsetsh(void) {
86         int tw;
87         unsigned int w;
88  
89 @@ -127,6 +133,26 @@ calcoffsets(void) {
90         }
91  }
92  
93 +void
94 +calcoffsetsv(void) {
95 +       static unsigned int w;
96 +
97 +       if(!curr)
98 +               return;
99 +       w = (dc.font.height + 2) * (lines + 1);
100 +       for(next = curr; next; next=next->right) {
101 +               w -= dc.font.height + 2;
102 +               if(w <= 0)
103 +                       break;
104 +       }
105 +       w = (dc.font.height + 2) * (lines + 1);
106 +       for(prev = curr; prev && prev->left; prev=prev->left) {
107 +               w -= dc.font.height + 2;
108 +               if(w <= 0)
109 +                       break;
110 +       }
111 +}
112 +
113  char *
114  cistrstr(const char *s, const char *sub) {
115         int c, csub;
116 @@ -171,7 +197,7 @@ cleanup(void) {
117  }
118  
119  void
120 -drawmenu(void) {
121 +drawmenuh(void) {
122         Item *i;
123  
124         dc.x = 0;
125 @@ -212,6 +238,39 @@ drawmenu(void) {
126  }
127  
128  void
129 +drawmenuv(void) {
130 +       Item *i;
131 +
132 +       dc.x = 0;
133 +       dc.y = 0;
134 +       dc.w = mw;
135 +       dc.h = mh;
136 +       drawtext(NULL, dc.norm);
137 +       /* print prompt? */
138 +       if(promptw) {
139 +               dc.w = promptw;
140 +               drawtext(prompt, dc.sel);
141 +       }
142 +       dc.x += promptw;
143 +       dc.w = mw - promptw;
144 +       /* print command */
145 +       drawtext(text[0] ? text : NULL, dc.norm);
146 +       if(curr) {
147 +               dc.x = 0;
148 +               dc.w = mw;
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;
154 +               }
155 +               drawtext(NULL, dc.norm);
156 +       }
157 +       XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
158 +       XFlush(dpy);
159 +}
160 +
161 +void
162  drawtext(const char *text, unsigned long col[ColLast]) {
163         char buf[256];
164         int i, x, y, h, len, olen;
165 @@ -222,8 +281,8 @@ drawtext(const char *text, unsigned long
166         if(!text)
167                 return;
168         olen = strlen(text);
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;
173         x = dc.x + (h / 2);
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) {
177                 calcoffsets();
178                 break;
179         case XK_Left:
180 +       case XK_Up:
181                 if(!(sel && sel->left))
182                         return;
183                 sel=sel->left;
184 @@ -457,6 +517,7 @@ kpress(XKeyEvent * e) {
185                 running = False;
186                 break;
187         case XK_Right:
188 +       case XK_Down:
189                 if(!(sel && sel->right))
190                         return;
191                 sel=sel->right;
192 @@ -598,6 +659,7 @@ setup(Bool topbar) {
193  
194         /* menu window geometry */
195         mh = dc.font.height + 2;
196 +       mh = vlist ? mh * (lines+1) : mh;
197  #if XINERAMA
198         if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
199                 i = 0;
200 @@ -676,6 +738,12 @@ main(int argc, char *argv[]) {
201                 }
202                 else if(!strcmp(argv[i], "-b"))
203                         topbar = False;
204 +               else if(!strcmp(argv[i], "-l")) {
205 +                       vlist = True;
206 +                       calcoffsets = calcoffsetsv;
207 +                       drawmenu = drawmenuv;
208 +                       if(++i < argc) lines += atoi(argv[i]);
209 +               }
210                 else if(!strcmp(argv[i], "-fn")) {
211                         if(++i < argc) font = argv[i];
212                 }
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");
216                 else
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");
This page took 0.098705 seconds and 3 git commands to generate.