diff options
-rw-r--r-- | config.mk | 2 | ||||
-rw-r--r-- | dmenu.c | 31 |
2 files changed, 11 insertions, 22 deletions
@@ -1,5 +1,5 @@ | |||
1 | # dmenu version | 1 | # dmenu version |
2 | VERSION = 3.8 | 2 | VERSION = 3.9 |
3 | 3 | ||
4 | # Customize below to fit your system | 4 | # Customize below to fit your system |
5 | 5 | ||
@@ -17,6 +17,7 @@ | |||
17 | /* macros */ | 17 | /* macros */ |
18 | #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) | 18 | #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) |
19 | #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) | 19 | #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) |
20 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | ||
20 | 21 | ||
21 | /* enums */ | 22 | /* enums */ |
22 | enum { ColFG, ColBG, ColLast }; | 23 | enum { ColFG, ColBG, ColLast }; |
@@ -212,37 +213,25 @@ drawmenu(void) { | |||
212 | 213 | ||
213 | void | 214 | void |
214 | drawtext(const char *text, unsigned long col[ColLast]) { | 215 | drawtext(const char *text, unsigned long col[ColLast]) { |
215 | int x, y, w, h; | 216 | int i, x, y, h, len, olen; |
216 | static char buf[256]; | 217 | char buf[256]; |
217 | unsigned int len, olen; | ||
218 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; | 218 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
219 | 219 | ||
220 | XSetForeground(dpy, dc.gc, col[ColBG]); | 220 | XSetForeground(dpy, dc.gc, col[ColBG]); |
221 | XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); | 221 | XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); |
222 | if(!text) | 222 | if(!text) |
223 | return; | 223 | return; |
224 | w = 0; | 224 | olen = strlen(text); |
225 | olen = len = strlen(text); | ||
226 | if(len >= sizeof buf) | ||
227 | len = sizeof buf - 1; | ||
228 | memcpy(buf, text, len); | ||
229 | buf[len] = 0; | ||
230 | h = dc.font.ascent + dc.font.descent; | 225 | h = dc.font.ascent + dc.font.descent; |
231 | y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; | 226 | y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; |
232 | x = dc.x + (h / 2); | 227 | x = dc.x + (h / 2); |
233 | /* shorten text if necessary */ | 228 | /* shorten text if necessary */ |
234 | while(len && (w = textnw(buf, len)) > dc.w - h) | 229 | for(len = MIN(olen, sizeof buf); len && (i = textnw(buf, len)) > dc.w - h; len--); |
235 | buf[--len] = 0; | 230 | if(!len) |
236 | if(len < olen) { | 231 | return; |
237 | if(len > 1) | 232 | memcpy(buf, text, len); |
238 | buf[len - 1] = '.'; | 233 | if(len < olen) |
239 | if(len > 2) | 234 | for(i = len; i && i > len - 3; buf[--i] = '.'); |
240 | buf[len - 2] = '.'; | ||
241 | if(len > 3) | ||
242 | buf[len - 3] = '.'; | ||
243 | } | ||
244 | if(w > dc.w) | ||
245 | return; /* too long */ | ||
246 | XSetForeground(dpy, dc.gc, col[ColFG]); | 235 | XSetForeground(dpy, dc.gc, col[ColFG]); |
247 | if(dc.font.set) | 236 | if(dc.font.set) |
248 | XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); | 237 | XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); |