aewl

diff draw.c @ 43:989178822938

changed default colors
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 11:43:05 +0200
parents cd30cce52b78
children f005d46462e8
line diff
     1.1 --- a/draw.c	Thu Jul 13 10:34:55 2006 +0200
     1.2 +++ b/draw.c	Thu Jul 13 11:43:05 2006 +0200
     1.3 @@ -8,7 +8,7 @@
     1.4  
     1.5  #include <X11/Xlocale.h>
     1.6  
     1.7 -#include "wm.h"
     1.8 +#include "dwm.h"
     1.9  
    1.10  static void
    1.11  drawborder(void)
    1.12 @@ -59,7 +59,7 @@
    1.13  	x = dc.x + (h / 2);
    1.14  
    1.15  	/* shorten text if necessary */
    1.16 -	while(len && (w = textnw(&dc.font, buf, len)) > dc.w - h)
    1.17 +	while(len && (w = textnw(buf, len)) > dc.w - h)
    1.18  		buf[--len] = 0;
    1.19  
    1.20  	if(w > dc.w)
    1.21 @@ -79,93 +79,80 @@
    1.22  	}
    1.23  }
    1.24  
    1.25 -static unsigned long
    1.26 -xinitcolors(Colormap cmap, const char *colstr)
    1.27 +unsigned long
    1.28 +initcolor(const char *colstr)
    1.29  {
    1.30  	XColor color;
    1.31 +	Colormap cmap = DefaultColormap(dpy, screen);
    1.32 +
    1.33  	XAllocNamedColor(dpy, cmap, colstr, &color, &color);
    1.34  	return color.pixel;
    1.35  }
    1.36  
    1.37 -void
    1.38 -initcolors(const char *bg, const char *fg, const char *border)
    1.39 +unsigned int
    1.40 +textnw(char *text, unsigned int len)
    1.41  {
    1.42 -	Colormap cmap = DefaultColormap(dpy, screen);
    1.43 -	dc.bg = xinitcolors(cmap, bg);
    1.44 -	dc.fg = xinitcolors(cmap, fg);
    1.45 -	dc.border = xinitcolors(cmap, border);
    1.46 +	XRectangle r;
    1.47 +	if(dc.font.set) {
    1.48 +		XmbTextExtents(dc.font.set, text, len, NULL, &r);
    1.49 +		return r.width;
    1.50 +	}
    1.51 +	return XTextWidth(dc.font.xfont, text, len);
    1.52  }
    1.53  
    1.54  unsigned int
    1.55 -textnw(Fnt *font, char *text, unsigned int len)
    1.56 +textw(char *text)
    1.57  {
    1.58 -	XRectangle r;
    1.59 -	if(font->set) {
    1.60 -		XmbTextExtents(font->set, text, len, NULL, &r);
    1.61 -		return r.width;
    1.62 -	}
    1.63 -	return XTextWidth(font->xfont, text, len);
    1.64 -}
    1.65 -
    1.66 -unsigned int
    1.67 -textw(Fnt *font, char *text)
    1.68 -{
    1.69 -	return textnw(font, text, strlen(text));
    1.70 -}
    1.71 -
    1.72 -unsigned int
    1.73 -texth(Fnt *font)
    1.74 -{
    1.75 -	return font->height + 4;
    1.76 +	return textnw(text, strlen(text));
    1.77  }
    1.78  
    1.79  void
    1.80 -initfont(Fnt *font, const char *fontstr)
    1.81 +initfont(const char *fontstr)
    1.82  {
    1.83  	char **missing, *def;
    1.84  	int i, n;
    1.85  
    1.86  	missing = NULL;
    1.87  	setlocale(LC_ALL, "");
    1.88 -	if(font->set)
    1.89 -		XFreeFontSet(dpy, font->set);
    1.90 -	font->set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
    1.91 +	if(dc.font.set)
    1.92 +		XFreeFontSet(dpy, dc.font.set);
    1.93 +	dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
    1.94  	if(missing) {
    1.95  		while(n--)
    1.96  			fprintf(stderr, "missing fontset: %s\n", missing[n]);
    1.97  		XFreeStringList(missing);
    1.98 -		if(font->set) {
    1.99 -			XFreeFontSet(dpy, font->set);
   1.100 -			font->set = NULL;
   1.101 +		if(dc.font.set) {
   1.102 +			XFreeFontSet(dpy, dc.font.set);
   1.103 +			dc.font.set = NULL;
   1.104  		}
   1.105  	}
   1.106 -	if(font->set) {
   1.107 +	if(dc.font.set) {
   1.108  		XFontSetExtents *font_extents;
   1.109  		XFontStruct **xfonts;
   1.110  		char **font_names;
   1.111  
   1.112 -		font->ascent = font->descent = 0;
   1.113 -		font_extents = XExtentsOfFontSet(font->set);
   1.114 -		n = XFontsOfFontSet(font->set, &xfonts, &font_names);
   1.115 -		for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
   1.116 -			if(font->ascent < (*xfonts)->ascent)
   1.117 -				font->ascent = (*xfonts)->ascent;
   1.118 -			if(font->descent < (*xfonts)->descent)
   1.119 -				font->descent = (*xfonts)->descent;
   1.120 +		dc.font.ascent = dc.font.descent = 0;
   1.121 +		font_extents = XExtentsOfFontSet(dc.font.set);
   1.122 +		n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
   1.123 +		for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
   1.124 +			if(dc.font.ascent < (*xfonts)->ascent)
   1.125 +				dc.font.ascent = (*xfonts)->ascent;
   1.126 +			if(dc.font.descent < (*xfonts)->descent)
   1.127 +				dc.font.descent = (*xfonts)->descent;
   1.128  			xfonts++;
   1.129  		}
   1.130  	}
   1.131  	else {
   1.132 -		if(font->xfont)
   1.133 -			XFreeFont(dpy, font->xfont);
   1.134 -		font->xfont = NULL;
   1.135 -		font->xfont = XLoadQueryFont(dpy, fontstr);
   1.136 -		if (!font->xfont)
   1.137 -			font->xfont = XLoadQueryFont(dpy, "fixed");
   1.138 -		if (!font->xfont)
   1.139 +		if(dc.font.xfont)
   1.140 +			XFreeFont(dpy, dc.font.xfont);
   1.141 +		dc.font.xfont = NULL;
   1.142 +		dc.font.xfont = XLoadQueryFont(dpy, fontstr);
   1.143 +		if (!dc.font.xfont)
   1.144 +			dc.font.xfont = XLoadQueryFont(dpy, "fixed");
   1.145 +		if (!dc.font.xfont)
   1.146  			error("error, cannot init 'fixed' font\n");
   1.147 -		font->ascent = font->xfont->ascent;
   1.148 -		font->descent = font->xfont->descent;
   1.149 +		dc.font.ascent = dc.font.xfont->ascent;
   1.150 +		dc.font.descent = dc.font.xfont->descent;
   1.151  	}
   1.152 -	font->height = font->ascent + font->descent;
   1.153 +	dc.font.height = dc.font.ascent + dc.font.descent;
   1.154  }