remove screen arg from uicb*
[awesome.git] / layouts / tile.c
blob0e1029230ea770b6789b6044c377036ccfe1488e
1 /*
2 * tile.c - tile layout
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <stdio.h>
24 #include "util.h"
25 #include "screen.h"
26 #include "awesome.h"
27 #include "tag.h"
28 #include "layout.h"
29 #include "layouts/tile.h"
31 /* extern */
32 extern Client *sel, *clients;
34 void
35 uicb_setnmaster(Display *disp,
36 DC * drawcontext,
37 awesome_config *awesomeconf,
38 const char * arg)
40 if(!arg || (!IS_ARRANGE(tile) && !IS_ARRANGE(tileleft)))
41 return;
43 if((awesomeconf->nmaster = (int) compute_new_value_from_arg(arg, (double) awesomeconf->nmaster)) < 0)
44 awesomeconf->nmaster = 0;
46 arrange(disp, drawcontext, awesomeconf);
49 void
50 uicb_setncols(Display *disp,
51 DC * drawcontext,
52 awesome_config *awesomeconf,
53 const char * arg)
55 if(!arg || (!IS_ARRANGE(tile) && !IS_ARRANGE(tileleft)))
56 return;
58 if((awesomeconf->ncols = (int) compute_new_value_from_arg(arg, (double) awesomeconf->ncols)) < 1)
59 awesomeconf->ncols = 1;
61 arrange(disp, drawcontext, awesomeconf);
64 void
65 uicb_setmwfact(Display *disp,
66 DC *drawcontext,
67 awesome_config * awesomeconf,
68 const char *arg)
70 if(!IS_ARRANGE(tile) && !IS_ARRANGE(tileleft))
71 return;
73 if((awesomeconf->mwfact = compute_new_value_from_arg(arg, awesomeconf->mwfact)) < 0.1)
74 awesomeconf->mwfact = 0.1;
75 else if(awesomeconf->mwfact > 0.9)
76 awesomeconf->mwfact = 0.9;
78 arrange(disp, drawcontext, awesomeconf);
81 static void
82 _tile(Display *disp, int screen, awesome_config *awesomeconf, const Bool right)
84 /* windows area geometry */
85 int wah = 0, waw = 0, wax = 0, way = 0;
86 /* new coordinates */
87 unsigned int nx, ny, nw, nh;
88 /* master size */
89 unsigned int mw = 0, mh = 0;
90 int n, i, li, last_i = 0, masterwin = 0, otherwin = 0;
91 int screen_numbers = 1, use_screen = -1;
92 int real_ncols = 1, win_by_col = 1, current_col = 0;
93 ScreenInfo *screens_info = NULL;
94 Client *c;
96 screens_info = get_screen_info(disp, screen, awesomeconf->statusbar, &screen_numbers);
98 for(n = 0, c = clients; c; c = c->next)
99 if(IS_TILED(c, screen, awesomeconf->selected_tags, awesomeconf->ntags))
100 n++;
102 for(i = 0, c = clients; c; c = c->next)
104 if(!IS_TILED(c, screen, awesomeconf->selected_tags, awesomeconf->ntags))
105 continue;
107 if(use_screen == -1
108 || (screen_numbers > 1
109 && i
110 && ((i - last_i) >= masterwin + otherwin
111 || n == screen_numbers)))
113 use_screen++;
114 last_i = i;
116 wah = screens_info[use_screen].height;
117 waw = screens_info[use_screen].width;
118 wax = screens_info[use_screen].x_org;
119 way = screens_info[use_screen].y_org;
121 if(n >= awesomeconf->nmaster * screen_numbers)
123 masterwin = awesomeconf->nmaster;
124 otherwin = (n - (awesomeconf->nmaster * screen_numbers)) / screen_numbers;
125 if(use_screen == 0)
126 otherwin += (n - (awesomeconf->nmaster * screen_numbers)) % screen_numbers;
128 else
130 masterwin = n / screen_numbers;
131 /* first screen takes more master */
132 if(use_screen == 0)
133 masterwin += n % screen_numbers;
134 otherwin = 0;
137 if(awesomeconf->nmaster)
139 mh = masterwin ? wah / masterwin : waw;
140 mw = otherwin ? waw * awesomeconf->mwfact : waw;
142 else
143 mh = mw = 0;
145 mw -= 2 * c->border;
146 mh -= 2 * c->border;
148 if(otherwin < awesomeconf->ncols)
149 real_ncols = otherwin;
150 else
151 real_ncols = awesomeconf->ncols;
153 current_col = 0;
156 c->ismax = False;
157 li = last_i ? i - last_i : i;
158 if(li < awesomeconf->nmaster)
159 { /* master */
160 ny = way + li * (mh + 2 * c->border);
161 nx = wax + (right ? 0 : waw - (mw + 2 * c->border));
162 resize(c, nx, ny, mw, mh, awesomeconf->resize_hints);
164 else
165 { /* tile window */
166 win_by_col = otherwin / real_ncols;
168 if((li - awesomeconf->nmaster) && (li - awesomeconf->nmaster) % win_by_col == 0 && current_col < real_ncols - 1)
169 current_col++;
171 if(current_col == real_ncols - 1)
172 win_by_col += otherwin % real_ncols;
174 if(otherwin <= real_ncols)
175 nh = wah - 2 * c->border;
176 else
177 nh = (wah / win_by_col) - 2 * c->border;
179 nw = (waw - (mw + 2 * c->border)) / real_ncols - 2 * c->border;
181 if(li == awesomeconf->nmaster || otherwin <= real_ncols || (li - awesomeconf->nmaster) % win_by_col == 0)
182 ny = way;
183 else
184 ny = way + ((li - awesomeconf->nmaster) % win_by_col) * (nh + 2 * c->border);
186 nx = wax + current_col * nw + (right ? mw + 2 * c->border : 0);
187 resize(c, nx, ny, nw, nh, awesomeconf->resize_hints);
189 i++;
191 XFree(screens_info);
194 void
195 tile(Display *disp, int screen, awesome_config *awesomeconf)
197 _tile(disp, screen, awesomeconf, True);
200 void
201 tileleft(Display *disp, int screen, awesome_config *awesomeconf)
203 _tile(disp, screen, awesomeconf, False);