dwm-meillo

diff client.c @ 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 95ffdfd0a819
children f96fb3fd8203
line diff
     1.1 --- a/client.c	Wed Jul 12 00:53:11 2006 +0200
     1.2 +++ b/client.c	Wed Jul 12 15:17:22 2006 +0200
     1.3 @@ -10,7 +10,16 @@
     1.4  #include "util.h"
     1.5  #include "wm.h"
     1.6  
     1.7 -#define CLIENT_MASK		(StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
     1.8 +static void
     1.9 +resize_title(Client *c)
    1.10 +{
    1.11 +	c->tw = textw(&brush.font, c->name) + bh;
    1.12 +	if(c->tw > c->w)
    1.13 +		c->tw = c->w + 2;
    1.14 +	c->tx = c->x + c->w - c->tw + 2;
    1.15 +	c->ty = c->y;
    1.16 +	XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
    1.17 +}
    1.18  
    1.19  void
    1.20  update_name(Client *c)
    1.21 @@ -37,6 +46,7 @@
    1.22  		}
    1.23  	}
    1.24  	XFree(name.value);
    1.25 +	resize_title(c);
    1.26  }
    1.27  
    1.28  void
    1.29 @@ -74,26 +84,37 @@
    1.30  }
    1.31  
    1.32  void
    1.33 +raise(Client *c)
    1.34 +{
    1.35 +	XRaiseWindow(dpy, c->win);
    1.36 +	XRaiseWindow(dpy, c->title);
    1.37 +}
    1.38 +
    1.39 +void
    1.40 +lower(Client *c)
    1.41 +{
    1.42 +	XLowerWindow(dpy, c->title);
    1.43 +	XLowerWindow(dpy, c->win);
    1.44 +}
    1.45 +
    1.46 +void
    1.47  focus(Client *c)
    1.48  {
    1.49  	Client **l, *old;
    1.50  
    1.51  	old = stack;
    1.52 -	for(l=&stack; *l && *l != c; l=&(*l)->snext);
    1.53 +	for(l = &stack; *l && *l != c; l = &(*l)->snext);
    1.54  	eassert(*l == c);
    1.55  	*l = c->snext;
    1.56  	c->snext = stack;
    1.57  	stack = c;
    1.58 -	XRaiseWindow(dpy, c->win);
    1.59 -	XRaiseWindow(dpy, c->title);
    1.60 -	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
    1.61  	if(old && old != c) {
    1.62  		XMapWindow(dpy, old->title);
    1.63  		draw_client(old);
    1.64  	}
    1.65  	XUnmapWindow(dpy, c->title);
    1.66 -	draw_bar();
    1.67 -	discard_events(EnterWindowMask);
    1.68 +	draw_client(old);
    1.69 +	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
    1.70  	XFlush(dpy);
    1.71  }
    1.72  
    1.73 @@ -107,13 +128,16 @@
    1.74  	c->win = w;
    1.75  	c->tx = c->x = wa->x;
    1.76  	c->ty = c->y = wa->y;
    1.77 +	if(c->y < bh)
    1.78 +		c->ty = c->y += bh;
    1.79  	c->tw = c->w = wa->width;
    1.80  	c->h = wa->height;
    1.81 -	c->th = barrect.height;
    1.82 +	c->th = bh;
    1.83  	update_size(c);
    1.84  	XSetWindowBorderWidth(dpy, c->win, 1);
    1.85  	XSetWindowBorder(dpy, c->win, brush.border);
    1.86 -	XSelectInput(dpy, c->win, CLIENT_MASK);
    1.87 +	XSelectInput(dpy, c->win,
    1.88 +			StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
    1.89  	XGetTransientForHint(dpy, c->win, &c->trans);
    1.90  	twa.override_redirect = 1;
    1.91  	twa.background_pixmap = ParentRelative;
    1.92 @@ -130,8 +154,8 @@
    1.93  	*l = c;
    1.94  	c->snext = stack;
    1.95  	stack = c;
    1.96 -	XMapWindow(dpy, c->win);
    1.97 -	XMapWindow(dpy, c->title);
    1.98 +	XMapRaised(dpy, c->win);
    1.99 +	XMapRaised(dpy, c->title);
   1.100  	XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
   1.101  			GrabModeAsync, GrabModeSync, None, None);
   1.102  	XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
   1.103 @@ -147,6 +171,7 @@
   1.104  {
   1.105  	XConfigureEvent e;
   1.106  
   1.107 +	resize_title(c);
   1.108  	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
   1.109  	e.type = ConfigureNotify;
   1.110  	e.event = c->win;
   1.111 @@ -158,9 +183,7 @@
   1.112  	e.border_width = 0;
   1.113  	e.above = None;
   1.114  	e.override_redirect = False;
   1.115 -	XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
   1.116  	XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
   1.117 -	XSelectInput(dpy, c->win, CLIENT_MASK);
   1.118  	XFlush(dpy);
   1.119  }
   1.120  
   1.121 @@ -219,17 +242,14 @@
   1.122  void
   1.123  draw_client(Client *c)
   1.124  {
   1.125 -	if(c == stack)
   1.126 +	if(c == stack) {
   1.127  		draw_bar();
   1.128 +		return;
   1.129 +	}
   1.130  
   1.131 -	c->tw = textwidth(&brush.font, c->name) + labelheight(&brush.font);
   1.132 -	c->tx = c->x + c->w - c->tw + 2;
   1.133 -	c->ty = c->y;
   1.134 -	XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
   1.135 -
   1.136 -	brush.rect.x = brush.rect.y = 0;
   1.137 -	brush.rect.width = c->tw;
   1.138 -	brush.rect.height = c->th;
   1.139 +	brush.x = brush.y = 0;
   1.140 +	brush.w = c->tw;
   1.141 +	brush.h = c->th;
   1.142  
   1.143  	draw(dpy, &brush, True, c->name);
   1.144  	XCopyArea(dpy, brush.drawable, c->title, brush.gc,