layout.c
changeset 933 f7619f63380a
parent 932 df47d77ec9a6
child 934 1e8e98b7544d
equal deleted inserted replaced
932:df47d77ec9a6 933:f7619f63380a
     6 unsigned int blw = 0;
     6 unsigned int blw = 0;
     7 Layout *lt = NULL;
     7 Layout *lt = NULL;
     8 
     8 
     9 /* static */
     9 /* static */
    10 
    10 
    11 static double ratio = RATIO;
    11 static double hratio = HRATIO;
       
    12 static double vratio = VRATIO;
    12 static unsigned int nlayouts = 0;
    13 static unsigned int nlayouts = 0;
    13 static unsigned int nmaster = NMASTER;
    14 static unsigned int nmaster = NMASTER;
       
    15 
       
    16 static void
       
    17 incratio(const char *arg, double *ratio, double def) {
       
    18 	double delta;
       
    19 
       
    20 	if(lt->arrange != tile)
       
    21 		return;
       
    22 	if(!arg)
       
    23 		*ratio = def;
       
    24 	else {
       
    25 		if(1 == sscanf(arg, "%lf", &delta)) {
       
    26 			if(delta + (*ratio) < .1 || delta + (*ratio) > 1.9)
       
    27 				return;
       
    28 			*ratio += delta;
       
    29 		}
       
    30 	}
       
    31 	lt->arrange();
       
    32 }
    14 
    33 
    15 static double /* simple pow() */
    34 static double /* simple pow() */
    16 spow(double x, double y)
    35 spow(double x, double y)
    17 {
    36 {
    18 	if(y == 0)
    37 	if(y == 0)
    29 	Client *c;
    48 	Client *c;
    30 
    49 
    31 	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
    50 	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
    32 		n++;
    51 		n++;
    33 
    52 
    34 	mw = (n <= nmaster) ? waw :  waw / (1 + ratio);
    53 	mw = (n <= nmaster) ? waw :  waw / (1 + hratio);
    35 	tw = waw - mw;
    54 	tw = waw - mw;
    36 
    55 
    37 	if(n > 0) {
    56 	if(n > 0) {
    38 		if(n < nmaster) {
    57 		if(n < nmaster) {
    39 			for(i = 0; i < n; i++)
    58 			for(i = 0; i < n; i++)
    40 				sum += spow(ratio, i);
    59 				sum += spow(vratio, i);
    41 			mscale = wah / sum;
    60 			mscale = wah / sum;
    42 		}
    61 		}
    43 		else {
    62 		else {
    44 			for(i = 0; i < nmaster; i++)
    63 			for(i = 0; i < nmaster; i++)
    45 				sum += spow(ratio, i);
    64 				sum += spow(vratio, i);
    46 			mscale = wah / sum;
    65 			mscale = wah / sum;
    47 			for(sum = 0, i = 0; i < (n - nmaster); i++)
    66 			for(sum = 0, i = 0; i < (n - nmaster); i++)
    48 				sum += spow(ratio, i);
    67 				sum += spow(vratio, i);
    49 			tscale = wah / sum;
    68 			tscale = wah / sum;
    50 		}
    69 		}
    51 	}
    70 	}
    52 	nx = wax;
    71 	nx = wax;
    53 	ny = way;
    72 	ny = way;
    60 			if(i < nmaster) { /* master window */
    79 			if(i < nmaster) { /* master window */
    61 				nw = mw - 2 * c->border;
    80 				nw = mw - 2 * c->border;
    62 				if(i + 1 == n || i + 1 == nmaster)
    81 				if(i + 1 == n || i + 1 == nmaster)
    63 					nh = (way + wah) - ny - (2 * c->border);
    82 					nh = (way + wah) - ny - (2 * c->border);
    64 				else
    83 				else
    65 					nh = (mscale * spow(ratio, i)) - (2 * c->border);
    84 					nh = (mscale * spow(vratio, i)) - (2 * c->border);
    66 			}
    85 			}
    67 			else { /* tile window */
    86 			else { /* tile window */
    68 				if(i == nmaster) {
    87 				if(i == nmaster) {
    69 					ny = way;
    88 					ny = way;
    70 					nx = wax + mw;
    89 					nx = wax + mw;
    71 				}
    90 				}
    72 				nw = tw - 2 * c->border;
    91 				nw = tw - 2 * c->border;
    73 				if(i + 1 == n)
    92 				if(i + 1 == n)
    74 					nh = (way + wah) - ny - (2 * c->border);
    93 					nh = (way + wah) - ny - (2 * c->border);
    75 				else
    94 				else
    76 					nh = (tscale * spow(ratio, i - nmaster)) - (2 * c->border);
    95 					nh = (tscale * spow(vratio, i - nmaster)) - (2 * c->border);
    77 			}
    96 			}
    78 			if(nh < bh) {
    97 			if(nh < bh) {
    79 				nh = bh;
    98 				nh = bh;
    80 				ny = way + wah - nh;
    99 				ny = way + wah - nh;
    81 			}
   100 			}
   131 		restack();
   150 		restack();
   132 	}
   151 	}
   133 }
   152 }
   134 
   153 
   135 void
   154 void
   136 incratio(const char *arg) {
   155 inchratio(const char *arg) {
   137 	double delta;
   156 	incratio(arg, &hratio, HRATIO);
   138 
   157 }
   139 	if(lt->arrange != tile)
   158 
   140 		return;
   159 void
   141 	if(!arg)
   160 incvratio(const char *arg) {
   142 		ratio = RATIO;
   161 	incratio(arg, &vratio, VRATIO);
   143 	else {
       
   144 		if(1 == sscanf(arg, "%lf", &delta)) {
       
   145 			if(delta + ratio < .1 || delta + ratio > 1.9)
       
   146 				return;
       
   147 			ratio += delta;
       
   148 		}
       
   149 	}
       
   150 	lt->arrange();
       
   151 }
   162 }
   152 
   163 
   153 void
   164 void
   154 incnmaster(const char *arg) {
   165 incnmaster(const char *arg) {
   155 	int i;
   166 	int i;