view.c
changeset 660 4c6d27f03773
parent 659 498b86c72a40
child 661 4b8096176bbe
equal deleted inserted replaced
659:498b86c72a40 660:4c6d27f03773
     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 *c1p = c1->prev;
       
    36 	Client *c1n = c1->next;
       
    37 	Client *c1s = c1->snext;
       
    38 	Client *c2p = c2->prev;
       
    39 	Client *c2n = c2->next;
       
    40 	Client *c2s = c2->snext;
       
    41 
       
    42 	*c1 = *c2;
       
    43 	*c2 = tmp;
       
    44 	c1->prev = c1p;
       
    45 	c1->next = c1n;
       
    46 	c1->snext = c1s;
       
    47 	c2->prev = c2p;
       
    48 	c2->next = c2n;
       
    49 	c2->snext = c2s;
       
    50 }
    12 }
    51 
    13 
    52 static void
    14 static void
    53 togglemax(Client *c) {
    15 togglemax(Client *c) {
    54 	XEvent ev;
    16 	XEvent ev;
    68 		c->w = c->rw;
    30 		c->w = c->rw;
    69 		c->h = c->rh;
    31 		c->h = c->rh;
    70 	}
    32 	}
    71 	resize(c, True, TopLeft);
    33 	resize(c, True, TopLeft);
    72 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
    34 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
    73 }
       
    74 
       
    75 static Client *
       
    76 topofstack() {
       
    77 	Client *c;
       
    78 	unsigned int i;
       
    79 
       
    80 	for(c = nexttiled(clients), i = 0; c && i < nmaster; c = nexttiled(c->next), i++);
       
    81 	return (i < nmaster) ? NULL : c;
       
    82 }
    35 }
    83 
    36 
    84 /* extern */
    37 /* extern */
    85 
    38 
    86 void (*arrange)(void) = DEFMODE;
    39 void (*arrange)(void) = DEFMODE;
   306 	}
   259 	}
   307 	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
   260 	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
   308 		n++;
   261 		n++;
   309 
   262 
   310 	c = sel;
   263 	c = sel;
   311 	if(arrange == dofloat)
   264 	if(arrange != dofloat) {
   312 		return;
   265 		detach(c);
   313 	else if(n <= nmaster)
   266 		if(clients)
   314 		pop(c);
   267 			clients->prev = c;
   315 	else if(ismaster(sel)) {
   268 		c->next = clients;
   316 		if(!(c = topofstack()))
   269 		clients = c;
   317 			return;
   270 		focus(c);
   318 		swap(c, sel);
   271 		arrange();
   319 		c = sel;
   272 	}
   320 	}
   273 }
   321 	else
       
   322 		pop(c);
       
   323 
       
   324 	focus(c);
       
   325 	arrange();
       
   326 }