2007-10-03 17:26:14 +02:00
|
|
|
/*
|
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>
|
2007-10-03 17:26:14 +02:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
2007-09-14 11:35:17 +02:00
|
|
|
#include "screen.h"
|
2008-06-09 21:43:09 +02:00
|
|
|
#include "tag.h"
|
2008-01-01 17:25:48 +01:00
|
|
|
#include "client.h"
|
2007-09-12 16:03:42 +02:00
|
|
|
#include "layouts/tile.h"
|
2008-01-21 18:14:59 +01:00
|
|
|
#include "common/util.h"
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-05-24 08:59:27 +02:00
|
|
|
extern awesome_t globalconf;
|
2007-12-16 02:45:38 +01:00
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
static void
|
2008-06-09 21:43:09 +02:00
|
|
|
_tile(int screen, const position_t position)
|
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;
|
|
|
|
/* master size */
|
|
|
|
unsigned int mw = 0, mh = 0;
|
2007-09-27 22:29:36 +02:00
|
|
|
int n, i, masterwin = 0, otherwin = 0;
|
2008-06-09 21:43:09 +02:00
|
|
|
int real_ncol = 1, win_by_col = 1, current_col = 0;
|
2008-06-22 22:09:48 +02:00
|
|
|
area_t area, geometry = { 0, 0, 0, 0 };
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *c;
|
2008-06-09 21:43:09 +02:00
|
|
|
tag_t **curtags = tags_get_current(screen);
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-06-04 15:35:48 +02:00
|
|
|
area = screen_area_get(screen,
|
2007-12-23 00:54:59 +01:00
|
|
|
globalconf.screens[screen].statusbar,
|
2008-06-04 15:35:48 +02:00
|
|
|
&globalconf.screens[screen].padding);
|
2007-10-03 17:26:14 +02:00
|
|
|
|
2007-12-16 02:45:38 +01:00
|
|
|
for(n = 0, c = globalconf.clients; c; c = c->next)
|
|
|
|
if(IS_TILED(c, screen))
|
2007-09-06 20:02:30 +02:00
|
|
|
n++;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2007-12-23 00:54:59 +01:00
|
|
|
wah = area.height;
|
|
|
|
waw = area.width;
|
|
|
|
wax = area.x;
|
|
|
|
way = area.y;
|
2007-09-13 23:20:05 +02:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
masterwin = MIN(n, curtags[0]->nmaster);
|
2007-10-03 17:26:14 +02:00
|
|
|
|
2008-05-27 20:15:52 +02:00
|
|
|
otherwin = MAX(n - masterwin, 0);
|
2007-09-15 02:52:41 +02:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
if(curtags[0]->nmaster)
|
2008-01-17 17:15:47 +01:00
|
|
|
switch(position)
|
2008-01-14 00:37:46 +01:00
|
|
|
{
|
2008-01-17 17:15:47 +01:00
|
|
|
case Right:
|
|
|
|
case Left:
|
2008-01-14 00:37:46 +01:00
|
|
|
mh = masterwin ? wah / masterwin : wah;
|
2008-06-09 21:43:09 +02:00
|
|
|
mw = otherwin ? waw * curtags[0]->mwfact : waw;
|
2008-01-17 17:15:47 +01:00
|
|
|
break;
|
|
|
|
default:
|
2008-06-09 21:43:09 +02:00
|
|
|
mh = otherwin ? wah * curtags[0]->mwfact : wah;
|
2008-01-14 00:37:46 +01:00
|
|
|
mw = masterwin ? waw / masterwin : waw;
|
2008-01-17 17:15:47 +01:00
|
|
|
break;
|
2008-01-14 00:37:46 +01:00
|
|
|
}
|
2007-09-27 22:29:36 +02:00
|
|
|
else
|
|
|
|
mh = mw = 0;
|
2007-09-15 14:37:26 +02:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
real_ncol = curtags[0]->ncol > 0 ? MIN(otherwin, curtags[0]->ncol) : MIN(otherwin, 1);
|
2007-09-15 15:48:31 +02:00
|
|
|
|
2007-12-16 02:45:38 +01:00
|
|
|
for(i = 0, c = globalconf.clients; c; c = c->next)
|
2007-09-27 22:29:36 +02:00
|
|
|
{
|
2007-12-16 02:45:38 +01:00
|
|
|
if(!IS_TILED(c, screen))
|
2007-09-27 22:29:36 +02:00
|
|
|
continue;
|
2007-09-13 23:20:05 +02:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
if(i < curtags[0]->nmaster)
|
2008-01-06 14:40:23 +01:00
|
|
|
{
|
2008-01-17 17:15:47 +01:00
|
|
|
switch(position)
|
2008-01-14 00:37:46 +01:00
|
|
|
{
|
2008-01-17 17:15:47 +01:00
|
|
|
case Right:
|
2008-01-14 00:37:46 +01:00
|
|
|
geometry.y = way + i * mh;
|
2008-01-17 17:15:47 +01:00
|
|
|
geometry.x = wax;
|
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
geometry.y = way + i * mh;
|
|
|
|
geometry.x = wax + (waw - mw);
|
|
|
|
break;
|
|
|
|
case Top:
|
|
|
|
geometry.x = wax + i * mw;
|
|
|
|
geometry.y = way + (wah - mh);
|
|
|
|
break;
|
|
|
|
case Bottom:
|
|
|
|
default:
|
2008-01-14 00:37:46 +01:00
|
|
|
geometry.x = wax + i * mw;
|
2008-01-17 17:15:47 +01:00
|
|
|
geometry.y = way;
|
|
|
|
break;
|
|
|
|
break;
|
2008-01-14 00:37:46 +01:00
|
|
|
}
|
2008-03-14 16:16:42 +01:00
|
|
|
|
2008-01-05 20:18:30 +01:00
|
|
|
geometry.width = mw - 2 * c->border;
|
|
|
|
geometry.height = mh - 2 * c->border;
|
2008-03-14 16:16:42 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
client_resize(c, geometry, globalconf.resize_hints);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
else
|
2008-01-06 14:40:23 +01:00
|
|
|
{
|
2007-10-08 18:45:05 +02:00
|
|
|
if(real_ncol)
|
|
|
|
win_by_col = otherwin / real_ncol;
|
2007-09-15 02:52:41 +02:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
if((i - curtags[0]->nmaster)
|
|
|
|
&& (i - curtags[0]->nmaster) % win_by_col == 0
|
2008-05-27 20:15:52 +02:00
|
|
|
&& current_col < real_ncol - 1)
|
2007-09-15 02:52:41 +02:00
|
|
|
current_col++;
|
|
|
|
|
2007-10-08 18:45:05 +02:00
|
|
|
if(current_col == real_ncol - 1)
|
|
|
|
win_by_col += otherwin % real_ncol;
|
2007-09-15 02:52:41 +02:00
|
|
|
|
2008-01-17 17:15:47 +01:00
|
|
|
if(position == Right || position == Left)
|
2008-01-14 00:37:46 +01:00
|
|
|
{
|
|
|
|
if(otherwin <= real_ncol)
|
|
|
|
geometry.height = wah - 2 * c->border;
|
|
|
|
else
|
|
|
|
geometry.height = (wah / win_by_col) - 2 * c->border;
|
|
|
|
|
|
|
|
geometry.width = (waw - mw) / real_ncol - 2 * c->border;
|
2007-09-15 02:52:41 +02:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
if(i == curtags[0]->nmaster || otherwin <= real_ncol || (i - curtags[0]->nmaster) % win_by_col == 0)
|
2008-01-14 00:37:46 +01:00
|
|
|
geometry.y = way;
|
|
|
|
else
|
2008-06-09 21:43:09 +02: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-17 17:15:47 +01:00
|
|
|
geometry.x = wax + current_col * (geometry.width + 2 * c->border);
|
|
|
|
|
|
|
|
if(position == Right)
|
|
|
|
geometry.x += mw;
|
2008-01-14 00:37:46 +01:00
|
|
|
}
|
2007-09-13 23:20:05 +02:00
|
|
|
else
|
2008-01-14 00:37:46 +01:00
|
|
|
{
|
|
|
|
if(otherwin <= real_ncol)
|
|
|
|
geometry.width = waw - 2 * c->border;
|
|
|
|
else
|
|
|
|
geometry.width = (waw / win_by_col) - 2 * c->border;
|
|
|
|
|
|
|
|
geometry.height = (wah - mh) / real_ncol - 2 * c->border;
|
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
if(i == curtags[0]->nmaster || otherwin <= real_ncol || (i - curtags[0]->nmaster) % win_by_col == 0)
|
2008-01-14 00:37:46 +01:00
|
|
|
geometry.x = wax;
|
|
|
|
else
|
2008-06-09 21:43:09 +02:00
|
|
|
geometry.x = wax + ((i - curtags[0]->nmaster) % win_by_col) * (geometry.width + 2 * c->border);
|
2008-01-14 00:37:46 +01:00
|
|
|
|
2008-01-17 17:15:47 +01:00
|
|
|
geometry.y = way + current_col * (geometry.height + 2 * c->border);
|
2007-09-15 02:52:41 +02:00
|
|
|
|
2008-01-17 17:15:47 +01:00
|
|
|
if(position == Bottom)
|
|
|
|
geometry.y += mh;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
client_resize(c, geometry, globalconf.resize_hints);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2007-09-06 20:02:30 +02:00
|
|
|
i++;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2008-06-09 21:43:09 +02:00
|
|
|
|
|
|
|
p_delete(&curtags);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-09 21:43:09 +02:00
|
|
|
layout_tile(int screen)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
_tile(screen, Right);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-09 21:43:09 +02:00
|
|
|
layout_tileleft(int screen)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
_tile(screen, Left);
|
2008-01-14 00:37:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-09 21:43:09 +02:00
|
|
|
layout_tilebottom(int screen)
|
2008-01-14 00:37:46 +01:00
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
_tile(screen, Bottom);
|
2008-01-14 00:37:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-09 21:43:09 +02:00
|
|
|
layout_tiletop(int screen)
|
2008-01-14 00:37:46 +01:00
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
_tile(screen, Top);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2007-12-11 20:56:51 +01:00
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|