aewl

diff client.c @ 49:466591c2f967

implemented tagging a client
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 17:09:35 +0200
parents 58307ad56ec1
children 148f25ed0ad7
line diff
     1.1 --- a/client.c	Thu Jul 13 14:33:22 2006 +0200
     1.2 +++ b/client.c	Thu Jul 13 17:09:35 2006 +0200
     1.3 @@ -11,44 +11,76 @@
     1.4  
     1.5  #include "dwm.h"
     1.6  
     1.7 -static void (*arrange)(void *) = floating;
     1.8 +static void (*arrange)(Arg *) = floating;
     1.9 +
    1.10 +static Client *
    1.11 +next(Client *c)
    1.12 +{
    1.13 +	for(c = c->next; c && !c->tags[tsel]; c = c->next);
    1.14 +	return c;
    1.15 +}
    1.16 +
    1.17 +static Client *
    1.18 +prev(Client *c)
    1.19 +{
    1.20 +	for(c = c->prev; c && !c->tags[tsel]; c = c->prev);
    1.21 +	return c;
    1.22 +}
    1.23  
    1.24  void
    1.25 -max(void *aux)
    1.26 +max(Arg *arg)
    1.27  {
    1.28 -	if(!stack)
    1.29 +	if(!csel)
    1.30  		return;
    1.31 -	stack->x = sx;
    1.32 -	stack->y = sy;
    1.33 -	stack->w = sw - 2 * stack->border;
    1.34 -	stack->h = sh - 2 * stack->border;
    1.35 -	craise(stack);
    1.36 -	resize(stack);
    1.37 +	csel->x = sx;
    1.38 +	csel->y = sy;
    1.39 +	csel->w = sw - 2 * csel->border;
    1.40 +	csel->h = sh - 2 * csel->border;
    1.41 +	craise(csel);
    1.42 +	resize(csel);
    1.43  	discard_events(EnterWindowMask);
    1.44  }
    1.45  
    1.46  void
    1.47 -floating(void *aux)
    1.48 +tag(Arg *arg)
    1.49 +{
    1.50 +	if(!csel)
    1.51 +		return;
    1.52 +
    1.53 +	if(arg->i == tsel)
    1.54 +		return;
    1.55 +
    1.56 +	if(csel->tags[arg->i])
    1.57 +		csel->tags[arg->i] = NULL; /* toggle tag */
    1.58 +	else
    1.59 +		csel->tags[arg->i] = tags[arg->i];
    1.60 +	arrange(NULL);
    1.61 +}
    1.62 +
    1.63 +void
    1.64 +floating(Arg *arg)
    1.65  {
    1.66  	Client *c;
    1.67  
    1.68  	arrange = floating;
    1.69 -	for(c = stack; c; c = c->snext)
    1.70 +	if(!csel)
    1.71 +		return;
    1.72 +	for(c = csel; c; c = next(c))
    1.73  		resize(c);
    1.74  	discard_events(EnterWindowMask);
    1.75  }
    1.76  
    1.77  void
    1.78 -tiling(void *aux)
    1.79 +tiling(Arg *arg)
    1.80  {
    1.81  	Client *c;
    1.82  	int n, cols, rows, gw, gh, i, j;
    1.83      float rt, fd;
    1.84  
    1.85  	arrange = tiling;
    1.86 -	if(!clients)
    1.87 +	if(!csel)
    1.88  		return;
    1.89 -	for(n = 0, c = clients; c; c = c->next, n++);
    1.90 +	for(n = 0, c = csel; c; c = next(c), n++);
    1.91  	rt = sqrt(n);
    1.92  	if(modff(rt, &fd) < 0.5)
    1.93  		rows = floor(rt);
    1.94 @@ -62,7 +94,7 @@
    1.95  	gw = (sw - 2)  / cols;
    1.96  	gh = (sh - 2) / rows;
    1.97  
    1.98 -	for(i = j = 0, c = clients; c; c = c->next) {
    1.99 +	for(i = j = 0, c = csel; c; c = next(c)) {
   1.100  		c->x = i * gw;
   1.101  		c->y = j * gh;
   1.102  		c->w = gw;
   1.103 @@ -77,28 +109,44 @@
   1.104  }
   1.105  
   1.106  void
   1.107 -sel(void *aux)
   1.108 +prevc(Arg *arg)
   1.109  {
   1.110 -	const char *arg = aux;
   1.111 -	Client *c = NULL;
   1.112 +	Client *c;
   1.113  
   1.114 -	if(!arg || !stack)
   1.115 +	if(!csel)
   1.116  		return;
   1.117 -	if(!strncmp(arg, "next", 5))
   1.118 -		c = stack->snext ? stack->snext : stack;
   1.119 -	else if(!strncmp(arg, "prev", 5))
   1.120 -		for(c = stack; c && c->snext; c = c->snext);
   1.121 -	if(!c)
   1.122 -		c = stack;
   1.123 -	craise(c);
   1.124 -	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
   1.125 -	focus(c);
   1.126 +
   1.127 +	if(!(c = prev(csel)))
   1.128 +		c = prev(cend);
   1.129 +	if(c) {
   1.130 +		craise(c);
   1.131 +		XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
   1.132 +		focus(c);
   1.133 +	}
   1.134  }
   1.135  
   1.136  void
   1.137 -ckill(void *aux)
   1.138 +nextc(Arg *arg)
   1.139  {
   1.140 -	Client *c = stack;
   1.141 +	Client *c;
   1.142 +   
   1.143 +	if(!csel)
   1.144 +		return;
   1.145 +
   1.146 +	if(!(c = next(csel)))
   1.147 +		c = next(cstart);
   1.148 +
   1.149 +	if(c) {
   1.150 +		craise(c);
   1.151 +		XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
   1.152 +		focus(c);
   1.153 +	}
   1.154 +}
   1.155 +
   1.156 +void
   1.157 +ckill(Arg *arg)
   1.158 +{
   1.159 +	Client *c = csel;
   1.160  
   1.161  	if(!c)
   1.162  		return;
   1.163 @@ -208,19 +256,12 @@
   1.164  void
   1.165  focus(Client *c)
   1.166  {
   1.167 -	Client **l, *old;
   1.168 -
   1.169 -	old = stack;
   1.170 -	for(l = &stack; *l && *l != c; l = &(*l)->snext);
   1.171 -	if(*l)
   1.172 -		*l = c->snext;
   1.173 -	c->snext = stack;
   1.174 -	stack = c;
   1.175 -	if(old && old != c) {
   1.176 -		XSetWindowBorder(dpy, old->win, dc.bg);
   1.177 -		XMapWindow(dpy, old->title);
   1.178 -		draw_client(old);
   1.179 +	if(csel && csel != c) {
   1.180 +		XSetWindowBorder(dpy, csel->win, dc.bg);
   1.181 +		XMapWindow(dpy, csel->title);
   1.182 +		draw_client(csel);
   1.183  	}
   1.184 +	csel = c;
   1.185  	XUnmapWindow(dpy, c->title);
   1.186  	XSetWindowBorder(dpy, c->win, dc.fg);
   1.187  	draw_client(c);
   1.188 @@ -232,7 +273,7 @@
   1.189  void
   1.190  manage(Window w, XWindowAttributes *wa)
   1.191  {
   1.192 -	Client *c, **l;
   1.193 +	Client *c;
   1.194  	XSetWindowAttributes twa;
   1.195  
   1.196  	c = emallocz(sizeof(Client));
   1.197 @@ -258,9 +299,15 @@
   1.198  			CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
   1.199  
   1.200  	update_name(c);
   1.201 -	for(l=&clients; *l; l=&(*l)->next);
   1.202 -	c->next = *l; /* *l == nil */
   1.203 -	*l = c;
   1.204 +
   1.205 +	if(!cstart)
   1.206 +		cstart = cend = c;
   1.207 +	else {
   1.208 +		cend->next = c;
   1.209 +		c->prev = cend;
   1.210 +		cend = c;
   1.211 +	}
   1.212 +
   1.213  	XSetWindowBorderWidth(dpy, c->win, 1);
   1.214  	XMapRaised(dpy, c->win);
   1.215  	XMapRaised(dpy, c->title);
   1.216 @@ -373,33 +420,42 @@
   1.217  void
   1.218  unmanage(Client *c)
   1.219  {
   1.220 -	Client **l;
   1.221 -
   1.222  	XGrabServer(dpy);
   1.223  	XSetErrorHandler(dummy_error_handler);
   1.224  
   1.225  	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
   1.226  	XDestroyWindow(dpy, c->title);
   1.227  
   1.228 -	for(l=&clients; *l && *l != c; l=&(*l)->next);
   1.229 -	*l = c->next;
   1.230 -	for(l=&stack; *l && *l != c; l=&(*l)->snext);
   1.231 -	*l = c->snext;
   1.232 +	if(c->prev) {
   1.233 +		c->prev->next = c->next;
   1.234 +		if(csel == c)
   1.235 +			csel = c->prev;
   1.236 +	}
   1.237 +	if(c->next) {
   1.238 +		c->next->prev = c->prev;
   1.239 +		if(csel == c)
   1.240 +			csel = c->next;
   1.241 +	}
   1.242 +	if(cstart == c)
   1.243 +		cstart = c->next;
   1.244 +	if(cend == c)
   1.245 +		cend = c->prev;
   1.246 +
   1.247  	free(c);
   1.248  
   1.249  	XFlush(dpy);
   1.250  	XSetErrorHandler(error_handler);
   1.251  	XUngrabServer(dpy);
   1.252  	arrange(NULL);
   1.253 -	if(stack)
   1.254 -		focus(stack);
   1.255 +	if(csel)
   1.256 +		focus(csel);
   1.257  }
   1.258  
   1.259  Client *
   1.260  gettitle(Window w)
   1.261  {
   1.262  	Client *c;
   1.263 -	for(c = clients; c; c = c->next)
   1.264 +	for(c = cstart; c; c = c->next)
   1.265  		if(c->title == w)
   1.266  			return c;
   1.267  	return NULL;
   1.268 @@ -409,7 +465,7 @@
   1.269  getclient(Window w)
   1.270  {
   1.271  	Client *c;
   1.272 -	for(c = clients; c; c = c->next)
   1.273 +	for(c = cstart; c; c = c->next)
   1.274  		if(c->win == w)
   1.275  			return c;
   1.276  	return NULL;
   1.277 @@ -419,7 +475,7 @@
   1.278  draw_client(Client *c)
   1.279  {
   1.280  	int i;
   1.281 -	if(c == stack)
   1.282 +	if(c == csel)
   1.283  		return;
   1.284  
   1.285  	dc.x = dc.y = 0;