dwm-meillo

changeset 327:96d09fd98e89

separated several functions into view.c
author Anselm R. Garbe <arg@10kloc.org>
date Tue, 22 Aug 2006 16:50:21 +0200
parents 73efaa15a635
children 083f1f3e1e93
files Makefile client.c dwm.h tag.c view.c
diffstat 5 files changed, 266 insertions(+), 258 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Tue Aug 22 16:42:29 2006 +0200
     1.2 +++ b/Makefile	Tue Aug 22 16:50:21 2006 +0200
     1.3 @@ -3,7 +3,7 @@
     1.4  
     1.5  include config.mk
     1.6  
     1.7 -SRC = client.c draw.c event.c main.c tag.c util.c
     1.8 +SRC = client.c draw.c event.c main.c tag.c util.c view.c
     1.9  OBJ = ${SRC:.c=.o}
    1.10  
    1.11  all: options dwm
     2.1 --- a/client.c	Tue Aug 22 16:42:29 2006 +0200
     2.2 +++ b/client.c	Tue Aug 22 16:50:21 2006 +0200
     2.3 @@ -89,40 +89,6 @@
     2.4  	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
     2.5  }
     2.6  
     2.7 -void
     2.8 -focusnext(Arg *arg)
     2.9 -{
    2.10 -	Client *c;
    2.11 -   
    2.12 -	if(!sel)
    2.13 -		return;
    2.14 -
    2.15 -	if(!(c = getnext(sel->next)))
    2.16 -		c = getnext(clients);
    2.17 -	if(c) {
    2.18 -		focus(c);
    2.19 -		restack();
    2.20 -	}
    2.21 -}
    2.22 -
    2.23 -void
    2.24 -focusprev(Arg *arg)
    2.25 -{
    2.26 -	Client *c;
    2.27 -
    2.28 -	if(!sel)
    2.29 -		return;
    2.30 -
    2.31 -	if(!(c = getprev(sel->prev))) {
    2.32 -		for(c = clients; c && c->next; c = c->next);
    2.33 -		c = getprev(c);
    2.34 -	}
    2.35 -	if(c) {
    2.36 -		focus(c);
    2.37 -		restack();
    2.38 -	}
    2.39 -}
    2.40 -
    2.41  Client *
    2.42  getclient(Window w)
    2.43  {
    2.44 @@ -446,30 +412,3 @@
    2.45  		focus(sel);
    2.46  	arrange(NULL);
    2.47  }
    2.48 -
    2.49 -void
    2.50 -zoom(Arg *arg)
    2.51 -{
    2.52 -	Client *c;
    2.53 -
    2.54 -	if(!sel || (arrange != dotile) || sel->isfloat || sel->ismax)
    2.55 -		return;
    2.56 -
    2.57 -	if(sel == getnext(clients))  {
    2.58 -		if((c = getnext(sel->next)))
    2.59 -			sel = c;
    2.60 -		else
    2.61 -			return;
    2.62 -	}
    2.63 -
    2.64 -	/* pop */
    2.65 -	sel->prev->next = sel->next;
    2.66 -	if(sel->next)
    2.67 -		sel->next->prev = sel->prev;
    2.68 -	sel->prev = NULL;
    2.69 -	clients->prev = sel;
    2.70 -	sel->next = clients;
    2.71 -	clients = sel;
    2.72 -	focus(sel);
    2.73 -	arrange(NULL);
    2.74 -}
     3.1 --- a/dwm.h	Tue Aug 22 16:42:29 2006 +0200
     3.2 +++ b/dwm.h	Tue Aug 22 16:50:21 2006 +0200
     3.3 @@ -84,8 +84,6 @@
     3.4  /* client.c */
     3.5  extern void ban(Client *c);
     3.6  extern void focus(Client *c);
     3.7 -extern void focusnext(Arg *arg);
     3.8 -extern void focusprev(Arg *arg);
     3.9  extern Client *getclient(Window w);
    3.10  extern Client *getctitle(Window w);
    3.11  extern void gravitate(Client *c, Bool invert);
    3.12 @@ -96,7 +94,6 @@
    3.13  extern void settitle(Client *c);
    3.14  extern void togglemax(Arg *arg);
    3.15  extern void unmanage(Client *c);
    3.16 -extern void zoom(Arg *arg);
    3.17  
    3.18  /* draw.c */
    3.19  extern void drawall();
    3.20 @@ -117,22 +114,27 @@
    3.21  extern int xerror(Display *dsply, XErrorEvent *ee);
    3.22  
    3.23  /* tag.c */
    3.24 -extern void dofloat(Arg *arg);
    3.25 -extern void dotile(Arg *arg);
    3.26  extern void initrregs();
    3.27 -extern Bool isvisible(Client *c);
    3.28  extern Client *getnext(Client *c);
    3.29  extern Client *getprev(Client *c);
    3.30 -extern void restack();
    3.31  extern void settags(Client *c);
    3.32  extern void tag(Arg *arg);
    3.33 -extern void togglemode(Arg *arg);
    3.34  extern void toggletag(Arg *arg);
    3.35 -extern void toggleview(Arg *arg);
    3.36 -extern void view(Arg *arg);
    3.37  
    3.38  /* util.c */
    3.39  extern void *emallocz(unsigned int size);
    3.40  extern void eprint(const char *errstr, ...);
    3.41  extern void *erealloc(void *ptr, unsigned int size);
    3.42  extern void spawn(Arg *arg);
    3.43 +
    3.44 +/* view.c */
    3.45 +extern void dofloat(Arg *arg);
    3.46 +extern void dotile(Arg *arg);
    3.47 +extern void focusnext(Arg *arg);
    3.48 +extern void focusprev(Arg *arg);
    3.49 +extern Bool isvisible(Client *c);
    3.50 +extern void restack();
    3.51 +extern void togglemode(Arg *arg);
    3.52 +extern void toggleview(Arg *arg);
    3.53 +extern void view(Arg *arg);
    3.54 +extern void zoom(Arg *arg);
     4.1 --- a/tag.c	Tue Aug 22 16:42:29 2006 +0200
     4.2 +++ b/tag.c	Tue Aug 22 16:50:21 2006 +0200
     4.3 @@ -30,97 +30,8 @@
     4.4  static RReg *rreg = NULL;
     4.5  static unsigned int len = 0;
     4.6  
     4.7 -void (*arrange)(Arg *) = DEFMODE;
     4.8 -
     4.9  /* extern */
    4.10  
    4.11 -void
    4.12 -dofloat(Arg *arg)
    4.13 -{
    4.14 -	Client *c;
    4.15 -
    4.16 -	for(c = clients; c; c = c->next) {
    4.17 -		c->ismax = False;
    4.18 -		if(isvisible(c)) {
    4.19 -			resize(c, True, TopLeft);
    4.20 -		}
    4.21 -		else
    4.22 -			ban(c);
    4.23 -	}
    4.24 -	if(!sel || !isvisible(sel))
    4.25 -		sel = getnext(clients);
    4.26 -	if(sel)
    4.27 -		focus(sel);
    4.28 -	else
    4.29 -		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
    4.30 -	restack();
    4.31 -}
    4.32 -
    4.33 -void
    4.34 -dotile(Arg *arg)
    4.35 -{
    4.36 -	int h, i, n, w;
    4.37 -	Client *c;
    4.38 -
    4.39 -	w = sw - mw;
    4.40 -	for(n = 0, c = clients; c; c = c->next)
    4.41 -		if(isvisible(c) && !c->isfloat)
    4.42 -			n++;
    4.43 -
    4.44 -	if(n > 1)
    4.45 -		h = (sh - bh) / (n - 1);
    4.46 -	else
    4.47 -		h = sh - bh;
    4.48 -
    4.49 -	for(i = 0, c = clients; c; c = c->next) {
    4.50 -		c->ismax = False;
    4.51 -		if(isvisible(c)) {
    4.52 -			if(c->isfloat) {
    4.53 -				resize(c, True, TopLeft);
    4.54 -				continue;
    4.55 -			}
    4.56 -			if(n == 1) {
    4.57 -				c->x = sx;
    4.58 -				c->y = sy + bh;
    4.59 -				c->w = sw - 2;
    4.60 -				c->h = sh - 2 - bh;
    4.61 -			}
    4.62 -			else if(i == 0) {
    4.63 -				c->x = sx;
    4.64 -				c->y = sy + bh;
    4.65 -				c->w = mw - 2;
    4.66 -				c->h = sh - 2 - bh;
    4.67 -			}
    4.68 -			else if(h > bh) {
    4.69 -				c->x = sx + mw;
    4.70 -				c->y = sy + (i - 1) * h + bh;
    4.71 -				c->w = w - 2;
    4.72 -				if(i + 1 == n)
    4.73 -					c->h = sh - c->y - 2;
    4.74 -				else
    4.75 -					c->h = h - 2;
    4.76 -			}
    4.77 -			else { /* fallback if h < bh */
    4.78 -				c->x = sx + mw;
    4.79 -				c->y = sy + bh;
    4.80 -				c->w = w - 2;
    4.81 -				c->h = sh - 2 - bh;
    4.82 -			}
    4.83 -			resize(c, False, TopLeft);
    4.84 -			i++;
    4.85 -		}
    4.86 -		else
    4.87 -			ban(c);
    4.88 -	}
    4.89 -	if(!sel || !isvisible(sel))
    4.90 -		sel = getnext(clients);
    4.91 -	if(sel)
    4.92 -		focus(sel);
    4.93 -	else
    4.94 -		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
    4.95 -	restack();
    4.96 -}
    4.97 -
    4.98  Client *
    4.99  getnext(Client *c)
   4.100  {
   4.101 @@ -164,69 +75,6 @@
   4.102  	}
   4.103  }
   4.104  
   4.105 -Bool
   4.106 -isvisible(Client *c)
   4.107 -{
   4.108 -	unsigned int i;
   4.109 -
   4.110 -	for(i = 0; i < ntags; i++)
   4.111 -		if(c->tags[i] && seltag[i])
   4.112 -			return True;
   4.113 -	return False;
   4.114 -}
   4.115 -
   4.116 -void
   4.117 -restack()
   4.118 -{
   4.119 -	static unsigned int nwins = 0;
   4.120 -	static Window *wins = NULL;
   4.121 -	unsigned int f, fi, m, mi, n;
   4.122 -	Client *c;
   4.123 -	XEvent ev;
   4.124 -
   4.125 -	for(f = 0, m = 0, c = clients; c; c = c->next)
   4.126 -		if(isvisible(c)) {
   4.127 -			if(c->isfloat || arrange == dofloat)
   4.128 -				f++;
   4.129 -			else
   4.130 -				m++;
   4.131 -		}
   4.132 -	if(!(n = 2 * (f + m))) {
   4.133 -		drawstatus();
   4.134 -		return;
   4.135 -	}
   4.136 -	if(nwins < n) {
   4.137 -		nwins = n;
   4.138 -		wins = erealloc(wins, nwins * sizeof(Window));
   4.139 -	}
   4.140 -
   4.141 -	fi = 0;
   4.142 -	mi = 2 * f;
   4.143 -	if(sel->isfloat || arrange == dofloat) {
   4.144 -		wins[fi++] = sel->title;
   4.145 -		wins[fi++] = sel->win;
   4.146 -	}
   4.147 -	else {
   4.148 -		wins[mi++] = sel->title;
   4.149 -		wins[mi++] = sel->win;
   4.150 -	}
   4.151 -	for(c = clients; c; c = c->next)
   4.152 -		if(isvisible(c) && c != sel) {
   4.153 -			if(c->isfloat || arrange == dofloat) {
   4.154 -				wins[fi++] = c->title;
   4.155 -				wins[fi++] = c->win;
   4.156 -			}
   4.157 -			else {
   4.158 -				wins[mi++] = c->title;
   4.159 -				wins[mi++] = c->win;
   4.160 -			}
   4.161 -		}
   4.162 -	XRestackWindows(dpy, wins, n);
   4.163 -	drawall();
   4.164 -	XSync(dpy, False);
   4.165 -	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
   4.166 -}
   4.167 -
   4.168  void
   4.169  settags(Client *c)
   4.170  {
   4.171 @@ -277,16 +125,6 @@
   4.172  }
   4.173  
   4.174  void
   4.175 -togglemode(Arg *arg)
   4.176 -{
   4.177 -	arrange = arrange == dofloat ? dotile : dofloat;
   4.178 -	if(sel)
   4.179 -		arrange(NULL);
   4.180 -	else
   4.181 -		drawstatus();
   4.182 -}
   4.183 -
   4.184 -void
   4.185  toggletag(Arg *arg)
   4.186  {
   4.187  	unsigned int i;
   4.188 @@ -302,27 +140,3 @@
   4.189  	if(!isvisible(sel))
   4.190  		arrange(NULL);
   4.191  }
   4.192 -
   4.193 -
   4.194 -void
   4.195 -toggleview(Arg *arg)
   4.196 -{
   4.197 -	unsigned int i;
   4.198 -
   4.199 -	seltag[arg->i] = !seltag[arg->i];
   4.200 -	for(i = 0; i < ntags && !seltag[i]; i++);
   4.201 -	if(i == ntags)
   4.202 -		seltag[arg->i] = True; /* cannot toggle last view */
   4.203 -	arrange(NULL);
   4.204 -}
   4.205 -
   4.206 -void
   4.207 -view(Arg *arg)
   4.208 -{
   4.209 -	unsigned int i;
   4.210 -
   4.211 -	for(i = 0; i < ntags; i++)
   4.212 -		seltag[i] = False;
   4.213 -	seltag[arg->i] = True;
   4.214 -	arrange(NULL);
   4.215 -}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/view.c	Tue Aug 22 16:50:21 2006 +0200
     5.3 @@ -0,0 +1,253 @@
     5.4 +/*
     5.5 + * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
     5.6 + * See LICENSE file for license details.
     5.7 + */
     5.8 +#include "dwm.h"
     5.9 +
    5.10 +/* extern */
    5.11 +
    5.12 +void (*arrange)(Arg *) = DEFMODE;
    5.13 +
    5.14 +void
    5.15 +dofloat(Arg *arg)
    5.16 +{
    5.17 +	Client *c;
    5.18 +
    5.19 +	for(c = clients; c; c = c->next) {
    5.20 +		c->ismax = False;
    5.21 +		if(isvisible(c)) {
    5.22 +			resize(c, True, TopLeft);
    5.23 +		}
    5.24 +		else
    5.25 +			ban(c);
    5.26 +	}
    5.27 +	if(!sel || !isvisible(sel))
    5.28 +		sel = getnext(clients);
    5.29 +	if(sel)
    5.30 +		focus(sel);
    5.31 +	else
    5.32 +		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
    5.33 +	restack();
    5.34 +}
    5.35 +
    5.36 +void
    5.37 +dotile(Arg *arg)
    5.38 +{
    5.39 +	int h, i, n, w;
    5.40 +	Client *c;
    5.41 +
    5.42 +	w = sw - mw;
    5.43 +	for(n = 0, c = clients; c; c = c->next)
    5.44 +		if(isvisible(c) && !c->isfloat)
    5.45 +			n++;
    5.46 +
    5.47 +	if(n > 1)
    5.48 +		h = (sh - bh) / (n - 1);
    5.49 +	else
    5.50 +		h = sh - bh;
    5.51 +
    5.52 +	for(i = 0, c = clients; c; c = c->next) {
    5.53 +		c->ismax = False;
    5.54 +		if(isvisible(c)) {
    5.55 +			if(c->isfloat) {
    5.56 +				resize(c, True, TopLeft);
    5.57 +				continue;
    5.58 +			}
    5.59 +			if(n == 1) {
    5.60 +				c->x = sx;
    5.61 +				c->y = sy + bh;
    5.62 +				c->w = sw - 2;
    5.63 +				c->h = sh - 2 - bh;
    5.64 +			}
    5.65 +			else if(i == 0) {
    5.66 +				c->x = sx;
    5.67 +				c->y = sy + bh;
    5.68 +				c->w = mw - 2;
    5.69 +				c->h = sh - 2 - bh;
    5.70 +			}
    5.71 +			else if(h > bh) {
    5.72 +				c->x = sx + mw;
    5.73 +				c->y = sy + (i - 1) * h + bh;
    5.74 +				c->w = w - 2;
    5.75 +				if(i + 1 == n)
    5.76 +					c->h = sh - c->y - 2;
    5.77 +				else
    5.78 +					c->h = h - 2;
    5.79 +			}
    5.80 +			else { /* fallback if h < bh */
    5.81 +				c->x = sx + mw;
    5.82 +				c->y = sy + bh;
    5.83 +				c->w = w - 2;
    5.84 +				c->h = sh - 2 - bh;
    5.85 +			}
    5.86 +			resize(c, False, TopLeft);
    5.87 +			i++;
    5.88 +		}
    5.89 +		else
    5.90 +			ban(c);
    5.91 +	}
    5.92 +	if(!sel || !isvisible(sel))
    5.93 +		sel = getnext(clients);
    5.94 +	if(sel)
    5.95 +		focus(sel);
    5.96 +	else
    5.97 +		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
    5.98 +	restack();
    5.99 +}
   5.100 +
   5.101 +void
   5.102 +focusnext(Arg *arg)
   5.103 +{
   5.104 +	Client *c;
   5.105 +   
   5.106 +	if(!sel)
   5.107 +		return;
   5.108 +
   5.109 +	if(!(c = getnext(sel->next)))
   5.110 +		c = getnext(clients);
   5.111 +	if(c) {
   5.112 +		focus(c);
   5.113 +		restack();
   5.114 +	}
   5.115 +}
   5.116 +
   5.117 +void
   5.118 +focusprev(Arg *arg)
   5.119 +{
   5.120 +	Client *c;
   5.121 +
   5.122 +	if(!sel)
   5.123 +		return;
   5.124 +
   5.125 +	if(!(c = getprev(sel->prev))) {
   5.126 +		for(c = clients; c && c->next; c = c->next);
   5.127 +		c = getprev(c);
   5.128 +	}
   5.129 +	if(c) {
   5.130 +		focus(c);
   5.131 +		restack();
   5.132 +	}
   5.133 +}
   5.134 +
   5.135 +Bool
   5.136 +isvisible(Client *c)
   5.137 +{
   5.138 +	unsigned int i;
   5.139 +
   5.140 +	for(i = 0; i < ntags; i++)
   5.141 +		if(c->tags[i] && seltag[i])
   5.142 +			return True;
   5.143 +	return False;
   5.144 +}
   5.145 +
   5.146 +void
   5.147 +restack()
   5.148 +{
   5.149 +	static unsigned int nwins = 0;
   5.150 +	static Window *wins = NULL;
   5.151 +	unsigned int f, fi, m, mi, n;
   5.152 +	Client *c;
   5.153 +	XEvent ev;
   5.154 +
   5.155 +	for(f = 0, m = 0, c = clients; c; c = c->next)
   5.156 +		if(isvisible(c)) {
   5.157 +			if(c->isfloat || arrange == dofloat)
   5.158 +				f++;
   5.159 +			else
   5.160 +				m++;
   5.161 +		}
   5.162 +	if(!(n = 2 * (f + m))) {
   5.163 +		drawstatus();
   5.164 +		return;
   5.165 +	}
   5.166 +	if(nwins < n) {
   5.167 +		nwins = n;
   5.168 +		wins = erealloc(wins, nwins * sizeof(Window));
   5.169 +	}
   5.170 +
   5.171 +	fi = 0;
   5.172 +	mi = 2 * f;
   5.173 +	if(sel->isfloat || arrange == dofloat) {
   5.174 +		wins[fi++] = sel->title;
   5.175 +		wins[fi++] = sel->win;
   5.176 +	}
   5.177 +	else {
   5.178 +		wins[mi++] = sel->title;
   5.179 +		wins[mi++] = sel->win;
   5.180 +	}
   5.181 +	for(c = clients; c; c = c->next)
   5.182 +		if(isvisible(c) && c != sel) {
   5.183 +			if(c->isfloat || arrange == dofloat) {
   5.184 +				wins[fi++] = c->title;
   5.185 +				wins[fi++] = c->win;
   5.186 +			}
   5.187 +			else {
   5.188 +				wins[mi++] = c->title;
   5.189 +				wins[mi++] = c->win;
   5.190 +			}
   5.191 +		}
   5.192 +	XRestackWindows(dpy, wins, n);
   5.193 +	drawall();
   5.194 +	XSync(dpy, False);
   5.195 +	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
   5.196 +}
   5.197 +
   5.198 +void
   5.199 +togglemode(Arg *arg)
   5.200 +{
   5.201 +	arrange = arrange == dofloat ? dotile : dofloat;
   5.202 +	if(sel)
   5.203 +		arrange(NULL);
   5.204 +	else
   5.205 +		drawstatus();
   5.206 +}
   5.207 +
   5.208 +void
   5.209 +toggleview(Arg *arg)
   5.210 +{
   5.211 +	unsigned int i;
   5.212 +
   5.213 +	seltag[arg->i] = !seltag[arg->i];
   5.214 +	for(i = 0; i < ntags && !seltag[i]; i++);
   5.215 +	if(i == ntags)
   5.216 +		seltag[arg->i] = True; /* cannot toggle last view */
   5.217 +	arrange(NULL);
   5.218 +}
   5.219 +
   5.220 +void
   5.221 +view(Arg *arg)
   5.222 +{
   5.223 +	unsigned int i;
   5.224 +
   5.225 +	for(i = 0; i < ntags; i++)
   5.226 +		seltag[i] = False;
   5.227 +	seltag[arg->i] = True;
   5.228 +	arrange(NULL);
   5.229 +}
   5.230 +
   5.231 +void
   5.232 +zoom(Arg *arg)
   5.233 +{
   5.234 +	Client *c;
   5.235 +
   5.236 +	if(!sel || (arrange != dotile) || sel->isfloat || sel->ismax)
   5.237 +		return;
   5.238 +
   5.239 +	if(sel == getnext(clients))  {
   5.240 +		if((c = getnext(sel->next)))
   5.241 +			sel = c;
   5.242 +		else
   5.243 +			return;
   5.244 +	}
   5.245 +
   5.246 +	/* pop */
   5.247 +	sel->prev->next = sel->next;
   5.248 +	if(sel->next)
   5.249 +		sel->next->prev = sel->prev;
   5.250 +	sel->prev = NULL;
   5.251 +	clients->prev = sel;
   5.252 +	sel->next = clients;
   5.253 +	clients = sel;
   5.254 +	focus(sel);
   5.255 +	arrange(NULL);
   5.256 +}