aboutsummaryrefslogtreecommitdiffstats
path: root/draw.c
diff options
context:
space:
mode:
Diffstat (limited to 'draw.c')
-rw-r--r--draw.c172
1 files changed, 86 insertions, 86 deletions
diff --git a/draw.c b/draw.c
index a1be746..d627fa9 100644
--- a/draw.c
+++ b/draw.c
@@ -1,5 +1,5 @@
-/*
+/*
* (C)opyright MMVII Robert Manea <rob dot manea at gmail dot com>
* See LICENSE file for license details.
*
@@ -21,7 +21,7 @@
typedef struct ICON_C {
char name[ARGLEN];
Pixmap p;
-
+
int w, h;
} icon_c;
@@ -108,7 +108,7 @@ setfont(const char *fontstr) {
missing = NULL;
if(dzen.font.set)
XFreeFontSet(dzen.dpy, dzen.font.set);
-
+
dzen.font.set = XCreateFontSet(dzen.dpy, fontstr, &missing, &n, &def);
if(missing)
XFreeStringList(missing);
@@ -165,7 +165,7 @@ get_token(const char *line, int * t, char **tval) {
line++;
for(i=0; cmd_lookup_table[i].name; ++i) {
- if( off=cmd_lookup_table[i].off,
+ if( off=cmd_lookup_table[i].off,
!strncmp(line, cmd_lookup_table[i].name, off) ) {
next_pos = get_tokval(line+off, &tokval);
*t = cmd_lookup_table[i].id;
@@ -201,7 +201,7 @@ get_rect_vals(char *s, int *w, int *h, int *x, int *y) {
static int
get_circle_vals(char *s, int *d, int *a) {
- int i, ret;
+ int ret;
*d=*a=ret=0;
return sscanf(s, "%5d%5d", d, a);
@@ -235,21 +235,21 @@ get_pos_vals(char *s, int *d, int *a) {
if(!strncmp(s, "_TOP", 4)) {
*d = TOP;
}
-
+
return 5;
} else {
for(i=0; s[i] && i<128; i++) {
if(s[i] == ';') {
onlyx=0;
break;
- } else
+ } else
buf[i]=s[i];
}
if(i) {
buf[i]='\0';
*d=atoi(buf);
- } else
+ } else
ret=2;
if(s[++i]) {
@@ -267,18 +267,17 @@ static int
search_icon_cache(const char* name) {
int i;
- for(i=0; i < MAX_ICON_CACHE; i++)
+ for(i=0; i < MAX_ICON_CACHE; i++)
if(!strncmp(icons[i].name, name, ARGLEN))
return i;
return -1;
}
+#ifdef DZEN_XPM
static void
cache_icon(const char* name, Pixmap pm, int w, int h) {
- int i;
-
- if(icon_cnt >= MAX_ICON_CACHE)
+ if(icon_cnt >= MAX_ICON_CACHE)
icon_cnt = 0;
if(icons[icon_cnt].p)
@@ -290,17 +289,18 @@ cache_icon(const char* name, Pixmap pm, int w, int h) {
icons[icon_cnt].p = pm;
icon_cnt++;
}
+#endif
char *
parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
/* bitmaps */
- unsigned int bm_w, bm_h;
+ unsigned int bm_w, bm_h;
int bm_xh, bm_yh;
/* rectangles, cirlcles*/
int rectw, recth, rectx, recty;
/* positioning */
int n_posx, n_posy, set_posy=0;
- int px=0, py=0, xorig;
+ int px=0, py=0, xorig=0;
int i, next_pos=0, j=0, h=0, tw=0, ow;
/* fonts */
int font_was_set=0;
@@ -333,7 +333,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
if(nodraw) {
rbuf = emalloc(MAX_LINE_LEN);
rbuf[0] = '\0';
- if( (lnr + dzen.slave_win.first_line_vis) >= dzen.slave_win.tcnt)
+ if( (lnr + dzen.slave_win.first_line_vis) >= dzen.slave_win.tcnt)
line = NULL;
else
line = dzen.slave_win.tbuf[dzen.slave_win.first_line_vis+lnr];
@@ -343,15 +343,15 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
else {
h = dzen.font.height;
py = (dzen.line_height - h) / 2;
- xorig = 0;
+ xorig = 0;
if(lnr != -1) {
- pm = XCreatePixmap(dzen.dpy, RootWindow(dzen.dpy, DefaultScreen(dzen.dpy)), dzen.slave_win.width,
+ pm = XCreatePixmap(dzen.dpy, RootWindow(dzen.dpy, DefaultScreen(dzen.dpy)), dzen.slave_win.width,
dzen.line_height, DefaultDepth(dzen.dpy, dzen.screen));
}
else {
- pm = XCreatePixmap(dzen.dpy, RootWindow(dzen.dpy, DefaultScreen(dzen.dpy)), dzen.title_win.width,
+ pm = XCreatePixmap(dzen.dpy, RootWindow(dzen.dpy, DefaultScreen(dzen.dpy)), dzen.title_win.width,
dzen.line_height, DefaultDepth(dzen.dpy, dzen.screen));
}
@@ -388,7 +388,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
xpma.valuemask = XpmColormap|XpmDepth|XpmVisual|XpmColorSymbols;
#endif
- if(!dzen.font.set){
+ if(!dzen.font.set){
gcv.font = dzen.font.xfont->fid;
XChangeGC(dzen.dpy, dzen.tgc, GCFont, &gcv);
}
@@ -415,20 +415,20 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
switch(t) {
case icon:
if(MAX_ICON_CACHE && (ip=search_icon_cache(tval)) != -1) {
- XCopyArea(dzen.dpy, icons[ip].p, pm, dzen.tgc,
+ 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 >= (signed)icons[ip].h ?
(dzen.line_height - icons[ip].h)/2 : 0));
px += !pos_is_fixed ? icons[ip].w : 0;
} else {
- if(XReadBitmapFile(dzen.dpy, pm, tval, &bm_w,
- &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess
+ 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);
+ XCopyPlane(dzen.dpy, bm, pm, dzen.tgc,
+ 0, 0, bm_w, bm_h, px, set_posy ? py :
+ (dzen.line_height >= (int)bm_h ? (dzen.line_height - (int)bm_h)/2 : 0), 1);
XFreePixmap(dzen.dpy, bm);
px += !pos_is_fixed ? bm_w : 0; }
#ifdef DZEN_XPM
@@ -438,9 +438,9 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
if(MAX_ICON_CACHE)
cache_icon(tval, xpm_pm, xpma.width, xpma.height);
- XCopyArea(dzen.dpy, xpm_pm, pm, dzen.tgc,
+ 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));
+ (dzen.line_height >= (int)xpma.height ? (dzen.line_height - (int)xpma.height)/2 : 0));
px += !pos_is_fixed ? xpma.width : 0;
/* freed by cache_icon() */
@@ -451,25 +451,25 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
}
break;
-
+
case rect:
get_rect_vals(tval, &rectw, &recth, &rectx, &recty);
recth = recth > dzen.line_height ? dzen.line_height : recth;
if(set_posy)
py += recty;
- recty = recty == 0 ? (dzen.line_height - recth)/2 :
+ recty = recty == 0 ? (dzen.line_height - recth)/2 :
(dzen.line_height - recth)/2 + recty;
px += !pos_is_fixed ? rectx : 0;
setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg);
-
- XFillRectangle(dzen.dpy, pm, dzen.tgc, px,
- set_posy ? py :
- ((int)recty < 0 ? dzen.line_height + recty : recty),
+
+ XFillRectangle(dzen.dpy, pm, dzen.tgc, px,
+ set_posy ? py :
+ ((int)recty < 0 ? dzen.line_height + recty : recty),
rectw, recth);
px += !pos_is_fixed ? rectw : 0;
break;
-
+
case recto:
get_rect_vals(tval, &rectw, &recth, &rectx, &recty);
if (!rectw) break;
@@ -477,14 +477,14 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
recth = recth > dzen.line_height ? dzen.line_height-2 : recth-1;
if(set_posy)
py += recty;
- recty = recty == 0 ? (dzen.line_height - recth)/2 :
+ recty = recty == 0 ? (dzen.line_height - recth)/2 :
(dzen.line_height - recth)/2 + recty;
px = (rectx == 0) ? px : rectx+px;
/* prevent from stairs effect when rounding recty */
if (!((dzen.line_height - recth) % 2)) recty--;
setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg);
- XDrawRectangle(dzen.dpy, pm, dzen.tgc, px,
- set_posy ? py :
+ XDrawRectangle(dzen.dpy, pm, dzen.tgc, px,
+ set_posy ? py :
((int)recty<0 ? dzen.line_height + recty : recty), rectw-1, recth);
px += !pos_is_fixed ? rectw : 0;
break;
@@ -492,7 +492,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
case circle:
rectx = get_circle_vals(tval, &rectw, &recth);
setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg);
- XFillArc(dzen.dpy, pm, dzen.tgc, px, set_posy ? py :(dzen.line_height - rectw)/2,
+ XFillArc(dzen.dpy, pm, dzen.tgc, px, set_posy ? py :(dzen.line_height - rectw)/2,
rectw, rectw, 90*64, rectx>1?recth*64:64*360);
px += !pos_is_fixed ? rectw : 0;
break;
@@ -500,7 +500,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
case circleo:
rectx = get_circle_vals(tval, &rectw, &recth);
setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg);
- XDrawArc(dzen.dpy, pm, dzen.tgc, px, set_posy ? py : (dzen.line_height - rectw)/2,
+ XDrawArc(dzen.dpy, pm, dzen.tgc, px, set_posy ? py : (dzen.line_height - rectw)/2,
rectw, rectw, 90*64, rectx>1?recth*64:64*360);
px += !pos_is_fixed ? rectw : 0;
break;
@@ -513,10 +513,10 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
set_posy=0;
else if (r == 5) {
switch(n_posx) {
- case LOCK_X:
+ case LOCK_X:
pos_is_fixed = 1;
break;
- case UNLOCK_X:
+ case UNLOCK_X:
pos_is_fixed = 0;
break;
case LEFT:
@@ -536,12 +536,12 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
set_posy = 1;
py = 0;
break;
- }
+ }
} else
set_posy=1;
if(r != 2)
- px = px+n_posx<0? 0 : px + n_posx;
+ px = px+n_posx<0? 0 : px + n_posx;
if(r != 1)
py += n_posy;
} else {
@@ -581,7 +581,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
lastfg = tval[0] ? (unsigned)getcolor(tval) : dzen.norm[ColFG];
XSetForeground(dzen.dpy, dzen.tgc, lastfg);
break;
-
+
case fn:
if(tval[0]) {
if(!strncmp(tval, "dfnt", 4)) {
@@ -597,7 +597,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
}
else {
cur_fnt = &dzen.font;
- if(!cur_fnt->set){
+ if(!cur_fnt->set){
gcv.font = cur_fnt->xfont->fid;
XChangeGC(dzen.dpy, dzen.tgc, GCFont, &gcv);
}
@@ -628,11 +628,11 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
if(!nobg)
setcolor(&pm, px, tw, lastfg, lastbg, reverse, nobg);
- if(cur_fnt->set)
+ if(cur_fnt->set)
XmbDrawString(dzen.dpy, pm, cur_fnt->set,
dzen.tgc, px, py + cur_fnt->ascent, lbuf, strlen(lbuf));
- else
- XDrawString(dzen.dpy, pm, dzen.tgc, px, py+dzen.font.ascent, lbuf, strlen(lbuf));
+ else
+ XDrawString(dzen.dpy, pm, dzen.tgc, px, py+dzen.font.ascent, lbuf, strlen(lbuf));
px += !pos_is_fixed ? tw : 0;
}
@@ -642,10 +642,10 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
i += next_pos;
/* ^^ escapes */
- if(next_pos == 0)
+ if(next_pos == 0)
lbuf[j++] = line[i++];
- }
- else
+ }
+ else
lbuf[j++] = line[i];
}
@@ -658,19 +658,19 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
switch(t) {
case icon:
if(MAX_ICON_CACHE && (ip=search_icon_cache(tval)) != -1) {
- XCopyArea(dzen.dpy, icons[ip].p, pm, dzen.tgc,
+ 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 >= (signed)icons[ip].h ?
(dzen.line_height - icons[ip].h)/2 : 0));
px += !pos_is_fixed ? icons[ip].w : 0;
} else {
- if(XReadBitmapFile(dzen.dpy, pm, tval, &bm_w,
- &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess
+ 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);
+ XCopyPlane(dzen.dpy, bm, pm, dzen.tgc,
+ 0, 0, bm_w, bm_h, px, set_posy ? py :
+ (dzen.line_height >= (int)bm_h ? (dzen.line_height - (int)bm_h)/2 : 0), 1);
XFreePixmap(dzen.dpy, bm);
px += !pos_is_fixed ? bm_w : 0;
}
@@ -681,9 +681,9 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
if(MAX_ICON_CACHE)
cache_icon(tval, xpm_pm, xpma.width, xpma.height);
- XCopyArea(dzen.dpy, xpm_pm, pm, dzen.tgc,
+ 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));
+ (dzen.line_height >= (int)xpma.height ? (dzen.line_height - (int)xpma.height)/2 : 0));
px += !pos_is_fixed ? xpma.width : 0;
//XFreePixmap(dzen.dpy, xpm_pm);
@@ -698,14 +698,14 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
recth = recth > dzen.line_height ? dzen.line_height : recth;
if(set_posy)
py += recty;
- recty = recty == 0 ? (dzen.line_height - recth)/2 :
+ recty = recty == 0 ? (dzen.line_height - recth)/2 :
(dzen.line_height - recth)/2 + recty;
px += rectx;
setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg);
- XFillRectangle(dzen.dpy, pm, dzen.tgc, px,
- set_posy ? py :
- ((int)recty < 0 ? dzen.line_height + recty : recty),
+ XFillRectangle(dzen.dpy, pm, dzen.tgc, px,
+ set_posy ? py :
+ ((int)recty < 0 ? dzen.line_height + recty : recty),
rectw, recth);
px += !pos_is_fixed ? rectw : 0;
@@ -724,8 +724,8 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
/* prevent from stairs effect when rounding recty */
if (!((dzen.line_height - recth) % 2)) recty--;
setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg);
- XDrawRectangle(dzen.dpy, pm, dzen.tgc, px,
- set_posy ? py :
+ XDrawRectangle(dzen.dpy, pm, dzen.tgc, px,
+ set_posy ? py :
((int)recty<0 ? dzen.line_height + recty : recty), rectw-1, recth);
px += !pos_is_fixed ? rectw : 0;
break;
@@ -733,7 +733,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
case circle:
rectx = get_circle_vals(tval, &rectw, &recth);
setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg);
- XFillArc(dzen.dpy, pm, dzen.tgc, px, set_posy ? py :(dzen.line_height - rectw)/2,
+ XFillArc(dzen.dpy, pm, dzen.tgc, px, set_posy ? py :(dzen.line_height - rectw)/2,
rectw, rectw, 90*64, rectx>1?recth*64:64*360);
px += !pos_is_fixed ? rectw : 0;
break;
@@ -741,7 +741,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
case circleo:
rectx = get_circle_vals(tval, &rectw, &recth);
setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg);
- XDrawArc(dzen.dpy, pm, dzen.tgc, px, set_posy ? py : (dzen.line_height - rectw)/2,
+ XDrawArc(dzen.dpy, pm, dzen.tgc, px, set_posy ? py : (dzen.line_height - rectw)/2,
rectw, rectw, 90*64, rectx>1?recth*64:64*360);
px += !pos_is_fixed ? rectw : 0;
break;
@@ -754,10 +754,10 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
set_posy=0;
else if (r == 5) {
switch(n_posx) {
- case LOCK_X:
+ case LOCK_X:
pos_is_fixed = 1;
break;
- case UNLOCK_X:
+ case UNLOCK_X:
pos_is_fixed = 0;
break;
case LEFT:
@@ -777,12 +777,12 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
set_posy = 1;
py = 0;
break;
- }
+ }
} else
set_posy=1;
if(r != 2)
- px = px+n_posx<0? 0 : px + n_posx;
+ px = px+n_posx<0? 0 : px + n_posx;
if(r != 1)
py += n_posy;
} else {
@@ -838,7 +838,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
}
else {
cur_fnt = &dzen.font;
- if(!cur_fnt->set){
+ if(!cur_fnt->set){
gcv.font = cur_fnt->xfont->fid;
XChangeGC(dzen.dpy, dzen.tgc, GCFont, &gcv);
}
@@ -869,11 +869,11 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
if(!nobg)
setcolor(&pm, px, tw, lastfg, lastbg, reverse, nobg);
- if(cur_fnt->set)
+ if(cur_fnt->set)
XmbDrawString(dzen.dpy, pm, cur_fnt->set,
dzen.tgc, px, py + cur_fnt->ascent, lbuf, strlen(lbuf));
- else
- XDrawString(dzen.dpy, pm, dzen.tgc, px, py+dzen.font.ascent, lbuf, strlen(lbuf));
+ else
+ XDrawString(dzen.dpy, pm, dzen.tgc, px, py+dzen.font.ascent, lbuf, strlen(lbuf));
px += !pos_is_fixed ? tw : 0;
/* expand/shrink dynamically */
@@ -883,7 +883,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
case left:
/* grow left end */
otx = dzen.title_win.x_right_corner - i > dzen.title_win.x ?
- dzen.title_win.x_right_corner - i : dzen.title_win.x;
+ dzen.title_win.x_right_corner - i : dzen.title_win.x;
XMoveResizeWindow(dzen.dpy, dzen.title_win.win, otx, dzen.title_win.y, px, dzen.line_height);
break;
case right:
@@ -902,10 +902,10 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
else if(align == ALIGNRIGHT) {
xorig = (lnr != -1) ?
(dzen.slave_win.width - px) :
- (dzen.title_win.width - px);
+ (dzen.title_win.width - px);
}
}
-
+
if(lnr != -1) {
XCopyArea(dzen.dpy, pm, dzen.slave_win.drawable[lnr], dzen.gc,
@@ -980,12 +980,12 @@ parse_non_drawing_commands(char * text) {
return 1;
}
-
+
void
drawheader(const char * text) {
- if(parse_non_drawing_commands((char *)text)) {
- if (text){
+ if(parse_non_drawing_commands((char *)text)) {
+ if (text){
dzen.w = dzen.title_win.width;
dzen.h = dzen.line_height;
@@ -997,7 +997,7 @@ drawheader(const char * text) {
dzen.cur_line = 0;
}
- XCopyArea(dzen.dpy, dzen.title_win.drawable, dzen.title_win.win,
+ XCopyArea(dzen.dpy, dzen.title_win.drawable, dzen.title_win.win,
dzen.gc, 0, 0, dzen.title_win.width, dzen.line_height, 0, 0);
}
@@ -1018,12 +1018,12 @@ drawbody(char * text) {
XFillRectangle(dzen.dpy, dzen.title_win.drawable, dzen.rgc, 0, 0, dzen.w, dzen.h);
parse_line(ec+5, -1, dzen.title_win.alignment, 0, 0);
- XCopyArea(dzen.dpy, dzen.title_win.drawable, dzen.title_win.win,
+ XCopyArea(dzen.dpy, dzen.title_win.drawable, dzen.title_win.win,
dzen.gc, 0, 0, dzen.w, dzen.h, 0, 0);
return;
}
- if(dzen.slave_win.tcnt == dzen.slave_win.tsize)
+ if(dzen.slave_win.tcnt == dzen.slave_win.tsize)
free_buffer();
write_buffer = parse_non_drawing_commands(text);