aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2>2008-02-01 17:49:00 +0000
committergotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2>2008-02-01 17:49:00 +0000
commit63cefbcb3609fc32a1187b28ac32b007d3b38f9e (patch)
treec1757e81864808d2349380a8692ea7eb42c7a566
parent9b2e296cb82a5e800e58b3c5eea56f8dd25ae632 (diff)
downloaddzen-63cefbcb3609fc32a1187b28ac32b007d3b38f9e.tar.gz
dzen-63cefbcb3609fc32a1187b28ac32b007d3b38f9e.zip
added a simple pixmap cache
git-svn-id: http://dzen.googlecode.com/svn/trunk@214 f2baff5b-bf2c-0410-a398-912abdc3d8b2
-rw-r--r--config.mk10
-rw-r--r--draw.c137
-rw-r--r--gadgets/dbar.c52
3 files changed, 137 insertions, 62 deletions
diff --git a/config.mk b/config.mk
index e029235..5512b70 100644
--- a/config.mk
+++ b/config.mk
@@ -1,5 +1,5 @@
# dzen version
-VERSION = 0.8.5
+VERSION = 0.8.5-svn
# Customize below to fit your system
@@ -19,8 +19,8 @@ INCS = -I. -I/usr/include -I${X11INC}
# Comment : Add # to the beginning of the respective lines
# Option 1: No Xinerama no XPM
-LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
-CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
+#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
+#CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
# Option 2: No Xinerama with XPM
#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXpm
@@ -31,8 +31,8 @@ CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
#CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XINERAMA
# Option 4: With Xinerama and XPM
-#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXinerama -lXpm
-#CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XINERAMA -DDZEN_XPM
+LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXinerama -lXpm
+CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XINERAMA -DDZEN_XPM
# END of feature configuration
diff --git a/draw.c b/draw.c
index d6d13f1..02aad95 100644
--- a/draw.c
+++ b/draw.c
@@ -14,7 +14,17 @@
#endif
#define ARGLEN 256
+#define MAX_ICON_CACHE 32
+typedef struct ICON_C {
+ char name[ARGLEN];
+ Pixmap p;
+
+ int w, h;
+} icon_c;
+
+icon_c icons[MAX_ICON_CACHE];
+int icon_cnt;
int otx;
/* command types for the in-text parser */
@@ -294,6 +304,34 @@ get_pos_vals(char *s, int *d, int *a) {
return ret;
}
+static int
+find_icon(const char* name) {
+ int i;
+
+ for(i=0; i < MAX_ICON_CACHE; i++)
+ if(!strncmp(icons[i].name, name, ARGLEN))
+ return i;
+
+ return -1;
+}
+
+static void
+insert_icon(const char* name, Pixmap pm, int w, int h) {
+ int i;
+
+ if(icon_cnt >= MAX_ICON_CACHE)
+ icon_cnt = 0;
+
+ if(icons[icon_cnt].p)
+ XFreePixmap(dzen.dpy, icons[icon_cnt].p);
+
+ strncpy(icons[icon_cnt].name, name, ARGLEN);
+ icons[icon_cnt].w = w;
+ icons[icon_cnt].h = h;
+ icons[icon_cnt].p = pm;
+ icon_cnt++;
+}
+
char *
parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
/* bitmaps */
@@ -328,6 +366,9 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
XpmColorSymbol xpms;
#endif
+ /* icon cache */
+ int ip;
+
/* parse line and return the text without control commands */
if(nodraw) {
rbuf = emalloc(MAX_LINE_LEN);
@@ -414,26 +455,36 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
if(t != -1 && tval) {
switch(t) {
case icon:
- if(XReadBitmapFile(dzen.dpy, *pm, tval, &bm_w,
- &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess
- && (h/2 + px + (signed)bm_w < dzen.w)) {
- setcolor(pm, px, bm_w, lastfg, lastbg, reverse, nobg);
- XCopyPlane(dzen.dpy, bm, *pm, dzen.tgc,
- 0, 0, bm_w, bm_h, px, set_posy ? py :
- (dzen.line_height >= (signed)bm_h ? (dzen.line_height - bm_h)/2 : 0), 1);
- XFreePixmap(dzen.dpy, bm);
- px += bm_w;
- }
+ if( (ip=find_icon(tval)) != -1) {
+ XCopyArea(dzen.dpy, icons[ip].p, *pm, dzen.tgc,
+ 0, 0, icons[ip].w, icons[ip].h, px, set_posy ? py :
+ (dzen.line_height >= (signed)icons[ip].h ?
+ (dzen.line_height - icons[ip].h)/2 : 0));
+ px += icons[ip].w;
+ } else {
+ if(XReadBitmapFile(dzen.dpy, *pm, tval, &bm_w,
+ &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess
+ && (h/2 + px + (signed)bm_w < dzen.w)) {
+ setcolor(pm, px, bm_w, lastfg, lastbg, reverse, nobg);
+ XCopyPlane(dzen.dpy, bm, *pm, dzen.tgc,
+ 0, 0, bm_w, bm_h, px, set_posy ? py :
+ (dzen.line_height >= (signed)bm_h ? (dzen.line_height - bm_h)/2 : 0), 1);
+ XFreePixmap(dzen.dpy, bm);
+ px += bm_w;
+ }
#ifdef DZEN_XPM
- else if(XpmReadFileToPixmap(dzen.dpy, dzen.title_win.win, tval, &xpm_pm, NULL, &xpma) == XpmSuccess) {
- setcolor(pm, px, xpma.width, lastfg, lastbg, reverse, nobg);
- XCopyArea(dzen.dpy, xpm_pm, *pm, dzen.tgc,
- 0, 0, xpma.width, xpma.height, px, set_posy ? py :
- (dzen.line_height >= (signed)xpma.height ? (dzen.line_height - xpma.height)/2 : 0));
- px += xpma.width;
-
- XFreePixmap(dzen.dpy, xpm_pm);
- free_xpm_attrib = 1;
+ else if(XpmReadFileToPixmap(dzen.dpy, dzen.title_win.win, tval, &xpm_pm, NULL, &xpma) == XpmSuccess) {
+ setcolor(pm, px, xpma.width, lastfg, lastbg, reverse, nobg);
+ insert_icon(tval, xpm_pm, xpma.width, xpma.height);
+
+ XCopyArea(dzen.dpy, xpm_pm, *pm, dzen.tgc,
+ 0, 0, xpma.width, xpma.height, px, set_posy ? py :
+ (dzen.line_height >= (signed)xpma.height ? (dzen.line_height - xpma.height)/2 : 0));
+ px += xpma.width;
+
+ //XFreePixmap(dzen.dpy, xpm_pm);
+ free_xpm_attrib = 1;
+ }
}
#endif
break;
@@ -617,26 +668,36 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
if(t != -1 && tval) {
switch(t) {
case icon:
- if(XReadBitmapFile(dzen.dpy, *pm, tval, &bm_w,
- &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess
- && (h/2 + px + (signed)bm_w < dzen.w)) {
- setcolor(pm, px, bm_w, lastfg, lastbg, reverse, nobg);
- XCopyPlane(dzen.dpy, bm, *pm, dzen.tgc,
- 0, 0, bm_w, bm_h, px, set_posy ? py :
- (dzen.line_height >= (signed)bm_h ? (dzen.line_height - bm_h)/2 : 0), 1);
- XFreePixmap(dzen.dpy, bm);
- px += bm_w;
- }
+ if( (ip=find_icon(tval)) != -1) {
+ XCopyArea(dzen.dpy, icons[ip].p, *pm, dzen.tgc,
+ 0, 0, icons[ip].w, icons[ip].h, px, set_posy ? py :
+ (dzen.line_height >= (signed)icons[ip].h ?
+ (dzen.line_height - icons[ip].h)/2 : 0));
+ px += icons[ip].w;
+ } else {
+ if(XReadBitmapFile(dzen.dpy, *pm, tval, &bm_w,
+ &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess
+ && (h/2 + px + (signed)bm_w < dzen.w)) {
+ setcolor(pm, px, bm_w, lastfg, lastbg, reverse, nobg);
+ XCopyPlane(dzen.dpy, bm, *pm, dzen.tgc,
+ 0, 0, bm_w, bm_h, px, set_posy ? py :
+ (dzen.line_height >= (signed)bm_h ? (dzen.line_height - bm_h)/2 : 0), 1);
+ XFreePixmap(dzen.dpy, bm);
+ px += bm_w;
+ }
#ifdef DZEN_XPM
- else if(XpmReadFileToPixmap(dzen.dpy, dzen.title_win.win, tval, &xpm_pm, NULL, &xpma) == XpmSuccess) {
- setcolor(pm, px, xpma.width, lastfg, lastbg, reverse, nobg);
- XCopyArea(dzen.dpy, xpm_pm, *pm, dzen.tgc,
- 0, 0, xpma.width, xpma.height, px, set_posy ? py :
- (dzen.line_height >= (signed)xpma.height ? (dzen.line_height - xpma.height)/2 : 0));
- px += xpma.width;
-
- XFreePixmap(dzen.dpy, xpm_pm);
- free_xpm_attrib = 1;
+ else if(XpmReadFileToPixmap(dzen.dpy, dzen.title_win.win, tval, &xpm_pm, NULL, &xpma) == XpmSuccess) {
+ setcolor(pm, px, xpma.width, lastfg, lastbg, reverse, nobg);
+ insert_icon(tval, xpm_pm, xpma.width, xpma.height);
+
+ XCopyArea(dzen.dpy, xpm_pm, *pm, dzen.tgc,
+ 0, 0, xpma.width, xpma.height, px, set_posy ? py :
+ (dzen.line_height >= (signed)xpma.height ? (dzen.line_height - xpma.height)/2 : 0));
+ px += xpma.width;
+
+ //XFreePixmap(dzen.dpy, xpm_pm);
+ free_xpm_attrib = 1;
+ }
}
#endif
break;
diff --git a/gadgets/dbar.c b/gadgets/dbar.c
index 1b707a9..2537e26 100644
--- a/gadgets/dbar.c
+++ b/gadgets/dbar.c
@@ -64,8 +64,9 @@ fdbar(Dbar *dbar, FILE *stream) {
switch(dbar->style) {
case outlined:
if(dbar->segb == 0) {
- fprintf(stream, "%s%3d%% ^ib(1)^fg(%s)^ro(%dx%d)^p(%d)^fg(%s)^r(%dx%d)^p(%d)^ib(0)^fg()%s",
- dbar->label ? dbar->label : "", rp,
+ //fprintf(stream, "%s%3d%% ^ib(1)^fg(%s)^ro(%dx%d)^p(%d)^fg(%s)^r(%dx%d)^p(%d)^ib(0)^fg()%s",
+ fprintf(stream, "%s^ib(1)^fg(%s)^ro(%dx%d)^p(%d)^fg(%s)^r(%dx%d)^p(%d)^ib(0)^fg()%s",
+ dbar->label ? dbar->label : "",
dbar->bg, (int)dbar->width, dbar->height, -1*(dbar->width-2),
dbar->fg, (int)l, dbar->height-4>0?dbar->height-4:1,
dbar->width-(int)l-1, dbar->pnl ? "\n" : "");
@@ -73,7 +74,8 @@ fdbar(Dbar *dbar, FILE *stream) {
segs = dbar->width / (dbar->segw + dbar->segb);
segsa = rp * segs / 100;
- printf("%s%3d%% ^ib(1)^fg(%s)^ro(%dx%d)^p(%d)",
+ //printf("%s%3d%% ^ib(1)^fg(%s)^ro(%dx%d)^p(%d)",
+ printf("%s^ib(1)^fg(%s)^ro(%dx%d)^p(%d)",
dbar->label ? dbar->label : "", rp,
dbar->bg, (int)dbar->width, dbar->height, -1*(dbar->width-2));
for(i=0; i < segs; i++) {
@@ -82,7 +84,7 @@ fdbar(Dbar *dbar, FILE *stream) {
else
break;
}
- printf("^fg()^p(%d)^ib(0)%s", (dbar->segw+dbar->segb)*(segs-segsa+1), dbar->pnl ? "\n" : "");
+ printf("^fg()^ib(0)^p(%d)%s", dbar->segb, dbar->pnl ? "\n" : "");
}
break;
@@ -91,19 +93,29 @@ fdbar(Dbar *dbar, FILE *stream) {
segsa = rp * segs / 100;
fprintf(stream, "%s^ib(1)", dbar->label ? dbar->label : "");
if(dbar->segb == 0) {
- fprintf(stream, "^fg(%s)^r(%dx%d+%d-%d)^fg(%s)^p(-%d)^r(%dx%d+%d-%d)",
- dbar->bg, dbar->segw, dbar->height, 0, dbar->height+1,
- dbar->fg, dbar->segw, dbar->segw, (int)l, 0, (int)l+1);
+ //fprintf(stream, "^fg(%s)^r(%dx%d+%d-%d)^fg(%s)^p(-%d)^r(%dx%d+%d-%d)",
+ // dbar->bg, dbar->segw, dbar->height, 0, dbar->height+1,
+ // dbar->fg, dbar->segw, dbar->segw, (int)l, 0, (int)l+1);
+ fprintf(stream, "^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d-%d+%d)",
+ dbar->bg, dbar->segw, dbar->height,
+ dbar->fg,
+ dbar->segw, (int)l, dbar->segw, (int)((dbar->height-l)/2.0 + .5));
} else {
for(i=0; i < segs; i++) {
if(i<segsa)
- fprintf(stream, "^fg(%s)^p(-%d)^r(%dx%d+%d-%d)",
- dbar->fg, i?dbar->segw:0, dbar->segw,
- dbar->segh, 0, (dbar->segh+dbar->segb)*(i+1));
+ fprintf(stream, "^fg(%s)^r(%dx%d-%d-%d)",
+ dbar->fg, dbar->segw, dbar->segh,
+ i?dbar->segw:0, (dbar->segh+dbar->segb)*i);
+ //fprintf(stream, "^fg(%s)^p(-%d)^r(%dx%d+%d-%d)",
+ // dbar->fg, i?dbar->segw:0, dbar->segw,
+ // dbar->segh, 0, (dbar->segh+dbar->segb)*(i+1));
else
- fprintf(stream, "^fg(%s)^p(-%d)^r(%dx%d+%d-%d)",
- dbar->bg, i?dbar->segw:0, dbar->segw,
- dbar->segh, 0, (dbar->segh+dbar->segb)*(i+1));
+ fprintf(stream, "^fg(%s)^r(%dx%d-%d-%d)",
+ dbar->bg, dbar->segw,
+ dbar->segh,i?dbar->segw:0, (dbar->segh+dbar->segb)*i);
+ //fprintf(stream, "^fg(%s)^p(-%d)^r(%dx%d+%d-%d)",
+ // dbar->bg, i?dbar->segw:0, dbar->segw,
+ // dbar->segh, 0, (dbar->segh+dbar->segb)*(i+1));
}
}
fprintf(stream, "^ib(0)^fg()%s", dbar->pnl ? "\n" : "");
@@ -141,8 +153,9 @@ fdbar(Dbar *dbar, FILE *stream) {
default:
if(dbar->segb == 0)
- printf("%s%3d%% ^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d)^fg()%s",
- dbar->label ? dbar->label : "", rp,
+ //printf("%s%3d%% ^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d)^fg()%s",
+ printf("%s^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d)^fg()%s",
+ dbar->label ? dbar->label : "",
dbar->fg, (int)l, dbar->height,
dbar->bg, dbar->width-(int)l, dbar->height,
dbar->pnl ? "\n" : "");
@@ -150,16 +163,17 @@ fdbar(Dbar *dbar, FILE *stream) {
segs = dbar->width / (dbar->segw + dbar->segb);
segsa = rp * segs / 100;
- printf("%s%3d%% ", dbar->label ? dbar->label : "", rp);
+ //printf("%s%3d%% ", dbar->label ? dbar->label : "", rp);
+ printf("%s", dbar->label ? dbar->label : "");
for(i=0; i < segs; i++) {
if(i<segsa)
- fprintf(stream, "^fg(%s)^r(%dx%d+%d+%d')",
+ fprintf(stream, "^fg(%s)^r(%dx%d+%d+%d)",
dbar->fg, dbar->segw, dbar->height, i?dbar->segb:0, 0);
else
- fprintf(stream, "^fg(%s)^r(%dx%d+%d+%d')",
+ fprintf(stream, "^fg(%s)^r(%dx%d+%d+%d)",
dbar->bg, dbar->segw, dbar->height, i?dbar->segb:0, 0);
}
- fprintf(stream, "^fg()%s", dbar->pnl ? "\n" : "");
+ fprintf(stream, "^p(%d)^fg()%s", dbar->segb, dbar->pnl ? "\n" : "");
}
break;
}