dwm

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

layout_fibonacci.c (3183B)


      1 #if VANITYGAPS_PATCH
      2 void
      3 fibonacci(Monitor *m, int s)
      4 {
      5 	unsigned int i, n;
      6 	int nx, ny, nw, nh;
      7 	int oh, ov, ih, iv;
      8 	int nv, hrest = 0, wrest = 0, r = 1;
      9 	Client *c;
     10 
     11 	getgaps(m, &oh, &ov, &ih, &iv, &n);
     12 	if (n == 0)
     13 		return;
     14 
     15 	nx = m->wx + ov;
     16 	ny = oh;
     17 	nw = m->ww - 2*ov;
     18 	nh = m->wh - 2*oh;
     19 
     20 	for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
     21 		if (r) {
     22 			if ((i % 2 && (nh - ih) / 2 <= (bh + 2*c->bw))
     23 			   || (!(i % 2) && (nw - iv) / 2 <= (bh + 2*c->bw))) {
     24 				r = 0;
     25 			}
     26 			if (r && i < n - 1) {
     27 				if (i % 2) {
     28 					nv = (nh - ih) / 2;
     29 					hrest = nh - 2*nv - ih;
     30 					nh = nv;
     31 				} else {
     32 					nv = (nw - iv) / 2;
     33 					wrest = nw - 2*nv - iv;
     34 					nw = nv;
     35 				}
     36 
     37 				if ((i % 4) == 2 && !s)
     38 					nx += nw + iv;
     39 				else if ((i % 4) == 3 && !s)
     40 					ny += nh + ih;
     41 			}
     42 
     43 			if ((i % 4) == 0) {
     44 				if (s) {
     45 					ny += nh + ih;
     46 					nh += hrest;
     47 				}
     48 				else {
     49 					nh -= hrest;
     50 					ny -= nh + ih;
     51 				}
     52 			}
     53 			else if ((i % 4) == 1) {
     54 				nx += nw + iv;
     55 				nw += wrest;
     56 			}
     57 			else if ((i % 4) == 2) {
     58 				ny += nh + ih;
     59 				nh += hrest;
     60 				if (i < n - 1)
     61 					nw += wrest;
     62 			}
     63 			else if ((i % 4) == 3) {
     64 				if (s) {
     65 					nx += nw + iv;
     66 					nw -= wrest;
     67 				} else {
     68 					nw -= wrest;
     69 					nx -= nw + iv;
     70 					nh += hrest;
     71 				}
     72 			}
     73 			if (i == 0)	{
     74 				if (n != 1) {
     75 					nw = (m->ww - iv - 2*ov) - (m->ww - iv - 2*ov) * (1 - m->mfact);
     76 					wrest = 0;
     77 				}
     78 				ny = m->wy + oh;
     79 			}
     80 			else if (i == 1)
     81 				nw = m->ww - nw - iv - 2*ov;
     82 			i++;
     83 		}
     84 
     85 		resize(c, nx, ny, nw - (2*c->bw), nh - (2*c->bw), False);
     86 	}
     87 }
     88 #else
     89 void
     90 fibonacci(Monitor *m, int s)
     91 {
     92 	unsigned int i, n;
     93 	int nx, ny, nw, nh;
     94 	int nv, hrest = 0, wrest = 0, r = 1;
     95 	Client *c;
     96 
     97 	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
     98 	if (n == 0)
     99 		return;
    100 
    101 	nx = m->wx;
    102 	ny = m->wy;
    103 	nw = m->ww;
    104 	nh = m->wh;
    105 
    106 	for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
    107 		if (r) {
    108 			if ((i % 2 && nh / 2 <= (bh + 2*c->bw))
    109 			   || (!(i % 2) && nw / 2 <= (bh + 2*c->bw))) {
    110 				r = 0;
    111 			}
    112 			if (r && i < n - 1) {
    113 				if (i % 2) {
    114 					nv = nh / 2;
    115 					hrest = nh - 2*nv;
    116 					nh = nv;
    117 				} else {
    118 					nv = nw / 2;
    119 					wrest = nw - 2*nv;
    120 					nw = nv;
    121 				}
    122 
    123 				if ((i % 4) == 2 && !s)
    124 					nx += nw;
    125 				else if ((i % 4) == 3 && !s)
    126 					ny += nh;
    127 			}
    128 
    129 			if ((i % 4) == 0) {
    130 				if (s) {
    131 					ny += nh;
    132 					nh += hrest;
    133 				}
    134 				else {
    135 					nh -= hrest;
    136 					ny -= nh;
    137 				}
    138 			}
    139 			else if ((i % 4) == 1) {
    140 				nx += nw;
    141 				nw += wrest;
    142 			}
    143 			else if ((i % 4) == 2) {
    144 				ny += nh;
    145 				nh += hrest;
    146 				if (i < n - 1)
    147 					nw += wrest;
    148 			}
    149 			else if ((i % 4) == 3) {
    150 				if (s) {
    151 					nx += nw;
    152 					nw -= wrest;
    153 				} else {
    154 					nw -= wrest;
    155 					nx -= nw;
    156 					nh += hrest;
    157 				}
    158 			}
    159 			if (i == 0)	{
    160 				if (n != 1) {
    161 					nw = m->ww - m->ww * (1 - m->mfact);
    162 					wrest = 0;
    163 				}
    164 				ny = m->wy;
    165 			}
    166 			else if (i == 1)
    167 				nw = m->ww - nw;
    168 			i++;
    169 		}
    170 
    171 		resize(c, nx, ny, nw - (2*c->bw), nh - (2*c->bw), False);
    172 	}
    173 }
    174 #endif
    175 
    176 #if FIBONACCI_DWINDLE_LAYOUT
    177 static void
    178 dwindle(Monitor *m)
    179 {
    180 	fibonacci(m, 1);
    181 }
    182 #endif
    183 
    184 #if FIBONACCI_SPIRAL_LAYOUT
    185 static void
    186 spiral(Monitor *m)
    187 {
    188 	fibonacci(m, 0);
    189 }
    190 #endif
    191