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 --- README | 5 +++++ bitmaps/battery.xbm | 6 ++++++ bitmaps/envelope.xbm | 6 ++++++ bitmaps/volume.xbm | 6 ++++++ draw.c | 41 +++++++++++++++++++++++++++++++++-------- 5 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 bitmaps/battery.xbm create mode 100644 bitmaps/envelope.xbm create mode 100644 bitmaps/volume.xbm diff --git a/README b/README index 52a9253..de14378 100644 --- a/README +++ b/README @@ -156,6 +156,11 @@ A6: Yes, both vertical and horizontal menus are supported. See "(3) Menu" for further details. +Q7; What is the expected format to the '-fn' option? + +A7: Run 'xfontsel' or 'xlsfonts'. These should come with your X + distribution by default. + Termination: diff --git a/bitmaps/battery.xbm b/bitmaps/battery.xbm new file mode 100644 index 0000000..745c389 --- /dev/null +++ b/bitmaps/battery.xbm @@ -0,0 +1,6 @@ +#define battery_width 16 +#define battery_height 16 +static unsigned char battery_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x1f, + 0xfc, 0x11, 0xfc, 0x71, 0xfc, 0x71, 0xfc, 0x71, 0xfc, 0x11, 0xfc, 0x1f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/bitmaps/envelope.xbm b/bitmaps/envelope.xbm new file mode 100644 index 0000000..83d1120 --- /dev/null +++ b/bitmaps/envelope.xbm @@ -0,0 +1,6 @@ +#define mail_width 16 +#define mail_height 16 +static unsigned char mail_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0x0c, 0x30, + 0x1c, 0x38, 0x34, 0x2c, 0xc4, 0x23, 0x84, 0x21, 0x04, 0x20, 0x04, 0x20, + 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/bitmaps/volume.xbm b/bitmaps/volume.xbm new file mode 100644 index 0000000..b4ee0ec --- /dev/null +++ b/bitmaps/volume.xbm @@ -0,0 +1,6 @@ +#define volume_width 16 +#define volume_height 16 +static unsigned char volume_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x1b, 0x60, 0x1b, + 0x60, 0x1b, 0x6c, 0x1b, 0x6c, 0x1b, 0x6c, 0x1b, 0x60, 0x1b, 0x60, 0x1b, + 0x00, 0x1b, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00}; 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