dwm-meillo

changeset 270:dacd3f3c5823

implemented restack behavior (floats are on top in tiled mode)
author Anselm R.Garbe <arg@10ksloc.org>
date Mon, 14 Aug 2006 10:18:24 +0200
parents bf6792e3e700
children e9dc5a9f9480
files client.c dwm.1 dwm.h event.c tag.c util.c
diffstat 6 files changed, 81 insertions(+), 34 deletions(-) [+]
line diff
     1.1 --- a/client.c	Mon Aug 14 08:52:15 2006 +0200
     1.2 +++ b/client.c	Mon Aug 14 10:18:24 2006 +0200
     1.3 @@ -59,8 +59,6 @@
     1.4  		drawtitle(old);
     1.5  	drawtitle(c);
     1.6  	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
     1.7 -	XSync(dpy, False);
     1.8 -	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
     1.9  }
    1.10  
    1.11  void
    1.12 @@ -77,8 +75,8 @@
    1.13  	if(!(c = getnext(sel->next)))
    1.14  		c = getnext(clients);
    1.15  	if(c) {
    1.16 -		higher(c);
    1.17  		focus(c);
    1.18 +		restack();
    1.19  	}
    1.20  }
    1.21  
    1.22 @@ -98,8 +96,8 @@
    1.23  		c = getprev(c);
    1.24  	}
    1.25  	if(c) {
    1.26 -		higher(c);
    1.27  		focus(c);
    1.28 +		restack();
    1.29  	}
    1.30  }
    1.31  
    1.32 @@ -181,13 +179,6 @@
    1.33  }
    1.34  
    1.35  void
    1.36 -higher(Client *c)
    1.37 -{
    1.38 -	XRaiseWindow(dpy, c->win);
    1.39 -	XRaiseWindow(dpy, c->title);
    1.40 -}
    1.41 -
    1.42 -void
    1.43  killclient(Arg *arg)
    1.44  {
    1.45  	if(!sel)
    1.46 @@ -271,13 +262,12 @@
    1.47  			|| (c->maxw && c->minw &&
    1.48  				c->maxw == c->minw && c->maxh == c->minh);
    1.49  	settitle(c);
    1.50 -	arrange(NULL);
    1.51  
    1.52 -	/* mapping the window now prevents flicker */
    1.53 -	XMapRaised(dpy, c->win);
    1.54 -	XMapRaised(dpy, c->title);
    1.55 +	XMapWindow(dpy, c->win);
    1.56 +	XMapWindow(dpy, c->title);
    1.57  	if(isvisible(c))
    1.58  		focus(c);
    1.59 +	arrange(NULL);
    1.60  }
    1.61  
    1.62  void
    1.63 @@ -410,7 +400,7 @@
    1.64  		sel->w = sw - 2;
    1.65  		sel->h = sh - 2 - bh;
    1.66  
    1.67 -		higher(sel);
    1.68 +		restack();
    1.69  		resize(sel, arrange == dofloat, TopLeft);
    1.70  
    1.71  		sel->x = ox;
    1.72 @@ -446,9 +436,9 @@
    1.73  	XSync(dpy, False);
    1.74  	XSetErrorHandler(xerror);
    1.75  	XUngrabServer(dpy);
    1.76 -	arrange(NULL);
    1.77  	if(sel)
    1.78  		focus(sel);
    1.79 +	arrange(NULL);
    1.80  }
    1.81  
    1.82  void
    1.83 @@ -474,6 +464,6 @@
    1.84  	clients->prev = sel;
    1.85  	sel->next = clients;
    1.86  	clients = sel;
    1.87 +	focus(sel);
    1.88  	arrange(NULL);
    1.89 -	focus(sel);
    1.90  }
     2.1 --- a/dwm.1	Mon Aug 14 08:52:15 2006 +0200
     2.2 +++ b/dwm.1	Mon Aug 14 10:18:24 2006 +0200
     2.3 @@ -36,11 +36,11 @@
     2.4  .B Standard input
     2.5  is read and displayed in the status text area.
     2.6  .TP
     2.7 -.B Button[1,3]
     2.8 +.B Button[1,2]
     2.9  click on a tag label focuses that
    2.10  .B tag.
    2.11  .TP
    2.12 -.B Button2
    2.13 +.B Button3
    2.14  click on a tag label toggles that
    2.15  .B tag.
    2.16  .SS Keyboard commands
     3.1 --- a/dwm.h	Mon Aug 14 08:52:15 2006 +0200
     3.2 +++ b/dwm.h	Mon Aug 14 10:18:24 2006 +0200
     3.3 @@ -89,7 +89,6 @@
     3.4  extern Client *getclient(Window w);
     3.5  extern Client *getctitle(Window w);
     3.6  extern void gravitate(Client *c, Bool invert);
     3.7 -extern void higher(Client *c);
     3.8  extern void killclient(Arg *arg);
     3.9  extern void manage(Window w, XWindowAttributes *wa);
    3.10  extern void resize(Client *c, Bool sizehints, Corner sticky);
    3.11 @@ -125,6 +124,7 @@
    3.12  extern Client *getnext(Client *c);
    3.13  extern Client *getprev(Client *c);
    3.14  extern void replacetag(Arg *arg);
    3.15 +extern void restack();
    3.16  extern void settags(Client *c);
    3.17  extern void togglemode(Arg *arg);
    3.18  extern void view(Arg *arg);
    3.19 @@ -133,4 +133,5 @@
    3.20  /* util.c */
    3.21  extern void *emallocz(unsigned int size);
    3.22  extern void eprint(const char *errstr, ...);
    3.23 +extern void *erealloc(void *ptr, unsigned int size);
    3.24  extern void spawn(Arg *arg);
     4.1 --- a/event.c	Mon Aug 14 08:52:15 2006 +0200
     4.2 +++ b/event.c	Mon Aug 14 10:18:24 2006 +0200
     4.3 @@ -118,21 +118,24 @@
     4.4  		}
     4.5  	}
     4.6  	else if((c = getclient(ev->window))) {
     4.7 -		higher(c);
     4.8  		focus(c);
     4.9  		switch(ev->button) {
    4.10  		default:
    4.11  			break;
    4.12  		case Button1:
    4.13 -			if(!c->ismax && (arrange == dofloat || c->isfloat))
    4.14 +			if(!c->ismax && (arrange == dofloat || c->isfloat)) {
    4.15 +				restack(c);
    4.16  				movemouse(c);
    4.17 +			}
    4.18  			break;
    4.19  		case Button2:
    4.20  			zoom(NULL);
    4.21  			break;
    4.22  		case Button3:
    4.23 -			if(!c->ismax && (arrange == dofloat || c->isfloat))
    4.24 +			if(!c->ismax && (arrange == dofloat || c->isfloat)) {
    4.25 +				restack(c);
    4.26  				resizemouse(c);
    4.27 +			}
    4.28  			break;
    4.29  		}
    4.30  	}
     5.1 --- a/tag.c	Mon Aug 14 08:52:15 2006 +0200
     5.2 +++ b/tag.c	Mon Aug 14 10:18:24 2006 +0200
     5.3 @@ -58,18 +58,17 @@
     5.4  			ban(c);
     5.5  	}
     5.6  	if((sel = getnext(clients))) {
     5.7 -		higher(sel);
     5.8  		focus(sel);
     5.9 +		restack();
    5.10  	}
    5.11  	else
    5.12  		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
    5.13 -	drawall();
    5.14  }
    5.15  
    5.16  void
    5.17  dotile(Arg *arg)
    5.18  {
    5.19 -	int n, i, w, h;
    5.20 +	int h, i, n, w;
    5.21  	Client *c;
    5.22  
    5.23  	w = sw - mw;
    5.24 @@ -86,7 +85,6 @@
    5.25  		c->ismax = False;
    5.26  		if(isvisible(c)) {
    5.27  			if(c->isfloat) {
    5.28 -				higher(c);
    5.29  				resize(c, True, TopLeft);
    5.30  				continue;
    5.31  			}
    5.32 @@ -123,13 +121,11 @@
    5.33  		else
    5.34  			ban(c);
    5.35  	}
    5.36 -	if((sel = getnext(clients))) {
    5.37 -		higher(sel);
    5.38 +	if((sel = getnext(clients)))
    5.39  		focus(sel);
    5.40 -	}
    5.41  	else
    5.42  		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
    5.43 -	drawall();
    5.44 +	restack();
    5.45  }
    5.46  
    5.47  Client *
    5.48 @@ -200,6 +196,56 @@
    5.49  }
    5.50  
    5.51  void
    5.52 +restack()
    5.53 +{
    5.54 +	static unsigned int nwins = 0;
    5.55 +	static Window *wins = NULL;
    5.56 +	unsigned int f, fi, m, mi, n;
    5.57 +	Client *c;
    5.58 +	XEvent ev;
    5.59 +
    5.60 +	for(f = 0, m = 0, c = clients; c; c = c->next)
    5.61 +		if(isvisible(c)) {
    5.62 +			if(c->isfloat || arrange == dofloat)
    5.63 +				f++;
    5.64 +			else
    5.65 +				m++;
    5.66 +		}
    5.67 +
    5.68 +	n = 2 * (f + m);
    5.69 +	if(nwins < n) {
    5.70 +		nwins = n;
    5.71 +		wins = erealloc(wins, nwins * sizeof(Window));
    5.72 +	}
    5.73 +
    5.74 +	fi = 0;
    5.75 +	mi = 2 * f;
    5.76 +	if(sel->isfloat || arrange == dofloat) {
    5.77 +		wins[fi++] = sel->title;
    5.78 +		wins[fi++] = sel->win;
    5.79 +	}
    5.80 +	else {
    5.81 +		wins[mi++] = sel->title;
    5.82 +		wins[mi++] = sel->win;
    5.83 +	}
    5.84 +	for(c = clients; c; c = c->next)
    5.85 +		if(isvisible(c) && c != sel) {
    5.86 +			if(c->isfloat || arrange == dofloat) {
    5.87 +				wins[fi++] = c->title;
    5.88 +				wins[fi++] = c->win;
    5.89 +			}
    5.90 +			else {
    5.91 +				wins[mi++] = c->title;
    5.92 +				wins[mi++] = c->win;
    5.93 +			}
    5.94 +		}
    5.95 +	XRestackWindows(dpy, wins, n);
    5.96 +	drawall();
    5.97 +	XSync(dpy, False);
    5.98 +	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
    5.99 +}
   5.100 +
   5.101 +void
   5.102  settags(Client *c)
   5.103  {
   5.104  	char classinst[256];
   5.105 @@ -248,7 +294,6 @@
   5.106  		seltag[i] = False;
   5.107  	seltag[arg->i] = True;
   5.108  	arrange(NULL);
   5.109 -	drawall();
   5.110  }
   5.111  
   5.112  void
   5.113 @@ -261,5 +306,4 @@
   5.114  	if(i == ntags)
   5.115  		seltag[arg->i] = True; /* cannot toggle last view */
   5.116  	arrange(NULL);
   5.117 -	drawall();
   5.118  }
     6.1 --- a/util.c	Mon Aug 14 08:52:15 2006 +0200
     6.2 +++ b/util.c	Mon Aug 14 10:18:24 2006 +0200
     6.3 @@ -40,6 +40,15 @@
     6.4  	exit(EXIT_FAILURE);
     6.5  }
     6.6  
     6.7 +void *
     6.8 +erealloc(void *ptr, unsigned int size)
     6.9 +{
    6.10 +	void *res = realloc(ptr, size);
    6.11 +	if(!res)
    6.12 +		bad_malloc(size);
    6.13 +	return res;
    6.14 +}
    6.15 +
    6.16  void
    6.17  spawn(Arg *arg)
    6.18  {