aewl

changeset 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 e238dc4844d7
children f96fb3fd8203
files bar.c client.c cmd.c config.h draw.c draw.h event.c menu.c mouse.c wm.c wm.h
diffstat 12 files changed, 164 insertions(+), 235 deletions(-) [+]
line diff
     1.1 --- a/bar.c	Wed Jul 12 00:53:11 2006 +0200
     1.2 +++ b/bar.c	Wed Jul 12 15:17:22 2006 +0200
     1.3 @@ -8,23 +8,22 @@
     1.4  void
     1.5  draw_bar()
     1.6  {
     1.7 -	brush.rect = barrect;
     1.8 -	brush.rect.x = brush.rect.y = 0;
     1.9 +	brush.x = brush.y = 0;
    1.10 +	brush.w = bw;
    1.11 +	brush.h = bh;
    1.12  	draw(dpy, &brush, False, NULL);
    1.13  
    1.14  	if(stack) {
    1.15 -		brush.rect.width = textwidth(&brush.font, stack->name) + labelheight(&brush.font);
    1.16 +		brush.w = textw(&brush.font, stack->name) + bh;
    1.17  		swap((void **)&brush.fg, (void **)&brush.bg);
    1.18  		draw(dpy, &brush, True, stack->name);
    1.19  		swap((void **)&brush.fg, (void **)&brush.bg);
    1.20 -		brush.rect.x += brush.rect.width;
    1.21 +		brush.x += brush.w;
    1.22  	}
    1.23  
    1.24 -	brush.rect.width = textwidth(&brush.font, statustext) + labelheight(&brush.font);
    1.25 -	brush.rect.x = barrect.x + barrect.width - brush.rect.width;
    1.26 +	brush.w = textw(&brush.font, statustext) + bh;
    1.27 +	brush.x = bx + bw - brush.w;
    1.28  	draw(dpy, &brush, False, statustext);
    1.29 -
    1.30 -	XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, barrect.width,
    1.31 -			barrect.height, 0, 0);
    1.32 +	XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, bw, bh, 0, 0);
    1.33  	XFlush(dpy);
    1.34  }
     2.1 --- a/client.c	Wed Jul 12 00:53:11 2006 +0200
     2.2 +++ b/client.c	Wed Jul 12 15:17:22 2006 +0200
     2.3 @@ -10,7 +10,16 @@
     2.4  #include "util.h"
     2.5  #include "wm.h"
     2.6  
     2.7 -#define CLIENT_MASK		(StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
     2.8 +static void
     2.9 +resize_title(Client *c)
    2.10 +{
    2.11 +	c->tw = textw(&brush.font, c->name) + bh;
    2.12 +	if(c->tw > c->w)
    2.13 +		c->tw = c->w + 2;
    2.14 +	c->tx = c->x + c->w - c->tw + 2;
    2.15 +	c->ty = c->y;
    2.16 +	XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
    2.17 +}
    2.18  
    2.19  void
    2.20  update_name(Client *c)
    2.21 @@ -37,6 +46,7 @@
    2.22  		}
    2.23  	}
    2.24  	XFree(name.value);
    2.25 +	resize_title(c);
    2.26  }
    2.27  
    2.28  void
    2.29 @@ -74,26 +84,37 @@
    2.30  }
    2.31  
    2.32  void
    2.33 +raise(Client *c)
    2.34 +{
    2.35 +	XRaiseWindow(dpy, c->win);
    2.36 +	XRaiseWindow(dpy, c->title);
    2.37 +}
    2.38 +
    2.39 +void
    2.40 +lower(Client *c)
    2.41 +{
    2.42 +	XLowerWindow(dpy, c->title);
    2.43 +	XLowerWindow(dpy, c->win);
    2.44 +}
    2.45 +
    2.46 +void
    2.47  focus(Client *c)
    2.48  {
    2.49  	Client **l, *old;
    2.50  
    2.51  	old = stack;
    2.52 -	for(l=&stack; *l && *l != c; l=&(*l)->snext);
    2.53 +	for(l = &stack; *l && *l != c; l = &(*l)->snext);
    2.54  	eassert(*l == c);
    2.55  	*l = c->snext;
    2.56  	c->snext = stack;
    2.57  	stack = c;
    2.58 -	XRaiseWindow(dpy, c->win);
    2.59 -	XRaiseWindow(dpy, c->title);
    2.60 -	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
    2.61  	if(old && old != c) {
    2.62  		XMapWindow(dpy, old->title);
    2.63  		draw_client(old);
    2.64  	}
    2.65  	XUnmapWindow(dpy, c->title);
    2.66 -	draw_bar();
    2.67 -	discard_events(EnterWindowMask);
    2.68 +	draw_client(old);
    2.69 +	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
    2.70  	XFlush(dpy);
    2.71  }
    2.72  
    2.73 @@ -107,13 +128,16 @@
    2.74  	c->win = w;
    2.75  	c->tx = c->x = wa->x;
    2.76  	c->ty = c->y = wa->y;
    2.77 +	if(c->y < bh)
    2.78 +		c->ty = c->y += bh;
    2.79  	c->tw = c->w = wa->width;
    2.80  	c->h = wa->height;
    2.81 -	c->th = barrect.height;
    2.82 +	c->th = bh;
    2.83  	update_size(c);
    2.84  	XSetWindowBorderWidth(dpy, c->win, 1);
    2.85  	XSetWindowBorder(dpy, c->win, brush.border);
    2.86 -	XSelectInput(dpy, c->win, CLIENT_MASK);
    2.87 +	XSelectInput(dpy, c->win,
    2.88 +			StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
    2.89  	XGetTransientForHint(dpy, c->win, &c->trans);
    2.90  	twa.override_redirect = 1;
    2.91  	twa.background_pixmap = ParentRelative;
    2.92 @@ -130,8 +154,8 @@
    2.93  	*l = c;
    2.94  	c->snext = stack;
    2.95  	stack = c;
    2.96 -	XMapWindow(dpy, c->win);
    2.97 -	XMapWindow(dpy, c->title);
    2.98 +	XMapRaised(dpy, c->win);
    2.99 +	XMapRaised(dpy, c->title);
   2.100  	XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
   2.101  			GrabModeAsync, GrabModeSync, None, None);
   2.102  	XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
   2.103 @@ -147,6 +171,7 @@
   2.104  {
   2.105  	XConfigureEvent e;
   2.106  
   2.107 +	resize_title(c);
   2.108  	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
   2.109  	e.type = ConfigureNotify;
   2.110  	e.event = c->win;
   2.111 @@ -158,9 +183,7 @@
   2.112  	e.border_width = 0;
   2.113  	e.above = None;
   2.114  	e.override_redirect = False;
   2.115 -	XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
   2.116  	XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
   2.117 -	XSelectInput(dpy, c->win, CLIENT_MASK);
   2.118  	XFlush(dpy);
   2.119  }
   2.120  
   2.121 @@ -219,17 +242,14 @@
   2.122  void
   2.123  draw_client(Client *c)
   2.124  {
   2.125 -	if(c == stack)
   2.126 +	if(c == stack) {
   2.127  		draw_bar();
   2.128 +		return;
   2.129 +	}
   2.130  
   2.131 -	c->tw = textwidth(&brush.font, c->name) + labelheight(&brush.font);
   2.132 -	c->tx = c->x + c->w - c->tw + 2;
   2.133 -	c->ty = c->y;
   2.134 -	XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
   2.135 -
   2.136 -	brush.rect.x = brush.rect.y = 0;
   2.137 -	brush.rect.width = c->tw;
   2.138 -	brush.rect.height = c->th;
   2.139 +	brush.x = brush.y = 0;
   2.140 +	brush.w = c->tw;
   2.141 +	brush.h = c->th;
   2.142  
   2.143  	draw(dpy, &brush, True, c->name);
   2.144  	XCopyArea(dpy, brush.drawable, c->title, brush.gc,
     3.1 --- a/cmd.c	Wed Jul 12 00:53:11 2006 +0200
     3.2 +++ b/cmd.c	Wed Jul 12 15:17:22 2006 +0200
     3.3 @@ -23,16 +23,18 @@
     3.4  sel(void *aux)
     3.5  {
     3.6  	const char *arg = aux;
     3.7 -	Client *c;
     3.8 +	Client *c = NULL;
     3.9  
    3.10  	if(!arg || !stack)
    3.11  		return;
    3.12  	if(!strncmp(arg, "next", 5))
    3.13 -		focus(stack->snext ? stack->snext : stack);
    3.14 -	else if(!strncmp(arg, "prev", 5)) {
    3.15 +		c = stack->snext ? stack->snext : stack;
    3.16 +	else if(!strncmp(arg, "prev", 5))
    3.17  		for(c = stack; c && c->snext; c = c->snext);
    3.18 -		focus(c ? c : stack);
    3.19 -	}
    3.20 +	if(!c)
    3.21 +		c = stack;
    3.22 +	raise(c);
    3.23 +	focus(c);
    3.24  }
    3.25  
    3.26  void
     4.1 --- a/config.h	Wed Jul 12 00:53:11 2006 +0200
     4.2 +++ b/config.h	Wed Jul 12 15:17:22 2006 +0200
     4.3 @@ -4,7 +4,7 @@
     4.4   */
     4.5  
     4.6  #define FONT		"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
     4.7 -#define BGCOLOR		"#0c0c33"
     4.8 -#define FGCOLOR		"#b2c8cd"
     4.9 -#define BORDERCOLOR	"#3030c0"
    4.10 -#define STATUSDELAY	10 /* milliseconds */
    4.11 +#define BGCOLOR		"#666699"
    4.12 +#define FGCOLOR		"#ffffff"
    4.13 +#define BORDERCOLOR	"#9999CC"
    4.14 +#define STATUSDELAY	10 /* seconds */
     5.1 --- a/draw.c	Wed Jul 12 00:53:11 2006 +0200
     5.2 +++ b/draw.c	Wed Jul 12 15:17:22 2006 +0200
     5.3 @@ -15,16 +15,16 @@
     5.4  	XPoint points[5];
     5.5  	XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter);
     5.6  	XSetForeground(dpy, b->gc, b->border);
     5.7 -	points[0].x = b->rect.x;
     5.8 -	points[0].y = b->rect.y;
     5.9 -	points[1].x = b->rect.width - 1;
    5.10 +	points[0].x = b->x;
    5.11 +	points[0].y = b->y;
    5.12 +	points[1].x = b->w - 1;
    5.13  	points[1].y = 0;
    5.14  	points[2].x = 0;
    5.15 -	points[2].y = b->rect.height - 1;
    5.16 -	points[3].x = -(b->rect.width - 1);
    5.17 +	points[2].y = b->h - 1;
    5.18 +	points[3].x = -(b->w - 1);
    5.19  	points[3].y = 0;
    5.20  	points[4].x = 0;
    5.21 -	points[4].y = -(b->rect.height - 1);
    5.22 +	points[4].y = -(b->h - 1);
    5.23  	XDrawLines(dpy, b->drawable, b->gc, points, 5, CoordModePrevious);
    5.24  }
    5.25  
    5.26 @@ -34,9 +34,10 @@
    5.27  	unsigned int x, y, w, h, len;
    5.28  	static char buf[256];
    5.29  	XGCValues gcv;
    5.30 +	XRectangle r = { b->x, b->y, b->w, b->h };
    5.31  
    5.32  	XSetForeground(dpy, b->gc, b->bg);
    5.33 -	XFillRectangles(dpy, b->drawable, b->gc, &b->rect, 1);
    5.34 +	XFillRectangles(dpy, b->drawable, b->gc, &r, 1);
    5.35  
    5.36  	if(border)
    5.37  		drawborder(dpy, b);
    5.38 @@ -51,14 +52,14 @@
    5.39  	buf[len] = 0;
    5.40  
    5.41  	h = b->font.ascent + b->font.descent;
    5.42 -	y = b->rect.y + (b->rect.height / 2) - (h / 2) + b->font.ascent;
    5.43 -	x = b->rect.x + (h / 2);
    5.44 +	y = b->y + (b->h / 2) - (h / 2) + b->font.ascent;
    5.45 +	x = b->x + (h / 2);
    5.46  
    5.47  	/* shorten text if necessary */
    5.48 -	while(len && (w = textwidth_l(&b->font, buf, len)) > b->rect.width - h)
    5.49 +	while(len && (w = textnw(&b->font, buf, len)) > b->w - h)
    5.50  		buf[--len] = 0;
    5.51  
    5.52 -	if(w > b->rect.width)
    5.53 +	if(w > b->w)
    5.54  		return; /* too long */
    5.55  
    5.56  	gcv.foreground = b->fg;
    5.57 @@ -94,20 +95,26 @@
    5.58  }
    5.59  
    5.60  unsigned int
    5.61 -textwidth_l(Fnt *font, char *text, unsigned int len)
    5.62 +textnw(Fnt *font, char *text, unsigned int len)
    5.63  {
    5.64 +	XRectangle r;
    5.65  	if(font->set) {
    5.66 -		XRectangle r;
    5.67 -		XmbTextExtents(font->set, text, len, 0, &r);
    5.68 +		XmbTextExtents(font->set, text, len, NULL, &r);
    5.69  		return r.width;
    5.70  	}
    5.71  	return XTextWidth(font->xfont, text, len);
    5.72  }
    5.73  
    5.74  unsigned int
    5.75 -textwidth(Fnt *font, char *text)
    5.76 +textw(Fnt *font, char *text)
    5.77  {
    5.78 -	return textwidth_l(font, text, strlen(text));
    5.79 +	return textnw(font, text, strlen(text));
    5.80 +}
    5.81 +
    5.82 +unsigned int
    5.83 +texth(Fnt *font)
    5.84 +{
    5.85 +	return font->height + 4;
    5.86  }
    5.87  
    5.88  void
    5.89 @@ -162,9 +169,3 @@
    5.90  	}
    5.91  	font->height = font->ascent + font->descent;
    5.92  }
    5.93 -
    5.94 -unsigned int
    5.95 -labelheight(Fnt *font)
    5.96 -{
    5.97 -	return font->height + 4;
    5.98 -}
     6.1 --- a/draw.h	Wed Jul 12 00:53:11 2006 +0200
     6.2 +++ b/draw.h	Wed Jul 12 15:17:22 2006 +0200
     6.3 @@ -20,7 +20,7 @@
     6.4  struct Brush {
     6.5  	GC gc;
     6.6  	Drawable drawable;
     6.7 -	XRectangle rect;
     6.8 +	int x, y, w, h;
     6.9  	Fnt font;
    6.10  	unsigned long bg;
    6.11  	unsigned long fg;
    6.12 @@ -31,6 +31,6 @@
    6.13  extern void loadcolors(Display *dpy, int screen, Brush *b,
    6.14  		const char *bg, const char *fg, const char *bo);
    6.15  extern void loadfont(Display *dpy, Fnt *font, const char *fontstr);
    6.16 -extern unsigned int textwidth_l(Fnt *font, char *text, unsigned int len);
    6.17 -extern unsigned int textwidth(Fnt *font, char *text);
    6.18 -extern unsigned int labelheight(Fnt *font);
    6.19 +extern unsigned int textnw(Fnt *font, char *text, unsigned int len);
    6.20 +extern unsigned int textw(Fnt *font, char *text);
    6.21 +extern unsigned int texth(Fnt *font);
     7.1 --- a/event.c	Wed Jul 12 00:53:11 2006 +0200
     7.2 +++ b/event.c	Wed Jul 12 15:17:22 2006 +0200
     7.3 @@ -37,13 +37,11 @@
     7.4  	[UnmapNotify] = unmapnotify
     7.5  };
     7.6  
     7.7 -unsigned int
     7.8 +void
     7.9  discard_events(long even_mask)
    7.10  {
    7.11  	XEvent ev;
    7.12 -	unsigned int n = 0;
    7.13 -	while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
    7.14 -	return n;
    7.15 +	while(XCheckMaskEvent(dpy, even_mask, &ev));
    7.16  }
    7.17  
    7.18  static void
    7.19 @@ -53,6 +51,7 @@
    7.20  	Client *c;
    7.21  
    7.22  	if((c = getclient(ev->window))) {
    7.23 +		raise(c);
    7.24  		switch(ev->button) {
    7.25  		default:
    7.26  			break;
    7.27 @@ -60,7 +59,7 @@
    7.28  			mmove(c);
    7.29  			break;
    7.30  		case Button2:
    7.31 -			XLowerWindow(dpy, c->win);
    7.32 +			lower(c);
    7.33  			break;
    7.34  		case Button3:
    7.35  			mresize(c);
    7.36 @@ -122,10 +121,8 @@
    7.37  
    7.38  	if((c = getclient(ev->window)))
    7.39  		focus(c);
    7.40 -	else if(ev->window == root) {
    7.41 +	else if(ev->window == root)
    7.42  		sel_screen = True;
    7.43 -		/*draw_frames();*/
    7.44 -	}
    7.45  }
    7.46  
    7.47  static void
    7.48 @@ -133,10 +130,8 @@
    7.49  {
    7.50  	XCrossingEvent *ev = &e->xcrossing;
    7.51  
    7.52 -	if((ev->window == root) && !ev->same_screen) {
    7.53 +	if((ev->window == root) && !ev->same_screen)
    7.54  		sel_screen = True;
    7.55 -		/*draw_frames();*/
    7.56 -	}
    7.57  }
    7.58  
    7.59  static void
     8.1 --- a/font.c	Wed Jul 12 00:53:11 2006 +0200
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,81 +0,0 @@
     8.4 -/*
     8.5 - * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
     8.6 - * See LICENSE file for license details.
     8.7 - */
     8.8 -
     8.9 -#include <stdio.h>
    8.10 -#include <stdlib.h>
    8.11 -#include <string.h>
    8.12 -#include <locale.h>
    8.13 -
    8.14 -unsigned int
    8.15 -textwidth_l(BlitzFont *font, char *text, unsigned int len)
    8.16 -{
    8.17 -	if(font->set) {
    8.18 -		XRectangle r;
    8.19 -		XmbTextExtents(font->set, text, len, nil, &r);
    8.20 -		return r.width;
    8.21 -	}
    8.22 -	return XTextWidth(font->xfont, text, len);
    8.23 -}
    8.24 -
    8.25 -unsigned int
    8.26 -textwidth(BlitzFont *font, char *text)
    8.27 -{
    8.28 -	return blitz_textwidth_l(font, text, strlen(text));
    8.29 -}
    8.30 -
    8.31 -void
    8.32 -loadfont(Blitz *blitz, BlitzFont *font)
    8.33 -{
    8.34 -	char *fontname = font->fontstr;
    8.35 -	char **missing = nil, *def = "?";
    8.36 -	int n;
    8.37 -
    8.38 -	setlocale(LC_ALL, "");
    8.39 -	if(font->set)
    8.40 -		XFreeFontSet(blitz->dpy, font->set);
    8.41 -	font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
    8.42 -	if(missing) {
    8.43 -		while(n--)
    8.44 -			fprintf(stderr, "missing fontset: %s\n", missing[n]);
    8.45 -		XFreeStringList(missing);
    8.46 -		if(font->set) {
    8.47 -			XFreeFontSet(blitz->dpy, font->set);
    8.48 -			font->set = nil;
    8.49 -		}
    8.50 -	}
    8.51 -	if(font->set) {
    8.52 -		XFontSetExtents *font_extents;
    8.53 -		XFontStruct **xfonts;
    8.54 -		char **font_names;
    8.55 -		unsigned int i;
    8.56 -
    8.57 -		font->ascent = font->descent = 0;
    8.58 -		font_extents = XExtentsOfFontSet(font->set);
    8.59 -		n = XFontsOfFontSet(font->set, &xfonts, &font_names);
    8.60 -		for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
    8.61 -			if(font->ascent < (*xfonts)->ascent)
    8.62 -				font->ascent = (*xfonts)->ascent;
    8.63 -			if(font->descent < (*xfonts)->descent)
    8.64 -				font->descent = (*xfonts)->descent;
    8.65 -			xfonts++;
    8.66 -		}
    8.67 -	}
    8.68 -	else {
    8.69 -		if(font->xfont)
    8.70 -			XFreeFont(blitz->dpy, font->xfont);
    8.71 -		font->xfont = nil;
    8.72 -		font->xfont = XLoadQueryFont(blitz->dpy, fontname);
    8.73 -		if (!font->xfont) {
    8.74 -			fontname = "fixed";
    8.75 -			font->xfont = XLoadQueryFont(blitz->dpy, fontname);
    8.76 -		}
    8.77 -		if (!font->xfont) {
    8.78 -			fprintf(stderr, "%s", "error, cannot load 'fixed' font\n");
    8.79 -			exit(1);
    8.80 -		}
    8.81 -		font->ascent = font->xfont->ascent;
    8.82 -		font->descent = font->xfont->descent;
    8.83 -	}
    8.84 -}
     9.1 --- a/menu.c	Wed Jul 12 00:53:11 2006 +0200
     9.2 +++ b/menu.c	Wed Jul 12 15:17:22 2006 +0200
     9.3 @@ -31,7 +31,6 @@
     9.4  static Display *dpy;
     9.5  static Window root;
     9.6  static Window win;
     9.7 -static XRectangle rect;
     9.8  static Bool done = False;
     9.9  
    9.10  static Item *allitem = NULL;	/* first of all items */
    9.11 @@ -41,14 +40,14 @@
    9.12  static Item *prevoff = NULL;
    9.13  static Item *curroff = NULL;
    9.14  
    9.15 -static int screen;
    9.16 +static int screen, mx, my, mw, mh;
    9.17  static char *title = NULL;
    9.18  static char text[4096];
    9.19  static int ret = 0;
    9.20  static int nitem = 0;
    9.21  static unsigned int cmdw = 0;
    9.22 -static unsigned int twidth = 0;
    9.23 -static unsigned int cwidth = 0;
    9.24 +static unsigned int tw = 0;
    9.25 +static unsigned int cw = 0;
    9.26  static const int seek = 30;		/* 30px */
    9.27  
    9.28  static Brush brush = {0};
    9.29 @@ -74,21 +73,21 @@
    9.30  		return;
    9.31  
    9.32  	for(nextoff = curroff; nextoff; nextoff=nextoff->right) {
    9.33 -		tw = textwidth(&brush.font, nextoff->text);
    9.34 -		if(tw > rect.width / 3)
    9.35 -			tw = rect.width / 3;
    9.36 +		tw = textw(&brush.font, nextoff->text);
    9.37 +		if(tw > mw / 3)
    9.38 +			tw = mw / 3;
    9.39  		w += tw + brush.font.height;
    9.40 -		if(w > rect.width)
    9.41 +		if(w > mw)
    9.42  			break;
    9.43  	}
    9.44  
    9.45  	w = cmdw + 2 * seek;
    9.46  	for(prevoff = curroff; prevoff && prevoff->left; prevoff=prevoff->left) {
    9.47 -		tw = textwidth(&brush.font, prevoff->left->text);
    9.48 -		if(tw > rect.width / 3)
    9.49 -			tw = rect.width / 3;
    9.50 +		tw = textw(&brush.font, prevoff->left->text);
    9.51 +		if(tw > mw / 3)
    9.52 +			tw = mw / 3;
    9.53  		w += tw + brush.font.height;
    9.54 -		if(w > rect.width)
    9.55 +		if(w > mw)
    9.56  			break;
    9.57  	}
    9.58  }
    9.59 @@ -103,9 +102,9 @@
    9.60  		return;
    9.61  
    9.62  	if(!title || *pattern)
    9.63 -		cmdw = cwidth;
    9.64 +		cmdw = cw;
    9.65  	else
    9.66 -		cmdw = twidth;
    9.67 +		cmdw = tw;
    9.68  
    9.69  	item = j = NULL;
    9.70  	nitem = 0;
    9.71 @@ -143,42 +142,40 @@
    9.72  static void
    9.73  draw_menu()
    9.74  {
    9.75 -	unsigned int offx = 0;
    9.76  	Item *i;
    9.77  
    9.78 -	brush.rect = rect;
    9.79 -	brush.rect.x = 0;
    9.80 -	brush.rect.y = 0;
    9.81 +	brush.x = 0;
    9.82 +	brush.y = 0;
    9.83 +	brush.w = mw;
    9.84 +	brush.h = mh;
    9.85  	draw(dpy, &brush, False, 0);
    9.86  
    9.87  	/* print command */
    9.88  	if(!title || text[0]) {
    9.89 -		cmdw = cwidth;
    9.90 +		cmdw = cw;
    9.91  		if(cmdw && item)
    9.92 -			brush.rect.width = cmdw;
    9.93 +			brush.w = cmdw;
    9.94  		draw(dpy, &brush, False, text);
    9.95  	}
    9.96  	else {
    9.97 -		cmdw = twidth;
    9.98 -		brush.rect.width = cmdw;
    9.99 +		cmdw = tw;
   9.100 +		brush.w = cmdw;
   9.101  		draw(dpy, &brush, False, title);
   9.102  	}
   9.103 -	offx += brush.rect.width;
   9.104 +	brush.x += brush.w;
   9.105  
   9.106  	if(curroff) {
   9.107 -		brush.rect.x = offx;
   9.108 -		brush.rect.width = seek;
   9.109 -		offx += brush.rect.width;
   9.110 +		brush.w = seek;
   9.111  		draw(dpy, &brush, False, (curroff && curroff->left) ? "<" : 0);
   9.112 +		brush.x += brush.w;
   9.113  
   9.114  		/* determine maximum items */
   9.115  		for(i = curroff; i != nextoff; i=i->right) {
   9.116  			brush.border = False;
   9.117 -			brush.rect.x = offx;
   9.118 -			brush.rect.width = textwidth(&brush.font, i->text);
   9.119 -			if(brush.rect.width > rect.width / 3)
   9.120 -				brush.rect.width = rect.width / 3;
   9.121 -			brush.rect.width += brush.font.height;
   9.122 +			brush.w = textw(&brush.font, i->text);
   9.123 +			if(brush.w > mw / 3)
   9.124 +				brush.w = mw / 3;
   9.125 +			brush.w += brush.font.height;
   9.126  			if(sel == i) {
   9.127  				swap((void **)&brush.fg, (void **)&brush.bg);
   9.128  				draw(dpy, &brush, True, i->text);
   9.129 @@ -186,15 +183,14 @@
   9.130  			}
   9.131  			else
   9.132  				draw(dpy, &brush, False, i->text);
   9.133 -			offx += brush.rect.width;
   9.134 +			brush.x += brush.w;
   9.135  		}
   9.136  
   9.137 -		brush.rect.x = rect.width - seek;
   9.138 -		brush.rect.width = seek;
   9.139 +		brush.x = mw - seek;
   9.140 +		brush.w = seek;
   9.141  		draw(dpy, &brush, False, nextoff ? ">" : 0);
   9.142  	}
   9.143 -	XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, rect.width,
   9.144 -			rect.height, 0, 0);
   9.145 +	XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, mw, mh, 0, 0);
   9.146  	XFlush(dpy);
   9.147  }
   9.148  
   9.149 @@ -399,36 +395,35 @@
   9.150  	wa.background_pixmap = ParentRelative;
   9.151  	wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
   9.152  
   9.153 -	rect.width = DisplayWidth(dpy, screen);
   9.154 -	rect.height = labelheight(&brush.font);
   9.155 -	rect.y = DisplayHeight(dpy, screen) - rect.height;
   9.156 -	rect.x = 0;
   9.157 +	mx = my = 0;
   9.158 +	mw = DisplayWidth(dpy, screen);
   9.159 +	mh = texth(&brush.font);
   9.160  
   9.161 -	win = XCreateWindow(dpy, root, rect.x, rect.y,
   9.162 -			rect.width, rect.height, 0, DefaultDepth(dpy, screen),
   9.163 -			CopyFromParent, DefaultVisual(dpy, screen),
   9.164 +	win = XCreateWindow(dpy, root, mx, my, mw, mh, 0,
   9.165 +			DefaultDepth(dpy, screen), CopyFromParent,
   9.166 +			DefaultVisual(dpy, screen),
   9.167  			CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
   9.168  	XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm));
   9.169  	XFlush(dpy);
   9.170  
   9.171  	/* pixmap */
   9.172  	brush.gc = XCreateGC(dpy, root, 0, 0);
   9.173 -	brush.drawable = XCreatePixmap(dpy, win, rect.width, rect.height,
   9.174 +	brush.drawable = XCreatePixmap(dpy, win, mw, mh,
   9.175  			DefaultDepth(dpy, screen));
   9.176  	XFlush(dpy);
   9.177  
   9.178  	if(maxname)
   9.179 -		cwidth = textwidth(&brush.font, maxname) + brush.font.height;
   9.180 -	if(cwidth > rect.width / 3)
   9.181 -		cwidth = rect.width / 3;
   9.182 +		cw = textw(&brush.font, maxname) + brush.font.height;
   9.183 +	if(cw > mw / 3)
   9.184 +		cw = mw / 3;
   9.185  
   9.186  	if(title) {
   9.187 -		twidth = textwidth(&brush.font, title) + brush.font.height;
   9.188 -		if(twidth > rect.width / 3)
   9.189 -			twidth = rect.width / 3;
   9.190 +		tw = textw(&brush.font, title) + brush.font.height;
   9.191 +		if(tw > mw / 3)
   9.192 +			tw = mw / 3;
   9.193  	}
   9.194  
   9.195 -	cmdw = title ? twidth : cwidth;
   9.196 +	cmdw = title ? tw : cw;
   9.197  
   9.198  	text[0] = 0;
   9.199  	update_items(text);
    10.1 --- a/mouse.c	Wed Jul 12 00:53:11 2006 +0200
    10.2 +++ b/mouse.c	Wed Jul 12 15:17:22 2006 +0200
    10.3 @@ -45,21 +45,21 @@
    10.4  	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
    10.5  				None, cursor[CurResize], CurrentTime) != GrabSuccess)
    10.6  		return;
    10.7 -	XGrabServer(dpy);
    10.8  	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
    10.9  	for(;;) {
   10.10 -		XMaskEvent(dpy, MouseMask, &ev);
   10.11 +		XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
   10.12  		switch(ev.type) {
   10.13  		default: break;
   10.14 +		case Expose:
   10.15 +			handler[Expose](&ev);
   10.16 +			break;
   10.17  		case MotionNotify:
   10.18 -			XUngrabServer(dpy);
   10.19 +			XFlush(dpy);
   10.20  			mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
   10.21  			XResizeWindow(dpy, c->win, c->w, c->h);
   10.22 -			XGrabServer(dpy);
   10.23  			break;
   10.24  		case ButtonRelease:
   10.25  			resize(c);
   10.26 -			XUngrabServer(dpy);
   10.27  			XUngrabPointer(dpy, CurrentTime);
   10.28  			return;
   10.29  		}
   10.30 @@ -80,21 +80,21 @@
   10.31  				None, cursor[CurMove], CurrentTime) != GrabSuccess)
   10.32  		return;
   10.33  	XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
   10.34 -	XGrabServer(dpy);
   10.35  	for(;;) {
   10.36 -		XMaskEvent(dpy, MouseMask, &ev);
   10.37 +		XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
   10.38  		switch (ev.type) {
   10.39  		default: break;
   10.40 +		case Expose:
   10.41 +			handler[Expose](&ev);
   10.42 +			break;
   10.43  		case MotionNotify:
   10.44 -			XUngrabServer(dpy);
   10.45 +			XFlush(dpy);
   10.46  			c->x = old_cx + (ev.xmotion.x - x1);
   10.47  			c->y = old_cy + (ev.xmotion.y - y1);
   10.48  			XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
   10.49 -			XGrabServer(dpy);
   10.50  			break;
   10.51  		case ButtonRelease:
   10.52  			resize(c);
   10.53 -			XUngrabServer(dpy);
   10.54  			XUngrabPointer(dpy, CurrentTime);
   10.55  			return;
   10.56  		}
    11.1 --- a/wm.c	Wed Jul 12 00:53:11 2006 +0200
    11.2 +++ b/wm.c	Wed Jul 12 15:17:22 2006 +0200
    11.3 @@ -23,12 +23,11 @@
    11.4  Window root, barwin;
    11.5  Atom wm_atom[WMLast], net_atom[NetLast];
    11.6  Cursor cursor[CurLast];
    11.7 -XRectangle rect, barrect;
    11.8  Bool running = True;
    11.9  Bool sel_screen;
   11.10  
   11.11  char statustext[1024], tag[256];
   11.12 -int screen;
   11.13 +int screen, sx, sy, sw, sh, bx, by, bw, bh;
   11.14  
   11.15  Brush brush = {0};
   11.16  Client *clients = NULL;
   11.17 @@ -39,7 +38,7 @@
   11.18  static int (*x_error_handler) (Display *, XErrorEvent *);
   11.19  
   11.20  static const char *status[] = {
   11.21 -	"sh", "-c", "echo -n `date '+%Y/%m/%d %H:%M'`" 
   11.22 +	"sh", "-c", "echo -n `date '+%Y-%m-%d %H:%M'`" 
   11.23  	" `uptime | sed 's/.*://; s/,//g'`"
   11.24  	" `acpi | awk '{print $4}' | sed 's/,//'`", 0
   11.25  };
   11.26 @@ -220,9 +219,9 @@
   11.27  	if(other_wm_running)
   11.28  		error("gridwm: another window manager is already running\n");
   11.29  
   11.30 -	rect.x = rect.y = 0;
   11.31 -	rect.width = DisplayWidth(dpy, screen);
   11.32 -	rect.height = DisplayHeight(dpy, screen);
   11.33 +	sx = sy = 0;
   11.34 +	sw = DisplayWidth(dpy, screen);
   11.35 +	sh = DisplayHeight(dpy, screen);
   11.36  	sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
   11.37  
   11.38  	XSetErrorHandler(0);
   11.39 @@ -253,18 +252,16 @@
   11.40  	wa.background_pixmap = ParentRelative;
   11.41  	wa.event_mask = ExposureMask;
   11.42  
   11.43 -	barrect = rect;
   11.44 -	barrect.height = labelheight(&brush.font);
   11.45 -	barrect.y = rect.height - barrect.height;
   11.46 -	barwin = XCreateWindow(dpy, root, barrect.x, barrect.y,
   11.47 -			barrect.width, barrect.height, 0, DefaultDepth(dpy, screen),
   11.48 +	bx = by = 0;
   11.49 +	bw = sw;
   11.50 +	bh = texth(&brush.font);
   11.51 +	barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
   11.52  			CopyFromParent, DefaultVisual(dpy, screen),
   11.53  			CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
   11.54  	XDefineCursor(dpy, barwin, cursor[CurNormal]);
   11.55  	XMapRaised(dpy, barwin);
   11.56  
   11.57 -	brush.drawable = XCreatePixmap(dpy, root, rect.width, barrect.height,
   11.58 -			DefaultDepth(dpy, screen));
   11.59 +	brush.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
   11.60  	brush.gc = XCreateGC(dpy, root, 0, 0);
   11.61  
   11.62  	pipe_spawn(statustext, sizeof(statustext), dpy, (char **)status);
    12.1 --- a/wm.h	Wed Jul 12 00:53:11 2006 +0200
    12.2 +++ b/wm.h	Wed Jul 12 15:17:22 2006 +0200
    12.3 @@ -46,11 +46,10 @@
    12.4  extern Window root, barwin;
    12.5  extern Atom wm_atom[WMLast], net_atom[NetLast];
    12.6  extern Cursor cursor[CurLast];
    12.7 -extern XRectangle rect, barrect;
    12.8  extern Bool running, sel_screen, grid;
    12.9  extern void (*handler[LASTEvent]) (XEvent *);
   12.10  
   12.11 -extern int screen;
   12.12 +extern int screen, sx, sy, sw, sh, bx, by, bw, bh;
   12.13  extern char statustext[1024], tag[256];
   12.14  
   12.15  extern Brush brush;
   12.16 @@ -75,9 +74,11 @@
   12.17  extern void resize(Client *c);
   12.18  extern void update_size(Client *c);
   12.19  extern Client *gettitle(Window w);
   12.20 +extern void raise(Client *c);
   12.21 +extern void lower(Client *c);
   12.22  
   12.23  /* event.c */
   12.24 -extern unsigned int discard_events(long even_mask);
   12.25 +extern void discard_events(long even_mask);
   12.26  
   12.27  /* key.c */
   12.28  extern void update_keys();