arrange() does not need Display as arg
[awesome.git] / layouts / tile.c
blob10fbb6772fe23b51701fbf4ac7b227374efba709
1 /*
2 * tile.c - tile layout
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
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 void
32 uicb_setnmaster(awesome_config *awesomeconf,
33 const char * arg)
35 if(!arg || (!IS_ARRANGE(0, layout_tile) && !IS_ARRANGE(0, layout_tileleft)))
36 return;
39 if((awesomeconf->nmaster = (int) compute_new_value_from_arg(arg, (double) awesomeconf->nmaster)) < 0)
40 awesomeconf->nmaster = 0;
42 arrange(awesomeconf);
45 void
46 uicb_setncol(awesome_config *awesomeconf,
47 const char * arg)
49 if(!arg || (!IS_ARRANGE(0, layout_tile) && !IS_ARRANGE(0, layout_tileleft)))
50 return;
52 if((awesomeconf->ncol = (int) compute_new_value_from_arg(arg, (double) awesomeconf->ncol)) < 1)
53 awesomeconf->ncol = 1;
55 arrange(awesomeconf);
58 void
59 uicb_setmwfact(awesome_config * awesomeconf,
60 const char *arg)
62 char *newarg;
64 if((!IS_ARRANGE(0, layout_tile) && !IS_ARRANGE(0, layout_tileleft)) || !arg)
65 return;
67 newarg = a_strdup(arg);
68 if(IS_ARRANGE(0, layout_tileleft))
70 if(newarg[0] == '+')
71 newarg[0] = '-';
72 else if(arg[0] == '-')
73 newarg[0] = '+';
76 if((awesomeconf->mwfact = compute_new_value_from_arg(newarg, awesomeconf->mwfact)) < 0.1)
77 awesomeconf->mwfact = 0.1;
78 else if(awesomeconf->mwfact > 0.9)
79 awesomeconf->mwfact = 0.9;
81 arrange(awesomeconf);
82 p_delete(&newarg);
85 static void
86 _tile(awesome_config *awesomeconf, const Bool right)
88 /* windows area geometry */
89 int wah = 0, waw = 0, wax = 0, way = 0;
90 /* new coordinates */
91 unsigned int nx, ny, nw, nh;
92 /* master size */
93 unsigned int mw = 0, mh = 0;
94 int n, i, masterwin = 0, otherwin = 0;
95 int real_ncol = 1, win_by_col = 1, current_col = 0;
96 ScreenInfo *screens_info = NULL;
97 Client *c;
99 screens_info = get_screen_info(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar);
101 for(n = 0, c = *awesomeconf->clients; c; c = c->next)
102 if(IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
103 n++;
105 wah = screens_info[awesomeconf->screen].height;
106 waw = screens_info[awesomeconf->screen].width;
107 wax = screens_info[awesomeconf->screen].x_org;
108 way = screens_info[awesomeconf->screen].y_org;
110 masterwin = MIN(n, awesomeconf->nmaster);
112 otherwin = n - masterwin;
114 if(otherwin < 0)
115 otherwin = 0;
117 if(awesomeconf->nmaster)
119 mh = masterwin ? wah / masterwin : waw;
120 mw = otherwin ? waw * awesomeconf->mwfact : waw;
122 else
123 mh = mw = 0;
125 real_ncol = MIN(otherwin, awesomeconf->ncol);
127 for(i = 0, c = *awesomeconf->clients; c; c = c->next)
129 if(!IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
130 continue;
132 c->ismax = False;
133 if(i < awesomeconf->nmaster)
134 { /* master */
135 ny = way + i * mh;
136 nx = wax + (right ? 0 : waw - mw);
137 resize(c, nx, ny, mw - 2 * c->border, mh - 2 * c->border, awesomeconf, awesomeconf->resize_hints);
139 else
140 { /* tile window */
141 if(real_ncol)
142 win_by_col = otherwin / real_ncol;
144 if((i - awesomeconf->nmaster) && (i - awesomeconf->nmaster) % win_by_col == 0 && current_col < real_ncol - 1)
145 current_col++;
147 if(current_col == real_ncol - 1)
148 win_by_col += otherwin % real_ncol;
150 if(otherwin <= real_ncol)
151 nh = wah - 2 * c->border;
152 else
153 nh = (wah / win_by_col) - 2 * c->border;
155 nw = (waw - mw) / real_ncol - 2 * c->border;
157 if(i == awesomeconf->nmaster || otherwin <= real_ncol || (i - awesomeconf->nmaster) % win_by_col == 0)
158 ny = way;
159 else
160 ny = way + ((i - awesomeconf->nmaster) % win_by_col) * (nh + 2 * c->border);
162 nx = wax + current_col * (nw + 2 * c->border) + (right ? mw : 0);
163 resize(c, nx, ny, nw, nh, awesomeconf, awesomeconf->resize_hints);
165 i++;
167 XFree(screens_info);
170 void
171 layout_tile(awesome_config *awesomeconf)
173 _tile(awesomeconf, True);
176 void
177 layout_tileleft(awesome_config *awesomeconf)
179 _tile(awesomeconf, False);
181 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99