aboutsummaryrefslogtreecommitdiffstats
path: root/draw.c
diff options
context:
space:
mode:
authorgotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2>2007-06-14 14:35:37 +0000
committergotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2>2007-06-14 14:35:37 +0000
commit35b3752eb2c16a0a256fa7a0bdc410ca4eaa0ad8 (patch)
treed4b0f5ae06edec33cd4cafbcec81b1f1dd440e5e /draw.c
parent81eed5c092eb40fd6e1256b2b1d160b2ba5bb426 (diff)
downloaddzen-35b3752eb2c16a0a256fa7a0bdc410ca4eaa0ad8.tar.gz
dzen-35b3752eb2c16a0a256fa7a0bdc410ca4eaa0ad8.zip
proper check if can allocate the requested color
git-svn-id: http://dzen.googlecode.com/svn/trunk@99 f2baff5b-bf2c-0410-a398-912abdc3d8b2
Diffstat (limited to 'draw.c')
-rw-r--r--draw.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/draw.c b/draw.c
index fa9c854..bac0883 100644
--- a/draw.c
+++ b/draw.c
@@ -40,7 +40,7 @@ drawtext(const char *text, int reverse, int line, int align) {
else { /* slave window */
mgc = reverse ? dzen.rgc : dzen.gc;
- if(!dzen.slave_win.tbuf[line].text) {
+ if(!dzen.slave_win.tbuf[line+dzen.slave_win.first_line_vis].text) {
reverse ?
XSetForeground(dzen.dpy, mgc, dzen.norm[ColFG]):
XSetForeground(dzen.dpy, mgc, dzen.norm[ColBG]);
@@ -49,10 +49,9 @@ drawtext(const char *text, int reverse, int line, int align) {
XSetForeground(dzen.dpy, mgc, dzen.slave_win.tbuf[line+dzen.slave_win.first_line_vis].fg):
XSetForeground(dzen.dpy, mgc, dzen.slave_win.tbuf[line+dzen.slave_win.first_line_vis].bg);
}
-
XFillRectangles(dzen.dpy, dzen.slave_win.drawable[line], mgc, &r, 1);
- if(!dzen.slave_win.tbuf[line].text) {
+ if(!dzen.slave_win.tbuf[line+dzen.slave_win.first_line_vis].text) {
reverse ?
XSetForeground(dzen.dpy, mgc, dzen.norm[ColBG]):
XSetForeground(dzen.dpy, mgc, dzen.norm[ColFG]);
@@ -125,13 +124,14 @@ drawtext(const char *text, int reverse, int line, int align) {
}
}
-unsigned long
+long
getcolor(const char *colstr) {
Colormap cmap = DefaultColormap(dzen.dpy, dzen.screen);
XColor color;
if(!XAllocNamedColor(dzen.dpy, cmap, colstr, &color, &color))
- eprint("dzen: error, cannot allocate color '%s'\n", colstr);
+ return -1;
+ //eprint("dzen: error, cannot allocate color '%s'\n", colstr);
return color.pixel;
}
@@ -186,13 +186,15 @@ setlinecolor(char * text, unsigned long * colfg, unsigned long * colbg) {
if(text[0] == '^' && text[1] == '#') {
strncpy(fgcolor, text+1, 7);
fgcolor[7] = '\0';
- newfg = getcolor(fgcolor);
+ if((newfg = getcolor(fgcolor)) == -1)
+ return NULL;
*colfg = newfg;
if(text[8] == '^' && text[9] == '#') {
strncpy(bgcolor, text+9, 7);
bgcolor[7] = '\0';
- newbg = getcolor(bgcolor);
+ if((newbg = getcolor(bgcolor)) == -1)
+ return NULL;
*colbg = newbg;
return text+16;
@@ -218,7 +220,6 @@ drawheader(char * text) {
if( (ctext = setlinecolor(text, &colfg, &colbg)) ) {
XSetForeground(dzen.dpy, dzen.gc, colfg);
XSetBackground(dzen.dpy, dzen.gc, colbg);
- printf("FG: %lu, BG: %lu\n", colfg, colbg);
drawtext(ctext, 0, -1, dzen.title_win.alignment);
XSetForeground(dzen.dpy, dzen.gc, dzen.norm[ColFG]);
XSetBackground(dzen.dpy, dzen.gc, dzen.norm[ColBG]);