awesome/layouts/tile.c

200 lines
5.4 KiB
C
Raw Normal View History

/*
2007-09-12 14:29:51 +02:00
* tile.c - tile layout
*
2008-01-02 16:59:43 +01:00
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
2007-09-12 14:29:51 +02:00
*/
2007-09-05 20:15:00 +02:00
#include <stdio.h>
#include "util.h"
#include "screen.h"
#include "awesome.h"
#include "tag.h"
#include "layout.h"
2008-01-01 17:25:48 +01:00
#include "client.h"
#include "layouts/tile.h"
2007-09-05 20:15:00 +02:00
extern AwesomeConf globalconf;
2007-09-05 20:15:00 +02:00
void
uicb_tag_setnmaster(int screen, char * arg)
2007-09-05 20:15:00 +02:00
{
2007-12-27 11:50:09 +01:00
Tag **curtags = get_current_tags(screen);
Layout *curlay = curtags[0]->layout;
if(!arg || (curlay->arrange != layout_tile && curlay->arrange != layout_tileleft))
return;
2007-12-27 11:50:09 +01:00
if((curtags[0]->nmaster = (int) compute_new_value_from_arg(arg, (double) curtags[0]->nmaster)) < 0)
curtags[0]->nmaster = 0;
p_delete(&curtags);
arrange(screen);
2007-09-05 20:15:00 +02:00
}
void
uicb_tag_setncol(int screen, char * arg)
{
2007-12-27 11:50:09 +01:00
Tag **curtags = get_current_tags(screen);
Layout *curlay = curtags[0]->layout;
if(!arg || (curlay->arrange != layout_tile && curlay->arrange != layout_tileleft))
return;
2007-12-27 11:50:09 +01:00
if((curtags[0]->ncol = (int) compute_new_value_from_arg(arg, (double) curtags[0]->ncol)) < 1)
curtags[0]->ncol = 1;
p_delete(&curtags);
arrange(screen);
}
2007-09-05 20:15:00 +02:00
void
uicb_tag_setmwfact(int screen, char *arg)
2007-09-05 20:15:00 +02:00
{
char *newarg;
2007-12-27 11:50:09 +01:00
Tag **curtags = get_current_tags(screen);
Layout *curlay = curtags[0]->layout;
if(!arg || (curlay->arrange != layout_tile && curlay->arrange != layout_tileleft))
2007-09-05 20:15:00 +02:00
return;
newarg = a_strdup(arg);
if(curlay->arrange == layout_tileleft)
{
if(newarg[0] == '+')
newarg[0] = '-';
else if(arg[0] == '-')
newarg[0] = '+';
}
2007-12-27 11:50:09 +01:00
if((curtags[0]->mwfact = compute_new_value_from_arg(newarg, curtags[0]->mwfact)) < 0.1)
curtags[0]->mwfact = 0.1;
else if(curtags[0]->mwfact > 0.9)
curtags[0]->mwfact = 0.9;
2007-09-15 14:20:01 +02:00
p_delete(&newarg);
2007-12-27 11:50:09 +01:00
p_delete(&curtags);
arrange(screen);
2007-09-05 20:15:00 +02:00
}
static void
_tile(int screen, const Bool right)
2007-09-05 20:15:00 +02:00
{
2007-09-13 23:20:05 +02:00
/* windows area geometry */
int wah = 0, waw = 0, wax = 0, way = 0;
/* new coordinates */
/* master size */
unsigned int mw = 0, mh = 0;
2007-09-27 22:29:36 +02:00
int n, i, masterwin = 0, otherwin = 0;
int real_ncol = 1, win_by_col = 1, current_col = 0;
2008-01-05 20:18:30 +01:00
Area area, geometry;
2007-09-05 20:15:00 +02:00
Client *c;
2007-12-27 11:50:09 +01:00
Tag **curtags = get_current_tags(screen);
2007-09-05 20:15:00 +02:00
area = get_screen_area(screen,
globalconf.screens[screen].statusbar,
&globalconf.screens[screen].padding);
for(n = 0, c = globalconf.clients; c; c = c->next)
if(IS_TILED(c, screen))
n++;
2007-09-05 20:15:00 +02:00
wah = area.height;
waw = area.width;
wax = area.x;
way = area.y;
2007-09-13 23:20:05 +02:00
2007-12-27 11:50:09 +01:00
masterwin = MIN(n, curtags[0]->nmaster);
2007-09-27 22:29:36 +02:00
otherwin = n - masterwin;
2007-09-27 22:29:36 +02:00
if(otherwin < 0)
otherwin = 0;
2007-09-15 02:52:41 +02:00
2007-12-27 11:50:09 +01:00
if(curtags[0]->nmaster)
2007-09-27 22:29:36 +02:00
{
mh = masterwin ? wah / masterwin : waw;
2007-12-27 11:50:09 +01:00
mw = otherwin ? waw * curtags[0]->mwfact : waw;
2007-09-27 22:29:36 +02:00
}
else
mh = mw = 0;
2007-09-15 14:37:26 +02:00
2007-12-27 11:50:09 +01:00
real_ncol = curtags[0]->ncol > 0 ? MIN(otherwin, curtags[0]->ncol) : MIN(otherwin, 1);
for(i = 0, c = globalconf.clients; c; c = c->next)
2007-09-27 22:29:36 +02:00
{
if(!IS_TILED(c, screen))
2007-09-27 22:29:36 +02:00
continue;
2007-09-13 23:20:05 +02:00
2007-09-05 20:15:00 +02:00
c->ismax = False;
2007-12-27 11:50:09 +01:00
if(i < curtags[0]->nmaster)
{
2008-01-05 20:18:30 +01:00
geometry.y = way + i * mh;
geometry.x = wax + (right ? 0 : waw - mw);
geometry.width = mw - 2 * c->border;
geometry.height = mh - 2 * c->border;
client_resize(c, geometry, globalconf.screens[screen].resize_hints);
2007-09-05 20:15:00 +02:00
}
else
{
if(real_ncol)
win_by_col = otherwin / real_ncol;
2007-09-15 02:52:41 +02:00
2007-12-27 11:50:09 +01:00
if((i - curtags[0]->nmaster) && (i - curtags[0]->nmaster) % win_by_col == 0 && current_col < real_ncol - 1)
2007-09-15 02:52:41 +02:00
current_col++;
if(current_col == real_ncol - 1)
win_by_col += otherwin % real_ncol;
2007-09-15 02:52:41 +02:00
if(otherwin <= real_ncol)
2008-01-05 20:18:30 +01:00
geometry.height = wah - 2 * c->border;
2007-09-14 20:59:37 +02:00
else
2008-01-05 20:18:30 +01:00
geometry.height = (wah / win_by_col) - 2 * c->border;
2007-09-15 02:52:41 +02:00
2008-01-05 20:18:30 +01:00
geometry.width = (waw - mw) / real_ncol - 2 * c->border;
2007-09-15 02:52:41 +02:00
2007-12-27 11:50:09 +01:00
if(i == curtags[0]->nmaster || otherwin <= real_ncol || (i - curtags[0]->nmaster) % win_by_col == 0)
2008-01-05 20:18:30 +01:00
geometry.y = way;
2007-09-13 23:20:05 +02:00
else
2008-01-05 20:18:30 +01:00
geometry.y = way + ((i - curtags[0]->nmaster) % win_by_col) * (geometry.height + 2 * c->border);
2007-09-15 02:52:41 +02:00
2008-01-05 20:18:30 +01:00
geometry.x = wax + current_col * (geometry.width + 2 * c->border) + (right ? mw : 0);
client_resize(c, geometry, globalconf.screens[screen].resize_hints);
2007-09-05 20:15:00 +02:00
}
i++;
2007-09-05 20:15:00 +02:00
}
2007-12-27 11:50:09 +01:00
p_delete(&curtags);
2007-09-05 20:15:00 +02:00
}
void
layout_tile(int screen)
2007-09-05 20:15:00 +02:00
{
_tile(screen, True);
2007-09-05 20:15:00 +02:00
}
void
layout_tileleft(int screen)
2007-09-05 20:15:00 +02:00
{
_tile(screen, False);
2007-09-05 20:15:00 +02:00
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80