dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

inplacerotate.c (1599B)


      1 void
      2 insertclient(Client *item, Client *insertItem, int after)
      3 {
      4 	Client *c;
      5 	if (item == NULL || insertItem == NULL || item == insertItem)
      6 		return;
      7 	detach(insertItem);
      8 	if (!after && selmon->clients == item) {
      9 		attach(insertItem);
     10 		return;
     11 	}
     12 	if (after) {
     13 		c = item;
     14 	} else {
     15 		for (c = selmon->clients; c; c = c->next) {
     16 			if (c->next == item)
     17 				break;
     18 		}
     19 	}
     20 	insertItem->next = c->next;
     21 	c->next = insertItem;
     22 }
     23 
     24 void
     25 inplacerotate(const Arg *arg)
     26 {
     27 	if (!selmon->sel || (selmon->sel->isfloating && !arg->f))
     28 		return;
     29 
     30 	unsigned int selidx = 0, i = 0;
     31 	Client *c = NULL, *stail = NULL, *mhead = NULL, *mtail = NULL, *shead = NULL;
     32 
     33 	// Determine positionings for insertclient
     34 	for (c = selmon->clients; c; c = c->next) {
     35 		if (ISVISIBLE(c) && !(c->isfloating)) {
     36 			if (selmon->sel == c)
     37 				selidx = i;
     38 			if (i == selmon->nmaster - 1)
     39 				mtail = c;
     40 			if (i == selmon->nmaster)
     41 				shead = c;
     42 			if (mhead == NULL)
     43 				mhead = c;
     44 			stail = c;
     45 			i++;
     46 		}
     47 	}
     48 
     49 	switch(arg->i) {
     50 	case 1:
     51 		if (selidx >= selmon->nmaster)
     52 			insertclient(shead, stail, 0);
     53 		else
     54 			insertclient(mhead, mtail, 0);
     55 		break;
     56 	case -1:
     57 		if (selidx >= selmon->nmaster)
     58 			insertclient(stail, shead, 1);
     59 		else
     60 			insertclient(mtail, mhead, 1);
     61 		break;
     62 	case 2:
     63 		insertclient(selmon->clients, stail, 0);
     64 		break;
     65 	case -2:
     66 		insertclient(stail, selmon->clients, 1);
     67 		break;
     68 	}
     69 
     70 	// Restore focus position
     71 	i = 0;
     72 	for (c = selmon->clients; c; c = c->next) {
     73 		if (!ISVISIBLE(c) || (c->isfloating))
     74 			continue;
     75 		if (i == selidx) {
     76 			focus(c);
     77 			break;
     78 		}
     79 		i++;
     80 	}
     81 	arrange(selmon);
     82 	focus(c);
     83 }
     84