dwm-meillo

diff client.c @ 31:386649deb651

before leaning things up
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 01:04:38 +0200
parents 2e0fb4130bfb
children 082c75b937b5
line diff
     1.1 --- a/client.c	Wed Jul 12 17:50:31 2006 +0200
     1.2 +++ b/client.c	Thu Jul 13 01:04:38 2006 +0200
     1.3 @@ -11,6 +11,8 @@
     1.4  #include "util.h"
     1.5  #include "wm.h"
     1.6  
     1.7 +void (*arrange)(void *aux);
     1.8 +
     1.9  void
    1.10  max(void *aux)
    1.11  {
    1.12 @@ -25,12 +27,24 @@
    1.13  }
    1.14  
    1.15  void
    1.16 -arrange(void *aux)
    1.17 +floating(void *aux)
    1.18 +{
    1.19 +	Client *c;
    1.20 +
    1.21 +	arrange = floating;
    1.22 +	for(c = stack; c; c = c->snext)
    1.23 +		resize(c);
    1.24 +	discard_events(EnterWindowMask);
    1.25 +}
    1.26 +
    1.27 +void
    1.28 +grid(void *aux)
    1.29  {
    1.30  	Client *c;
    1.31  	int n, cols, rows, gw, gh, i, j;
    1.32      float rt, fd;
    1.33  
    1.34 +	arrange = grid;
    1.35  	if(!clients)
    1.36  		return;
    1.37  	for(n = 0, c = clients; c; c = c->next, n++);
    1.38 @@ -95,7 +109,13 @@
    1.39  static void
    1.40  resize_title(Client *c)
    1.41  {
    1.42 -	c->tw = textw(&brush.font, c->name) + bh;
    1.43 +	int i;
    1.44 +
    1.45 +	c->tw = 0;
    1.46 +	for(i = 0; i < TLast; i++)
    1.47 +		if(c->tags[i])
    1.48 +			c->tw += textw(&brush.font, c->tags[i]) + bh;
    1.49 +	c->tw += textw(&brush.font, c->name) + bh;
    1.50  	if(c->tw > c->w)
    1.51  		c->tw = c->w + 2;
    1.52  	c->tx = c->x + c->w - c->tw + 2;
    1.53 @@ -190,8 +210,8 @@
    1.54  
    1.55  	old = stack;
    1.56  	for(l = &stack; *l && *l != c; l = &(*l)->snext);
    1.57 -	eassert(*l == c);
    1.58 -	*l = c->snext;
    1.59 +	if(*l)
    1.60 +		*l = c->snext;
    1.61  	c->snext = stack;
    1.62  	stack = c;
    1.63  	if(old && old != c) {
    1.64 @@ -230,17 +250,16 @@
    1.65  	twa.background_pixmap = ParentRelative;
    1.66  	twa.event_mask = ExposureMask;
    1.67  
    1.68 +	c->tags[tsel] = tags[tsel];
    1.69  	c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
    1.70  			0, DefaultDepth(dpy, screen), CopyFromParent,
    1.71  			DefaultVisual(dpy, screen),
    1.72  			CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
    1.73 +
    1.74  	update_name(c);
    1.75 -
    1.76  	for(l=&clients; *l; l=&(*l)->next);
    1.77  	c->next = *l; /* *l == nil */
    1.78  	*l = c;
    1.79 -	c->snext = stack;
    1.80 -	stack = c;
    1.81  	XMapRaised(dpy, c->win);
    1.82  	XMapRaised(dpy, c->title);
    1.83  	XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
    1.84 @@ -249,7 +268,7 @@
    1.85  			GrabModeAsync, GrabModeSync, None, None);
    1.86  	XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
    1.87  			GrabModeAsync, GrabModeSync, None, None);
    1.88 -	resize(c);
    1.89 +	arrange(NULL);
    1.90  	focus(c);
    1.91  }
    1.92  
    1.93 @@ -308,11 +327,24 @@
    1.94  	c->y += dy;
    1.95  }
    1.96  
    1.97 +
    1.98  void
    1.99  resize(Client *c)
   1.100  {
   1.101  	XConfigureEvent e;
   1.102  
   1.103 +	if(c->incw)
   1.104 +		c->w -= (c->w - c->basew) % c->incw;
   1.105 +	if(c->inch)
   1.106 +		c->h -= (c->h - c->baseh) % c->inch;
   1.107 +	if(c->minw && c->w < c->minw)
   1.108 +		c->w = c->minw;
   1.109 +	if(c->minh && c->h < c->minh)
   1.110 +		c->h = c->minh;
   1.111 +	if(c->maxw && c->w > c->maxw)
   1.112 +		c->w = c->maxw;
   1.113 +	if(c->maxh && c->h > c->maxh)
   1.114 +		c->h = c->maxh;
   1.115  	resize_title(c);
   1.116  	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
   1.117  	e.type = ConfigureNotify;
   1.118 @@ -357,6 +389,7 @@
   1.119  	XFlush(dpy);
   1.120  	XSetErrorHandler(error_handler);
   1.121  	XUngrabServer(dpy);
   1.122 +	arrange(NULL);
   1.123  	if(stack)
   1.124  		focus(stack);
   1.125  }
   1.126 @@ -384,15 +417,25 @@
   1.127  void
   1.128  draw_client(Client *c)
   1.129  {
   1.130 +	int i;
   1.131  	if(c == stack) {
   1.132  		draw_bar();
   1.133  		return;
   1.134  	}
   1.135  
   1.136  	brush.x = brush.y = 0;
   1.137 -	brush.w = c->tw;
   1.138  	brush.h = c->th;
   1.139  
   1.140 +	brush.w = 0;
   1.141 +	for(i = 0; i < TLast; i++) {
   1.142 +		if(c->tags[i]) {
   1.143 +			brush.x += brush.w;
   1.144 +			brush.w = textw(&brush.font, c->tags[i]) + bh;
   1.145 +			draw(dpy, &brush, True, c->tags[i]);
   1.146 +		}
   1.147 +	}
   1.148 +	brush.x += brush.w;
   1.149 +	brush.w = textw(&brush.font, c->name) + bh;
   1.150  	draw(dpy, &brush, True, c->name);
   1.151  	XCopyArea(dpy, brush.drawable, c->title, brush.gc,
   1.152  			0, 0, c->tw, c->th, 0, 0);