awesome/layouts/tile.c

234 lines
6.2 KiB
C
Raw Normal View History

2007-09-12 14:29:51 +02:00
/*
* tile.c - tile layout
*
* Copyright © 2007 Julien Danjou <julien@danjou.info>
* Copyright © 2007 Ross Mohn <rpmohn@waxandwane.org>
*
* 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-05 20:15:00 +02:00
#include <stdio.h>
#include "layouts/tile.h"
#include "layout.h"
#include "tag.h"
2007-09-05 20:15:00 +02:00
/* extern */
extern int wax, way, wah, waw; /* windowarea geometry */
extern Client *sel, *clients;
/* static */
2007-09-10 12:06:54 +02:00
static void _tile(awesome_config *, const Bool); /* arranges all windows tiled */
2007-09-05 20:15:00 +02:00
2007-09-11 15:53:03 +02:00
static double mwfact = 0.6;
2007-09-05 20:15:00 +02:00
static int nmaster = 2;
void
2007-09-11 15:53:03 +02:00
uicb_setnmaster(Display *disp,
2007-09-10 12:06:54 +02:00
awesome_config *awesomeconf,
2007-09-05 20:15:00 +02:00
const char * arg)
{
2007-09-11 15:53:03 +02:00
int delta;
2007-09-05 20:15:00 +02:00
if(!IS_ARRANGE(tile) && !IS_ARRANGE(tileleft) && !IS_ARRANGE(bstack) && !IS_ARRANGE(bstackportrait))
return;
if(!arg)
2007-09-10 12:06:54 +02:00
nmaster = awesomeconf->nmaster;
2007-09-11 15:53:03 +02:00
else if(sscanf(arg, "%d", &delta))
2007-09-05 20:15:00 +02:00
{
2007-09-11 15:53:03 +02:00
if((arg[0] == '+' || arg[0] == '-')
&& !((nmaster + delta) < 1 || wah / (nmaster + delta) <= 2 * awesomeconf->borderpx))
nmaster += delta;
else if(delta >= 1 && wah / delta <= 2 * awesomeconf->borderpx)
nmaster = delta;
else
2007-09-05 20:15:00 +02:00
return;
}
if(sel)
2007-09-10 12:06:54 +02:00
arrange(disp, awesomeconf);
2007-09-05 20:15:00 +02:00
else
2007-09-10 12:06:54 +02:00
drawstatus(disp, awesomeconf);
2007-09-05 20:15:00 +02:00
}
void
uicb_setmwfact(Display *disp,
2007-09-10 12:06:54 +02:00
awesome_config * awesomeconf,
2007-09-05 20:15:00 +02:00
const char *arg)
{
double delta;
if(!IS_ARRANGE(tile) && !IS_ARRANGE(tileleft) && !IS_ARRANGE(bstack) && !IS_ARRANGE(bstackportrait))
return;
/* arg handling, manipulate mwfact */
if(!arg)
2007-09-10 12:06:54 +02:00
mwfact = awesomeconf->mwfact;
2007-09-11 15:53:03 +02:00
else if(sscanf(arg, "%lf", &delta))
2007-09-05 20:15:00 +02:00
{
if(arg[0] != '+' && arg[0] != '-')
mwfact = delta;
else
mwfact += delta;
if(mwfact < 0.1)
mwfact = 0.1;
else if(mwfact > 0.9)
mwfact = 0.9;
}
2007-09-10 12:06:54 +02:00
arrange(disp, awesomeconf);
2007-09-05 20:15:00 +02:00
}
static void
2007-09-10 12:06:54 +02:00
_tile(awesome_config *awesomeconf, const Bool right)
2007-09-05 20:15:00 +02:00
{
unsigned int nx, ny, nw, nh, mw;
int n, th, i, mh;
Client *c;
for(n = 0, c = clients; c; c = c->next)
2007-09-10 12:06:54 +02:00
if(IS_TILED(c, awesomeconf->selected_tags, awesomeconf->ntags))
n++;
2007-09-05 20:15:00 +02:00
/* window geoms */
mh = (n <= nmaster) ? wah / (n > 0 ? n : 1) : wah / nmaster;
mw = (n <= nmaster) ? waw : mwfact * waw;
th = (n > nmaster) ? wah / (n - nmaster) : 0;
2007-09-10 12:06:54 +02:00
if(n > nmaster && th < awesomeconf->statusbar.height)
2007-09-05 20:15:00 +02:00
th = wah;
nx = wax;
ny = way;
for(i = 0, c = clients; c; c = c->next)
2007-09-05 20:15:00 +02:00
{
2007-09-10 12:06:54 +02:00
if(!IS_TILED(c, awesomeconf->selected_tags, awesomeconf->ntags))
continue;
2007-09-05 20:15:00 +02:00
c->ismax = False;
if(i < nmaster)
{ /* master */
ny = way + i * mh;
if(!right && i == 0)
nx += (waw - mw);
nw = mw - 2 * c->border;
nh = mh;
if(i + 1 == (n < nmaster ? n : nmaster)) /* remainder */
nh = wah - mh * i;
nh -= 2 * c->border;
}
else
{ /* tile window */
if(i == nmaster)
{
ny = way;
if(right)
nx += mw;
else
nx = 0;
}
nw = waw - mw - 2 * c->border;
if(i + 1 == n) /* remainder */
nh = (way + wah) - ny - 2 * c->border;
else
nh = th - 2 * c->border;
}
2007-09-10 12:06:54 +02:00
resize(c, nx, ny, nw, nh, awesomeconf->resize_hints);
2007-09-05 20:15:00 +02:00
if(n > nmaster && th != wah)
ny += nh + 2 * c->border;
i++;
2007-09-05 20:15:00 +02:00
}
}
void
2007-09-10 12:06:54 +02:00
tile(Display *disp __attribute__ ((unused)), awesome_config *awesomeconf)
2007-09-05 20:15:00 +02:00
{
2007-09-10 12:06:54 +02:00
_tile(awesomeconf, True);
2007-09-05 20:15:00 +02:00
}
void
2007-09-10 12:06:54 +02:00
tileleft(Display *disp __attribute__ ((unused)), awesome_config *awesomeconf)
2007-09-05 20:15:00 +02:00
{
2007-09-10 12:06:54 +02:00
_tile(awesomeconf, False);
2007-09-05 20:15:00 +02:00
}
static void
2007-09-10 12:06:54 +02:00
_bstack(awesome_config *awesomeconf, Bool portrait)
2007-09-05 20:15:00 +02:00
{
int i, n, nx, ny, nw, nh, mw, mh, tw, th;
Client *c;
for(n = 0, c = clients; c; c = c->next)
2007-09-10 12:06:54 +02:00
if(IS_TILED(c, awesomeconf->selected_tags, awesomeconf->ntags))
n++;
2007-09-05 20:15:00 +02:00
/* window geoms */
mh = (n > nmaster) ? (wah * mwfact) / nmaster : wah / (n > 0 ? n : 1);
mw = waw;
th = (n > nmaster) ? (wah * (1 - mwfact)) / (portrait ? 1 : n - nmaster) : 0;
tw = (n > nmaster) ? waw / (portrait ? n - nmaster : 1) : 0;
for(i = 0, c = clients; c; c = c->next)
2007-09-05 20:15:00 +02:00
{
2007-09-10 12:06:54 +02:00
if(!IS_TILED(c, awesomeconf->selected_tags, awesomeconf->ntags))
continue;
2007-09-05 20:15:00 +02:00
c->ismax = False;
nx = wax;
ny = way;
if(i < nmaster)
{
ny += i * mh;
nw = mw - 2 * c->border;
nh = mh - 2 * c->border;
}
else if(portrait)
{
nx += (i - nmaster) * tw;
ny += mh * nmaster;
nw = tw - 2 * c->border;
nh = th - 2 * c->border + 1;
}
else
{
ny += mh * nmaster;
nw = tw - 2 * c->border;
if(th > 2 * c->border)
{
ny += (i - nmaster) * th;
nh = th - 2 * c->border;
if (i == n - 1)
nh += (n > nmaster) ? wah - mh - th * (n - nmaster) : 0;
}
else
nh = wah - 2 * c->border;
}
resize(c, nx, ny, nw, nh, False);
i++;
2007-09-05 20:15:00 +02:00
}
}
void
2007-09-10 12:06:54 +02:00
bstack(Display *disp __attribute__ ((unused)), awesome_config *awesomeconf)
2007-09-05 20:15:00 +02:00
{
2007-09-10 12:06:54 +02:00
_bstack(awesomeconf, False);
2007-09-05 20:15:00 +02:00
}
void
2007-09-10 12:06:54 +02:00
bstackportrait(Display *disp __attribute__ ((unused)), awesome_config *awesomeconf)
2007-09-05 20:15:00 +02:00
{
2007-09-10 12:06:54 +02:00
_bstack(awesomeconf, True);
2007-09-05 20:15:00 +02:00
}