view.c
changeset 651 b9f4efd21473
parent 650 f3b8c71a69d4
child 654 04734db9a219
equal deleted inserted replaced
650:f3b8c71a69d4 651:b9f4efd21473
     7 
     7 
     8 static Client *
     8 static Client *
     9 nexttiled(Client *c) {
     9 nexttiled(Client *c) {
    10 	for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
    10 	for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
    11 	return c;
    11 	return c;
       
    12 }
       
    13 
       
    14 static Bool
       
    15 ismaster(Client *c) {
       
    16 	Client *cl;
       
    17 	unsigned int i;
       
    18 
       
    19 	for(cl = nexttiled(clients), i = 0; cl && cl != c; cl = nexttiled(cl->next), i++);
       
    20 	return i < nmaster;
       
    21 }
       
    22 
       
    23 static void
       
    24 pop(Client *c) {
       
    25 	detach(c);
       
    26 	if(clients)
       
    27 		clients->prev = c;
       
    28 	c->next = clients;
       
    29 	clients = c;
       
    30 }
       
    31 
       
    32 static void
       
    33 swap(Client *c1, Client *c2) {
       
    34 	Client tmp = *c1;
       
    35 	Client *cp = c1->prev;
       
    36 	Client *cn = c1->next;
       
    37 
       
    38 	*c1 = *c2;
       
    39 	c1->prev = cp;
       
    40 	c1->next = cn;
       
    41 	cp = c2->prev;
       
    42 	cn = c2->next;
       
    43 	*c2 = tmp;
       
    44 	c2->prev = cp;
       
    45 	c2->next = cn;
    12 }
    46 }
    13 
    47 
    14 static void
    48 static void
    15 togglemax(Client *c) {
    49 togglemax(Client *c) {
    16 	XEvent ev;
    50 	XEvent ev;
    30 		c->w = c->rw;
    64 		c->w = c->rw;
    31 		c->h = c->rh;
    65 		c->h = c->rh;
    32 	}
    66 	}
    33 	resize(c, True, TopLeft);
    67 	resize(c, True, TopLeft);
    34 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
    68 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
       
    69 }
       
    70 
       
    71 static Client *
       
    72 topofstack() {
       
    73 	Client *c;
       
    74 	unsigned int i;
       
    75 
       
    76 	for(c = nexttiled(clients), i = 0; c && i < nmaster; c = nexttiled(c->next), i++);
       
    77 	return (i < nmaster) ? NULL : c;
    35 }
    78 }
    36 
    79 
    37 /* extern */
    80 /* extern */
    38 
    81 
    39 void (*arrange)(void) = DEFMODE;
    82 void (*arrange)(void) = DEFMODE;
   246 	arrange();
   289 	arrange();
   247 }
   290 }
   248 
   291 
   249 void
   292 void
   250 zoom(Arg *arg) {
   293 zoom(Arg *arg) {
   251 	unsigned int i, n;
   294 	unsigned int n;
   252 	Client *c;
   295 	Client *c;
   253 
   296 
   254 	if(!sel)
   297 	if(!sel)
   255 		return;
   298 		return;
   256 	if(sel->isfloat || (arrange == dofloat)) {
   299 	if(sel->isfloat || (arrange == dofloat)) {
   260 	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
   303 	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
   261 		n++;
   304 		n++;
   262 	if(n <= nmaster || (arrange == dofloat))
   305 	if(n <= nmaster || (arrange == dofloat))
   263 		return;
   306 		return;
   264 
   307 
   265 	for(c = nexttiled(clients), i = 0; c && (c != sel) && i < nmaster; c = nexttiled(c->next))
   308 	if(ismaster((c = sel))) {
   266 		i++;
   309 		if(!(c = topofstack()))
   267 	if(c == sel && i < nmaster)
   310 			return;
   268 		for(; c && i < nmaster; c = nexttiled(c->next))
   311 		swap(c, sel);
   269 			i++;
   312 		c = sel;
   270 	if(!c)
   313 	}
   271 		return;
   314 	else
   272 
   315 		pop(c);
   273 	detach(c);
   316 
   274 	if(clients)
       
   275 		clients->prev = c;
       
   276 	c->next = clients;
       
   277 	clients = c;
       
   278 	focus(c);
   317 	focus(c);
   279 	arrange();
   318 	arrange();
   280 }
   319 }