remove DC from global in draw.c
[awesome.git] / layouts / tile.c
blob956c72e4fade5fb2d70dc5d3a9e20a1639c8c1d0
1 /*
2 * tile.c - tile layout
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
5 * Copyright © 2007 Ross Mohn <rpmohn@waxandwane.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <stdio.h>
25 #include "awesome.h"
26 #include "tag.h"
27 #include "layout.h"
28 #include "layouts/tile.h"
30 /* extern */
31 extern Client *sel, *clients;
32 extern DC dc;
34 /* static */
36 static double mwfact = 0.6;
37 static int nmaster = 2;
39 void
40 uicb_setnmaster(Display *disp,
41 awesome_config *awesomeconf,
42 const char * arg)
44 int delta;
45 int wah = get_windows_area_height(disp, awesomeconf->statusbar);
47 if(!IS_ARRANGE(tile) && !IS_ARRANGE(tileleft) && !IS_ARRANGE(bstack) && !IS_ARRANGE(bstackportrait))
48 return;
49 if(!arg)
50 nmaster = awesomeconf->nmaster;
51 else if(sscanf(arg, "%d", &delta))
53 if((arg[0] == '+' || arg[0] == '-')
54 && !((nmaster + delta) < 1 || wah / (nmaster + delta) <= 2 * awesomeconf->borderpx))
55 nmaster += delta;
56 else if(delta >= 1 && wah / delta <= 2 * awesomeconf->borderpx)
57 nmaster = delta;
58 else
59 return;
61 if(sel)
62 arrange(disp, awesomeconf);
63 else
64 drawstatus(disp, &dc, awesomeconf);
67 void
68 uicb_setmwfact(Display *disp,
69 awesome_config * awesomeconf,
70 const char *arg)
72 double delta;
74 if(!IS_ARRANGE(tile) && !IS_ARRANGE(tileleft) && !IS_ARRANGE(bstack) && !IS_ARRANGE(bstackportrait))
75 return;
77 /* arg handling, manipulate mwfact */
78 if(!arg)
79 mwfact = awesomeconf->mwfact;
80 else if(sscanf(arg, "%lf", &delta))
82 if(arg[0] != '+' && arg[0] != '-')
83 mwfact = delta;
84 else
85 mwfact += delta;
86 if(mwfact < 0.1)
87 mwfact = 0.1;
88 else if(mwfact > 0.9)
89 mwfact = 0.9;
91 arrange(disp, awesomeconf);
94 static void
95 _tile(Display *disp, awesome_config *awesomeconf, const Bool right)
97 int wah = get_windows_area_height(disp, awesomeconf->statusbar);
98 int waw = get_windows_area_width(disp, awesomeconf->statusbar);
99 int wax = get_windows_area_x(awesomeconf->statusbar);
100 int way = get_windows_area_y(awesomeconf->statusbar);
101 unsigned int nx, ny, nw, nh, mw;
102 int n, th, i, mh;
103 Client *c;
105 for(n = 0, c = clients; c; c = c->next)
106 if(IS_TILED(c, awesomeconf->selected_tags, awesomeconf->ntags))
107 n++;
109 /* window geoms */
110 mh = (n <= nmaster) ? wah / (n > 0 ? n : 1) : wah / nmaster;
111 mw = (n <= nmaster) ? waw : mwfact * waw;
112 th = (n > nmaster) ? wah / (n - nmaster) : 0;
113 if(n > nmaster && th < awesomeconf->statusbar.height)
114 th = wah;
116 nx = wax;
117 ny = way;
118 for(i = 0, c = clients; c; c = c->next)
120 if(!IS_TILED(c, awesomeconf->selected_tags, awesomeconf->ntags))
121 continue;
123 c->ismax = False;
124 if(i < nmaster)
125 { /* master */
126 ny = way + i * mh;
127 if(!right && i == 0)
128 nx += (waw - mw);
129 nw = mw - 2 * c->border;
130 nh = mh;
131 if(i + 1 == (n < nmaster ? n : nmaster)) /* remainder */
132 nh = wah - mh * i;
133 nh -= 2 * c->border;
135 else
136 { /* tile window */
137 if(i == nmaster)
139 ny = way;
140 if(right)
141 nx += mw;
142 else
143 nx = 0;
145 nw = waw - mw - 2 * c->border;
146 if(i + 1 == n) /* remainder */
147 nh = (way + wah) - ny - 2 * c->border;
148 else
149 nh = th - 2 * c->border;
151 resize(c, nx, ny, nw, nh, awesomeconf->resize_hints);
152 if(n > nmaster && th != wah)
153 ny += nh + 2 * c->border;
154 i++;
158 void
159 tile(Display *disp, awesome_config *awesomeconf)
161 _tile(disp, awesomeconf, True);
164 void
165 tileleft(Display *disp, awesome_config *awesomeconf)
167 _tile(disp, awesomeconf, False);
171 static void
172 _bstack(Display *disp, awesome_config *awesomeconf, Bool portrait)
174 int i, n, nx, ny, nw, nh, mw, mh, tw, th;
175 int wah = get_windows_area_height(disp, awesomeconf->statusbar);
176 int waw = get_windows_area_width(disp, awesomeconf->statusbar);
177 Client *c;
179 for(n = 0, c = clients; c; c = c->next)
180 if(IS_TILED(c, awesomeconf->selected_tags, awesomeconf->ntags))
181 n++;
183 /* window geoms */
184 mh = (n > nmaster) ? (wah * mwfact) / nmaster : wah / (n > 0 ? n : 1);
185 mw = waw;
186 th = (n > nmaster) ? (wah * (1 - mwfact)) / (portrait ? 1 : n - nmaster) : 0;
187 tw = (n > nmaster) ? waw / (portrait ? n - nmaster : 1) : 0;
189 for(i = 0, c = clients; c; c = c->next)
191 if(!IS_TILED(c, awesomeconf->selected_tags, awesomeconf->ntags))
192 continue;
194 c->ismax = False;
195 nx = get_windows_area_x(awesomeconf->statusbar);
196 ny = get_windows_area_y(awesomeconf->statusbar);
197 if(i < nmaster)
199 ny += i * mh;
200 nw = mw - 2 * c->border;
201 nh = mh - 2 * c->border;
203 else if(portrait)
205 nx += (i - nmaster) * tw;
206 ny += mh * nmaster;
207 nw = tw - 2 * c->border;
208 nh = th - 2 * c->border + 1;
210 else
212 ny += mh * nmaster;
213 nw = tw - 2 * c->border;
214 if(th > 2 * c->border)
216 ny += (i - nmaster) * th;
217 nh = th - 2 * c->border;
218 if (i == n - 1)
219 nh += (n > nmaster) ? wah - mh - th * (n - nmaster) : 0;
221 else
222 nh = wah - 2 * c->border;
224 resize(c, nx, ny, nw, nh, False);
225 i++;
229 void
230 bstack(Display *disp, awesome_config *awesomeconf)
232 _bstack(disp, awesomeconf, False);
235 void
236 bstackportrait(Display *disp, awesome_config *awesomeconf)
238 _bstack(disp, awesomeconf, True);