aewl

changeset 95:5d88952cbf96

implemened distinguishing float/managed geometries of clients (works quite well)
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 18 Jul 2006 12:36:57 +0200
parents 6efe82c775c9
children a5fd13035bf9
files client.c dwm.h event.c main.c tag.c
diffstat 5 files changed, 105 insertions(+), 78 deletions(-) [+]
line diff
     1.1 --- a/client.c	Tue Jul 18 11:45:32 2006 +0200
     1.2 +++ b/client.c	Tue Jul 18 12:36:57 2006 +0200
     1.3 @@ -16,16 +16,16 @@
     1.4  {
     1.5  	int i;
     1.6  
     1.7 -	c->tw = 0;
     1.8 +	c->bw = 0;
     1.9  	for(i = 0; i < TLast; i++)
    1.10  		if(c->tags[i])
    1.11 -			c->tw += textw(c->tags[i]);
    1.12 -	c->tw += textw(c->name);
    1.13 -	if(c->tw > c->w)
    1.14 -		c->tw = c->w + 2;
    1.15 -	c->tx = c->x + c->w - c->tw + 2;
    1.16 -	c->ty = c->y;
    1.17 -	XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
    1.18 +			c->bw += textw(c->tags[i]);
    1.19 +	c->bw += textw(c->name);
    1.20 +	if(c->bw > *c->w)
    1.21 +		c->bw = *c->w + 2;
    1.22 +	c->bx = *c->x + *c->w - c->bw + 2;
    1.23 +	c->by = *c->y;
    1.24 +	XMoveResizeWindow(dpy, c->title, c->bx, c->by, c->bw, c->bh);
    1.25  }
    1.26  
    1.27  static int
    1.28 @@ -39,8 +39,8 @@
    1.29  void
    1.30  ban(Client *c)
    1.31  {
    1.32 -	XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
    1.33 -	XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
    1.34 +	XMoveWindow(dpy, c->win, *c->x + 2 * sw, *c->y);
    1.35 +	XMoveWindow(dpy, c->title, c->bx + 2 * sw, c->by);
    1.36  }
    1.37  
    1.38  void
    1.39 @@ -124,12 +124,12 @@
    1.40  	case EastGravity:
    1.41  	case CenterGravity:
    1.42  	case WestGravity:
    1.43 -		dy = -(c->h / 2) + c->border;
    1.44 +		dy = -(*c->h / 2) + c->border;
    1.45  		break;
    1.46  	case SouthEastGravity:
    1.47  	case SouthGravity:
    1.48  	case SouthWestGravity:
    1.49 -		dy = -c->h;
    1.50 +		dy = -(*c->h);
    1.51  		break;
    1.52  	default:
    1.53  		break;
    1.54 @@ -145,12 +145,12 @@
    1.55  	case NorthGravity:
    1.56  	case CenterGravity:
    1.57  	case SouthGravity:
    1.58 -		dx = -(c->w / 2) + c->border;
    1.59 +		dx = -(*c->w / 2) + c->border;
    1.60  		break;
    1.61  	case NorthEastGravity:
    1.62  	case EastGravity:
    1.63  	case SouthEastGravity:
    1.64 -		dx = -(c->w + c->border);
    1.65 +		dx = -(*c->w + c->border);
    1.66  		break;
    1.67  	default:
    1.68  		break;
    1.69 @@ -160,8 +160,8 @@
    1.70  		dx = -dx;
    1.71  		dy = -dy;
    1.72  	}
    1.73 -	c->x += dx;
    1.74 -	c->y += dy;
    1.75 +	*c->x += dx;
    1.76 +	*c->y += dy;
    1.77  }
    1.78  
    1.79  void
    1.80 @@ -198,13 +198,13 @@
    1.81  
    1.82  	c = emallocz(sizeof(Client));
    1.83  	c->win = w;
    1.84 -	c->tx = c->x = wa->x;
    1.85 -	c->ty = c->y = wa->y;
    1.86 -	if(c->y < bh)
    1.87 -		c->ty = c->y += bh;
    1.88 -	c->tw = c->w = wa->width;
    1.89 -	c->h = wa->height;
    1.90 -	c->th = bh;
    1.91 +	c->bx = c->fx = c->tx = wa->x;
    1.92 +	c->by = c->fy = c->ty = wa->y;
    1.93 +	if(c->fy < bh)
    1.94 +		c->by = c->fy = c->ty += bh;
    1.95 +	c->bw = c->fw = c->tw = wa->width;
    1.96 +	c->fh = c->th = wa->height;
    1.97 +	c->bh = bh;
    1.98  	c->border = 1;
    1.99  	c->proto = getproto(c->win);
   1.100  	setsize(c);
   1.101 @@ -215,12 +215,11 @@
   1.102  	twa.background_pixmap = ParentRelative;
   1.103  	twa.event_mask = ExposureMask;
   1.104  
   1.105 -	c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
   1.106 +	c->title = XCreateWindow(dpy, root, c->bx, c->by, c->bw, c->bh,
   1.107  			0, DefaultDepth(dpy, screen), CopyFromParent,
   1.108  			DefaultVisual(dpy, screen),
   1.109  			CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
   1.110  
   1.111 -	settitle(c);
   1.112  	settags(c);
   1.113  
   1.114  	c->next = clients;
   1.115 @@ -239,7 +238,11 @@
   1.116  		c->isfloat = trans
   1.117  			|| ((c->maxw == c->minw) && (c->maxh == c->minh));
   1.118  
   1.119 +	setgeom(c);
   1.120 +	settitle(c);
   1.121 +
   1.122  	arrange(NULL);
   1.123 +
   1.124  	/* mapping the window now prevents flicker */
   1.125  	if(c->tags[tsel]) {
   1.126  		XMapRaised(dpy, c->win);
   1.127 @@ -259,10 +262,10 @@
   1.128  {
   1.129  	if(!sel)
   1.130  		return;
   1.131 -	sel->x = sx;
   1.132 -	sel->y = sy + bh;
   1.133 -	sel->w = sw - 2 * sel->border;
   1.134 -	sel->h = sh - 2 * sel->border - bh;
   1.135 +	*sel->x = sx;
   1.136 +	*sel->y = sy + bh;
   1.137 +	*sel->w = sw - 2 * sel->border;
   1.138 +	*sel->h = sh - 2 * sel->border - bh;
   1.139  	higher(sel);
   1.140  	resize(sel, False);
   1.141  }
   1.142 @@ -286,32 +289,32 @@
   1.143  
   1.144  	if(inc) {
   1.145  		if(c->incw)
   1.146 -			c->w -= (c->w - c->basew) % c->incw;
   1.147 +			*c->w -= (*c->w - c->basew) % c->incw;
   1.148  		if(c->inch)
   1.149 -			c->h -= (c->h - c->baseh) % c->inch;
   1.150 +			*c->h -= (*c->h - c->baseh) % c->inch;
   1.151  	}
   1.152 -	if(c->x > sw) /* might happen on restart */
   1.153 -		c->x = sw - c->w;
   1.154 -	if(c->y > sh)
   1.155 -		c->ty = c->y = sh - c->h;
   1.156 -	if(c->minw && c->w < c->minw)
   1.157 -		c->w = c->minw;
   1.158 -	if(c->minh && c->h < c->minh)
   1.159 -		c->h = c->minh;
   1.160 -	if(c->maxw && c->w > c->maxw)
   1.161 -		c->w = c->maxw;
   1.162 -	if(c->maxh && c->h > c->maxh)
   1.163 -		c->h = c->maxh;
   1.164 +	if(*c->x > sw) /* might happen on restart */
   1.165 +		*c->x = sw - *c->w;
   1.166 +	if(*c->y > sh)
   1.167 +		*c->y = sh - *c->h;
   1.168 +	if(c->minw && *c->w < c->minw)
   1.169 +		*c->w = c->minw;
   1.170 +	if(c->minh && *c->h < c->minh)
   1.171 +		*c->h = c->minh;
   1.172 +	if(c->maxw && *c->w > c->maxw)
   1.173 +		*c->w = c->maxw;
   1.174 +	if(c->maxh && *c->h > c->maxh)
   1.175 +		*c->h = c->maxh;
   1.176  	resizetitle(c);
   1.177  	XSetWindowBorderWidth(dpy, c->win, 1);
   1.178 -	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
   1.179 +	XMoveResizeWindow(dpy, c->win, *c->x, *c->y, *c->w, *c->h);
   1.180  	e.type = ConfigureNotify;
   1.181  	e.event = c->win;
   1.182  	e.window = c->win;
   1.183 -	e.x = c->x;
   1.184 -	e.y = c->y;
   1.185 -	e.width = c->w;
   1.186 -	e.height = c->h;
   1.187 +	e.x = *c->x;
   1.188 +	e.y = *c->y;
   1.189 +	e.width = *c->w;
   1.190 +	e.height = *c->h;
   1.191  	e.border_width = c->border;
   1.192  	e.above = None;
   1.193  	e.override_redirect = False;
   1.194 @@ -320,6 +323,23 @@
   1.195  }
   1.196  
   1.197  void
   1.198 +setgeom(Client *c)
   1.199 +{
   1.200 +	if((arrange == dotile) && !c->isfloat) {
   1.201 +		c->x = &c->tx;
   1.202 +		c->y = &c->ty;
   1.203 +		c->w = &c->tw;
   1.204 +		c->h = &c->th;
   1.205 +	}
   1.206 +	else {
   1.207 +		c->x = &c->fx;
   1.208 +		c->y = &c->fy;
   1.209 +		c->w = &c->fw;
   1.210 +		c->h = &c->fh;
   1.211 +	}
   1.212 +}
   1.213 +
   1.214 +void
   1.215  setsize(Client *c)
   1.216  {
   1.217  	XSizeHints size;
     2.1 --- a/dwm.h	Tue Jul 18 11:45:32 2006 +0200
     2.2 +++ b/dwm.h	Tue Jul 18 12:36:57 2006 +0200
     2.3 @@ -65,8 +65,10 @@
     2.4  	char name[256];
     2.5  	char *tags[TLast];
     2.6  	int proto;
     2.7 -	int x, y, w, h;
     2.8 -	int tx, ty, tw, th;
     2.9 +	int *x, *y, *w, *h; /* current geom */
    2.10 +	int bx, by, bw, bh; /* title bar */
    2.11 +	int fx, fy, fw, fh; /* floating geom */
    2.12 +	int tx, ty, tw, th; /* tiled geom */
    2.13  	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
    2.14  	int grav;
    2.15  	unsigned int border;
    2.16 @@ -120,6 +122,7 @@
    2.17  extern void maximize(Arg *arg);
    2.18  extern void pop(Client *c);
    2.19  extern void resize(Client *c, Bool inc);
    2.20 +extern void setgeom(Client *c);
    2.21  extern void setsize(Client *c);
    2.22  extern void settitle(Client *c);
    2.23  extern void unmanage(Client *c);
     3.1 --- a/event.c	Tue Jul 18 11:45:32 2006 +0200
     3.2 +++ b/event.c	Tue Jul 18 12:36:57 2006 +0200
     3.3 @@ -62,8 +62,8 @@
     3.4  	unsigned int dui;
     3.5  	Window dummy;
     3.6  
     3.7 -	ocx = c->x;
     3.8 -	ocy = c->y;
     3.9 +	ocx = *c->x;
    3.10 +	ocy = *c->y;
    3.11  	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
    3.12  				None, cursor[CurMove], CurrentTime) != GrabSuccess)
    3.13  		return;
    3.14 @@ -77,8 +77,8 @@
    3.15  			break;
    3.16  		case MotionNotify:
    3.17  			XSync(dpy, False);
    3.18 -			c->x = ocx + (ev.xmotion.x - x1);
    3.19 -			c->y = ocy + (ev.xmotion.y - y1);
    3.20 +			*c->x = ocx + (ev.xmotion.x - x1);
    3.21 +			*c->y = ocy + (ev.xmotion.y - y1);
    3.22  			resize(c, False);
    3.23  			break;
    3.24  		case ButtonRelease:
    3.25 @@ -94,12 +94,12 @@
    3.26  	XEvent ev;
    3.27  	int ocx, ocy;
    3.28  
    3.29 -	ocx = c->x;
    3.30 -	ocy = c->y;
    3.31 +	ocx = *c->x;
    3.32 +	ocy = *c->y;
    3.33  	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
    3.34  				None, cursor[CurResize], CurrentTime) != GrabSuccess)
    3.35  		return;
    3.36 -	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
    3.37 +	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, *c->w, *c->h);
    3.38  	for(;;) {
    3.39  		XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
    3.40  		switch(ev.type) {
    3.41 @@ -109,10 +109,10 @@
    3.42  			break;
    3.43  		case MotionNotify:
    3.44  			XSync(dpy, False);
    3.45 -			c->w = abs(ocx - ev.xmotion.x);
    3.46 -			c->h = abs(ocy - ev.xmotion.y);
    3.47 -			c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
    3.48 -			c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
    3.49 +			*c->w = abs(ocx - ev.xmotion.x);
    3.50 +			*c->h = abs(ocy - ev.xmotion.y);
    3.51 +			*c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - *c->w;
    3.52 +			*c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - *c->h;
    3.53  			resize(c, True);
    3.54  			break;
    3.55  		case ButtonRelease:
    3.56 @@ -187,13 +187,13 @@
    3.57  	if((c = getclient(ev->window))) {
    3.58  		gravitate(c, True);
    3.59  		if(ev->value_mask & CWX)
    3.60 -			c->x = ev->x;
    3.61 +			*c->x = ev->x;
    3.62  		if(ev->value_mask & CWY)
    3.63 -			c->y = ev->y;
    3.64 +			*c->y = ev->y;
    3.65  		if(ev->value_mask & CWWidth)
    3.66 -			c->w = ev->width;
    3.67 +			*c->w = ev->width;
    3.68  		if(ev->value_mask & CWHeight)
    3.69 -			c->h = ev->height;
    3.70 +			*c->h = ev->height;
    3.71  		if(ev->value_mask & CWBorderWidth)
    3.72  			c->border = 1;
    3.73  		gravitate(c, False);
     4.1 --- a/main.c	Tue Jul 18 11:45:32 2006 +0200
     4.2 +++ b/main.c	Tue Jul 18 12:36:57 2006 +0200
     4.3 @@ -261,6 +261,7 @@
     4.4  	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
     4.5  
     4.6  	strcpy(stext, "dwm-"VERSION);
     4.7 +
     4.8  	scan();
     4.9  
    4.10  	/* main event loop, reads status text from stdin as well */
     5.1 --- a/tag.c	Tue Jul 18 11:45:32 2006 +0200
     5.2 +++ b/tag.c	Tue Jul 18 12:36:57 2006 +0200
     5.3 @@ -43,8 +43,10 @@
     5.4  
     5.5  	arrange = dofloat;
     5.6  	for(c = clients; c; c = c->next) {
     5.7 -		if(c->tags[tsel])
     5.8 +		setgeom(c);
     5.9 +		if(c->tags[tsel]) {
    5.10  			resize(c, True);
    5.11 +		}
    5.12  		else
    5.13  			ban(c);
    5.14  	}
    5.15 @@ -75,6 +77,7 @@
    5.16  		h = sh - bh;
    5.17  
    5.18  	for(i = 0, c = clients; c; c = c->next) {
    5.19 +		setgeom(c);
    5.20  		if(c->tags[tsel]) {
    5.21  			if(c->isfloat) {
    5.22  				higher(c);
    5.23 @@ -82,22 +85,22 @@
    5.24  				continue;
    5.25  			}
    5.26  			if(n == 1) {
    5.27 -				c->x = sx;
    5.28 -				c->y = sy + bh;
    5.29 -				c->w = sw - 2 * c->border;
    5.30 -				c->h = sh - 2 * c->border - bh;
    5.31 +				*c->x = sx;
    5.32 +				*c->y = sy + bh;
    5.33 +				*c->w = sw - 2 * c->border;
    5.34 +				*c->h = sh - 2 * c->border - bh;
    5.35  			}
    5.36  			else if(i == 0) {
    5.37 -				c->x = sx;
    5.38 -				c->y = sy + bh;
    5.39 -				c->w = mw - 2 * c->border;
    5.40 -				c->h = sh - 2 * c->border - bh;
    5.41 +				*c->x = sx;
    5.42 +				*c->y = sy + bh;
    5.43 +				*c->w = mw - 2 * c->border;
    5.44 +				*c->h = sh - 2 * c->border - bh;
    5.45  			}
    5.46  			else {
    5.47 -				c->x = sx + mw;
    5.48 -				c->y = sy + (i - 1) * h + bh;
    5.49 -				c->w = w - 2 * c->border;
    5.50 -				c->h = h - 2 * c->border;
    5.51 +				*c->x = sx + mw;
    5.52 +				*c->y = sy + (i - 1) * h + bh;
    5.53 +				*c->w = w - 2 * c->border;
    5.54 +				*c->h = h - 2 * c->border;
    5.55  			}
    5.56  			resize(c, False);
    5.57  			i++;