diff options
| -rw-r--r-- | draw.c | 12 |
1 files changed, 10 insertions, 2 deletions
| @@ -26,7 +26,7 @@ drawtext(const char *text, Bool invert) | |||
| 26 | { | 26 | { |
| 27 | int x, y, w, h; | 27 | int x, y, w, h; |
| 28 | static char buf[256]; | 28 | static char buf[256]; |
| 29 | unsigned int len; | 29 | unsigned int len, olen; |
| 30 | XGCValues gcv; | 30 | XGCValues gcv; |
| 31 | XPoint points[5]; | 31 | XPoint points[5]; |
| 32 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; | 32 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
| @@ -51,7 +51,7 @@ drawtext(const char *text, Bool invert) | |||
| 51 | return; | 51 | return; |
| 52 | 52 | ||
| 53 | w = 0; | 53 | w = 0; |
| 54 | len = strlen(text); | 54 | olen = len = strlen(text); |
| 55 | if(len >= sizeof(buf)) | 55 | if(len >= sizeof(buf)) |
| 56 | len = sizeof(buf) - 1; | 56 | len = sizeof(buf) - 1; |
| 57 | memcpy(buf, text, len); | 57 | memcpy(buf, text, len); |
| @@ -64,6 +64,14 @@ drawtext(const char *text, Bool invert) | |||
| 64 | /* shorten text if necessary */ | 64 | /* shorten text if necessary */ |
| 65 | while(len && (w = textnw(buf, len)) > dc.w - h) | 65 | while(len && (w = textnw(buf, len)) > dc.w - h) |
| 66 | buf[--len] = 0; | 66 | buf[--len] = 0; |
| 67 | if(len < olen) { | ||
| 68 | if(len > 3) | ||
| 69 | memcpy(buf + len - 4, "...\0", 4); | ||
| 70 | else if(len > 2) | ||
| 71 | memcpy(buf + len - 3, "..\0", 3); | ||
| 72 | else if(len > 1) | ||
| 73 | memcpy(buf + len - 2, ".\0", 2); | ||
| 74 | } | ||
| 67 | 75 | ||
| 68 | if(w > dc.w) | 76 | if(w > dc.w) |
| 69 | return; /* too long */ | 77 | return; /* too long */ |
