From 659ce3daaaac43ed08190d121de71bf236e0718d Mon Sep 17 00:00:00 2001 From: gotmor Date: Mon, 23 Jul 2007 07:21:24 +0000 Subject: added support for X bitmap icons git-svn-id: http://dzen.googlecode.com/svn/trunk@141 f2baff5b-bf2c-0410-a398-912abdc3d8b2 --- draw.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'draw.c') diff --git a/draw.c b/draw.c index 1ffdc12..a86e7ff 100644 --- a/draw.c +++ b/draw.c @@ -152,6 +152,9 @@ get_token(const char *line, int * t, char **tval) { void set_opts(int type, char * value, int reverse) { + unsigned int w, h, xh, yh; + Pixmap * bm; + switch(type) { case fg: reverse ? @@ -168,15 +171,15 @@ set_opts(int type, char * value, int reverse) { char * parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { + unsigned int bm_w, bm_h, bm_xh, bm_yh; int i, next_pos=0, j=0, px=0, py=0, xorig, h=0, tw, ow; char lbuf[MAX_LINE_LEN], *rbuf = NULL; int t=-1; char *tval=NULL; XGCValues gcv; - Drawable pm; + Drawable pm, bm; XRectangle r = { dzen.x, dzen.y, dzen.w, dzen.h}; - /* parse line and return the text without control commands*/ if(nodraw) { rbuf = emalloc(MAX_LINE_LEN); @@ -245,12 +248,23 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { strcat(rbuf, lbuf); } else { - if(t != -1 && tval) - set_opts(t, tval, reverse); + if(t != -1 && tval){ + if(t == icon) { + if((XReadBitmapFile(dzen.dpy, pm, tval, &bm_w, + &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess) + && ((h/2 + px + bm_w) < dzen.w)) { + XCopyPlane(dzen.dpy, bm, pm, dzen.tgc, + 0, 0, bm_w, bm_h, px, 0, 1); + px += bm_w; + } + } + else + set_opts(t, tval, reverse); + } /* check if text is longer than window's width */ ow = j; tw = textnw(lbuf, strlen(lbuf)); - while((tw + px) > (dzen.w - h)) { + while( ((tw + px) > (dzen.w - h)) && j>=0) { lbuf[--j] = '\0'; tw = textnw(lbuf, strlen(lbuf)); } @@ -289,12 +303,23 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { strcat(rbuf, lbuf); } else { - if(t != -1 && tval) - set_opts(t, tval, reverse); + if(t != -1 && tval){ + if(t == icon) { + if(XReadBitmapFile(dzen.dpy, pm, tval, &bm_w, + &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess + && (h/2 + px + bm_w < dzen.w)) { + XCopyPlane(dzen.dpy, bm, pm, dzen.tgc, + 0, 0, bm_w, bm_h, px, 0, 1); + px += bm_w; + } + } + else + set_opts(t, tval, reverse); + } /* check if text is longer than window's width */ ow = j; tw = textnw(lbuf, strlen(lbuf)); - while((tw + px) > (dzen.w - h)) { + while( ((tw + px) > (dzen.w - h)) && j>=0) { lbuf[--j] = '\0'; tw = textnw(lbuf, strlen(lbuf)); } -- cgit v1.2.3-54-g00ecf