Xinqi Bao's Git
projects
/
dmenu.git
/ diff
summary
|
log
|
commit
|
diff
|
tree
raw
|
patch
|
inline
| side by side (parent:
2f3068f
)
fixed string cutting
author
Anselm R.Garbe <
[email protected]
>
Mon, 14 Aug 2006 06:52:28 +0000
(08:52 +0200)
committer
Anselm R.Garbe <
[email protected]
>
Mon, 14 Aug 2006 06:52:28 +0000
(08:52 +0200)
draw.c
diff
|
blob
|
history
diff --git
a/draw.c
b/draw.c
index
383e130
..
066a0bf
100644
(file)
--- a/
draw.c
+++ b/
draw.c
@@
-28,7
+28,7
@@
drawtext(const char *text, Bool invert, Bool border)
{
int x, y, w, h;
static char buf[256];
{
int x, y, w, h;
static char buf[256];
- unsigned int len;
+ unsigned int len
, olen
;
XGCValues gcv;
XPoint points[5];
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
XGCValues gcv;
XPoint points[5];
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
@@
-56,7
+56,7
@@
drawtext(const char *text, Bool invert, Bool border)
if(!text)
return;
if(!text)
return;
- len = strlen(text);
+
olen =
len = strlen(text);
if(len >= sizeof(buf))
len = sizeof(buf) - 1;
memcpy(buf, text, len);
if(len >= sizeof(buf))
len = sizeof(buf) - 1;
memcpy(buf, text, len);
@@
-69,6
+69,14
@@
drawtext(const char *text, Bool invert, Bool border)
/* shorten text if necessary */
while(len && (w = textnw(buf, len)) > dc.w - h)
buf[--len] = 0;
/* shorten text if necessary */
while(len && (w = textnw(buf, len)) > dc.w - h)
buf[--len] = 0;
+ if(len < olen) {
+ if(len > 3)
+ memcpy(buf + len - 4, "...\0", 4);
+ else if(len > 2)
+ memcpy(buf + len - 3, "..\0", 3);
+ else if(len > 1)
+ memcpy(buf + len - 2, ".\0", 2);
+ }
if(w > dc.w)
return; /* too long */
if(w > dc.w)
return; /* too long */