dwm-meillo

diff draw.c @ 76:4bd49f404f10

proceeded with cleaning up, sorting functions, etc
author Anselm R. Garbe <garbeam@wmii.de>
date Sat, 15 Jul 2006 17:00:56 +0200
parents f08271b7cb20
children 38c8f7f7d401
line diff
     1.1 --- a/draw.c	Sat Jul 15 16:30:50 2006 +0200
     1.2 +++ b/draw.c	Sat Jul 15 17:00:56 2006 +0200
     1.3 @@ -2,13 +2,34 @@
     1.4   * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
     1.5   * See LICENSE file for license details.
     1.6   */
     1.7 +#include "dwm.h"
     1.8  
     1.9  #include <stdio.h>
    1.10  #include <string.h>
    1.11 -
    1.12  #include <X11/Xlocale.h>
    1.13  
    1.14 -#include "dwm.h"
    1.15 +/* static functions */
    1.16 +
    1.17 +static void
    1.18 +drawborder(void)
    1.19 +{
    1.20 +	XPoint points[5];
    1.21 +	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
    1.22 +	XSetForeground(dpy, dc.gc, dc.border);
    1.23 +	points[0].x = dc.x;
    1.24 +	points[0].y = dc.y;
    1.25 +	points[1].x = dc.w - 1;
    1.26 +	points[1].y = 0;
    1.27 +	points[2].x = 0;
    1.28 +	points[2].y = dc.h - 1;
    1.29 +	points[3].x = -(dc.w - 1);
    1.30 +	points[3].y = 0;
    1.31 +	points[4].x = 0;
    1.32 +	points[4].y = -(dc.h - 1);
    1.33 +	XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
    1.34 +}
    1.35 +
    1.36 +/* extern functions */
    1.37  
    1.38  void
    1.39  drawall()
    1.40 @@ -53,59 +74,6 @@
    1.41  }
    1.42  
    1.43  void
    1.44 -drawtitle(Client *c)
    1.45 -{
    1.46 -	int i;
    1.47 -	Bool istile = arrange == dotile;
    1.48 -
    1.49 -	if(c == sel) {
    1.50 -		drawstatus();
    1.51 -		XUnmapWindow(dpy, c->title);
    1.52 -		XSetWindowBorder(dpy, c->win, dc.fg);
    1.53 -		return;
    1.54 -	}
    1.55 -
    1.56 -	XSetWindowBorder(dpy, c->win, dc.bg);
    1.57 -	XMapWindow(dpy, c->title);
    1.58 -
    1.59 -	dc.x = dc.y = 0;
    1.60 -
    1.61 -	dc.w = 0;
    1.62 -	for(i = 0; i < TLast; i++) {
    1.63 -		if(c->tags[i]) {
    1.64 -			dc.x += dc.w;
    1.65 -			dc.w = textw(c->tags[i]);
    1.66 -			drawtext(c->tags[i], !istile, True);
    1.67 -		}
    1.68 -	}
    1.69 -	dc.x += dc.w;
    1.70 -	dc.w = textw(c->name);
    1.71 -	drawtext(c->name, !istile, True);
    1.72 -	XCopyArea(dpy, dc.drawable, c->title, dc.gc,
    1.73 -			0, 0, c->tw, c->th, 0, 0);
    1.74 -	XFlush(dpy);
    1.75 -}
    1.76 -
    1.77 -static void
    1.78 -drawborder(void)
    1.79 -{
    1.80 -	XPoint points[5];
    1.81 -	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
    1.82 -	XSetForeground(dpy, dc.gc, dc.border);
    1.83 -	points[0].x = dc.x;
    1.84 -	points[0].y = dc.y;
    1.85 -	points[1].x = dc.w - 1;
    1.86 -	points[1].y = 0;
    1.87 -	points[2].x = 0;
    1.88 -	points[2].y = dc.h - 1;
    1.89 -	points[3].x = -(dc.w - 1);
    1.90 -	points[3].y = 0;
    1.91 -	points[4].x = 0;
    1.92 -	points[4].y = -(dc.h - 1);
    1.93 -	XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
    1.94 -}
    1.95 -
    1.96 -void
    1.97  drawtext(const char *text, Bool invert, Bool border)
    1.98  {
    1.99  	int x, y, w, h;
   1.100 @@ -155,6 +123,40 @@
   1.101  	}
   1.102  }
   1.103  
   1.104 +void
   1.105 +drawtitle(Client *c)
   1.106 +{
   1.107 +	int i;
   1.108 +	Bool istile = arrange == dotile;
   1.109 +
   1.110 +	if(c == sel) {
   1.111 +		drawstatus();
   1.112 +		XUnmapWindow(dpy, c->title);
   1.113 +		XSetWindowBorder(dpy, c->win, dc.fg);
   1.114 +		return;
   1.115 +	}
   1.116 +
   1.117 +	XSetWindowBorder(dpy, c->win, dc.bg);
   1.118 +	XMapWindow(dpy, c->title);
   1.119 +
   1.120 +	dc.x = dc.y = 0;
   1.121 +
   1.122 +	dc.w = 0;
   1.123 +	for(i = 0; i < TLast; i++) {
   1.124 +		if(c->tags[i]) {
   1.125 +			dc.x += dc.w;
   1.126 +			dc.w = textw(c->tags[i]);
   1.127 +			drawtext(c->tags[i], !istile, True);
   1.128 +		}
   1.129 +	}
   1.130 +	dc.x += dc.w;
   1.131 +	dc.w = textw(c->name);
   1.132 +	drawtext(c->name, !istile, True);
   1.133 +	XCopyArea(dpy, dc.drawable, c->title, dc.gc,
   1.134 +			0, 0, c->tw, c->th, 0, 0);
   1.135 +	XFlush(dpy);
   1.136 +}
   1.137 +
   1.138  unsigned long
   1.139  getcolor(const char *colstr)
   1.140  {
   1.141 @@ -165,23 +167,6 @@
   1.142  	return color.pixel;
   1.143  }
   1.144  
   1.145 -unsigned int
   1.146 -textnw(char *text, unsigned int len)
   1.147 -{
   1.148 -	XRectangle r;
   1.149 -	if(dc.font.set) {
   1.150 -		XmbTextExtents(dc.font.set, text, len, NULL, &r);
   1.151 -		return r.width;
   1.152 -	}
   1.153 -	return XTextWidth(dc.font.xfont, text, len);
   1.154 -}
   1.155 -
   1.156 -unsigned int
   1.157 -textw(char *text)
   1.158 -{
   1.159 -	return textnw(text, strlen(text)) + dc.font.height;
   1.160 -}
   1.161 -
   1.162  void
   1.163  setfont(const char *fontstr)
   1.164  {
   1.165 @@ -232,3 +217,20 @@
   1.166  	}
   1.167  	dc.font.height = dc.font.ascent + dc.font.descent;
   1.168  }
   1.169 +
   1.170 +unsigned int
   1.171 +textnw(char *text, unsigned int len)
   1.172 +{
   1.173 +	XRectangle r;
   1.174 +	if(dc.font.set) {
   1.175 +		XmbTextExtents(dc.font.set, text, len, NULL, &r);
   1.176 +		return r.width;
   1.177 +	}
   1.178 +	return XTextWidth(dc.font.xfont, text, len);
   1.179 +}
   1.180 +
   1.181 +unsigned int
   1.182 +textw(char *text)
   1.183 +{
   1.184 +	return textnw(text, strlen(text)) + dc.font.height;
   1.185 +}