dwm-meillo

diff draw.c @ 26:e8f627998d6f

simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
author Anselm R. Garbe <garbeam@wmii.de>
date Wed, 12 Jul 2006 15:17:22 +0200
parents 49e2fc9fb94f
children 2e0fb4130bfb
line diff
     1.1 --- a/draw.c	Wed Jul 12 00:53:11 2006 +0200
     1.2 +++ b/draw.c	Wed Jul 12 15:17:22 2006 +0200
     1.3 @@ -15,16 +15,16 @@
     1.4  	XPoint points[5];
     1.5  	XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter);
     1.6  	XSetForeground(dpy, b->gc, b->border);
     1.7 -	points[0].x = b->rect.x;
     1.8 -	points[0].y = b->rect.y;
     1.9 -	points[1].x = b->rect.width - 1;
    1.10 +	points[0].x = b->x;
    1.11 +	points[0].y = b->y;
    1.12 +	points[1].x = b->w - 1;
    1.13  	points[1].y = 0;
    1.14  	points[2].x = 0;
    1.15 -	points[2].y = b->rect.height - 1;
    1.16 -	points[3].x = -(b->rect.width - 1);
    1.17 +	points[2].y = b->h - 1;
    1.18 +	points[3].x = -(b->w - 1);
    1.19  	points[3].y = 0;
    1.20  	points[4].x = 0;
    1.21 -	points[4].y = -(b->rect.height - 1);
    1.22 +	points[4].y = -(b->h - 1);
    1.23  	XDrawLines(dpy, b->drawable, b->gc, points, 5, CoordModePrevious);
    1.24  }
    1.25  
    1.26 @@ -34,9 +34,10 @@
    1.27  	unsigned int x, y, w, h, len;
    1.28  	static char buf[256];
    1.29  	XGCValues gcv;
    1.30 +	XRectangle r = { b->x, b->y, b->w, b->h };
    1.31  
    1.32  	XSetForeground(dpy, b->gc, b->bg);
    1.33 -	XFillRectangles(dpy, b->drawable, b->gc, &b->rect, 1);
    1.34 +	XFillRectangles(dpy, b->drawable, b->gc, &r, 1);
    1.35  
    1.36  	if(border)
    1.37  		drawborder(dpy, b);
    1.38 @@ -51,14 +52,14 @@
    1.39  	buf[len] = 0;
    1.40  
    1.41  	h = b->font.ascent + b->font.descent;
    1.42 -	y = b->rect.y + (b->rect.height / 2) - (h / 2) + b->font.ascent;
    1.43 -	x = b->rect.x + (h / 2);
    1.44 +	y = b->y + (b->h / 2) - (h / 2) + b->font.ascent;
    1.45 +	x = b->x + (h / 2);
    1.46  
    1.47  	/* shorten text if necessary */
    1.48 -	while(len && (w = textwidth_l(&b->font, buf, len)) > b->rect.width - h)
    1.49 +	while(len && (w = textnw(&b->font, buf, len)) > b->w - h)
    1.50  		buf[--len] = 0;
    1.51  
    1.52 -	if(w > b->rect.width)
    1.53 +	if(w > b->w)
    1.54  		return; /* too long */
    1.55  
    1.56  	gcv.foreground = b->fg;
    1.57 @@ -94,20 +95,26 @@
    1.58  }
    1.59  
    1.60  unsigned int
    1.61 -textwidth_l(Fnt *font, char *text, unsigned int len)
    1.62 +textnw(Fnt *font, char *text, unsigned int len)
    1.63  {
    1.64 +	XRectangle r;
    1.65  	if(font->set) {
    1.66 -		XRectangle r;
    1.67 -		XmbTextExtents(font->set, text, len, 0, &r);
    1.68 +		XmbTextExtents(font->set, text, len, NULL, &r);
    1.69  		return r.width;
    1.70  	}
    1.71  	return XTextWidth(font->xfont, text, len);
    1.72  }
    1.73  
    1.74  unsigned int
    1.75 -textwidth(Fnt *font, char *text)
    1.76 +textw(Fnt *font, char *text)
    1.77  {
    1.78 -	return textwidth_l(font, text, strlen(text));
    1.79 +	return textnw(font, text, strlen(text));
    1.80 +}
    1.81 +
    1.82 +unsigned int
    1.83 +texth(Fnt *font)
    1.84 +{
    1.85 +	return font->height + 4;
    1.86  }
    1.87  
    1.88  void
    1.89 @@ -162,9 +169,3 @@
    1.90  	}
    1.91  	font->height = font->ascent + font->descent;
    1.92  }
    1.93 -
    1.94 -unsigned int
    1.95 -labelheight(Fnt *font)
    1.96 -{
    1.97 -	return font->height + 4;
    1.98 -}