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>
|
|
|
|
|
2007-09-14 11:35:17 +02:00
|
|
|
#include "screen.h"
|
2007-09-12 16:03:42 +02:00
|
|
|
#include "awesome.h"
|
2007-09-06 20:02:30 +02:00
|
|
|
#include "tag.h"
|
2007-09-12 16:03:42 +02:00
|
|
|
#include "layout.h"
|
|
|
|
#include "layouts/tile.h"
|
2007-09-05 20:15:00 +02:00
|
|
|
|
|
|
|
/* extern */
|
|
|
|
extern Client *sel, *clients;
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
|
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;
|
2007-09-15 02:52:41 +02:00
|
|
|
static int ncols = 1;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
|
|
|
void
|
2007-09-11 15:53:03 +02:00
|
|
|
uicb_setnmaster(Display *disp,
|
2007-09-13 19:11:24 +02:00
|
|
|
DC * drawcontext,
|
|
|
|
awesome_config *awesomeconf,
|
|
|
|
const char * arg)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
if(!IS_ARRANGE(tile) && !IS_ARRANGE(tileleft) && !IS_ARRANGE(bstack) && !IS_ARRANGE(bstackportrait))
|
|
|
|
return;
|
2007-09-14 13:43:51 +02:00
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
if(!arg)
|
2007-09-10 12:06:54 +02:00
|
|
|
nmaster = awesomeconf->nmaster;
|
2007-09-14 13:43:51 +02:00
|
|
|
else
|
2007-09-14 21:20:05 +02:00
|
|
|
if((nmaster = (int) compute_new_value_from_arg(arg, (double) nmaster)) < 0)
|
2007-09-14 20:59:37 +02:00
|
|
|
nmaster = 0;
|
2007-09-14 13:43:51 +02:00
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
if(sel)
|
2007-09-13 19:11:24 +02:00
|
|
|
arrange(disp, drawcontext, awesomeconf);
|
2007-09-05 20:15:00 +02:00
|
|
|
else
|
2007-09-13 19:11:24 +02:00
|
|
|
drawstatus(disp, drawcontext, awesomeconf);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
uicb_setmwfact(Display *disp,
|
2007-09-13 19:11:24 +02:00
|
|
|
DC *drawcontext,
|
|
|
|
awesome_config * awesomeconf,
|
|
|
|
const char *arg)
|
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
|
|
|
mwfact = awesomeconf->mwfact;
|
2007-09-14 13:54:59 +02:00
|
|
|
else
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-09-14 21:20:05 +02:00
|
|
|
if((mwfact = compute_new_value_from_arg(arg, mwfact)) < 0.1)
|
2007-09-05 20:15:00 +02:00
|
|
|
mwfact = 0.1;
|
|
|
|
else if(mwfact > 0.9)
|
|
|
|
mwfact = 0.9;
|
|
|
|
}
|
2007-09-13 19:11:24 +02:00
|
|
|
arrange(disp, drawcontext, awesomeconf);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-09-12 16:03:42 +02:00
|
|
|
_tile(Display *disp, awesome_config *awesomeconf, 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 */
|
|
|
|
unsigned int nx, ny, nw, nh;
|
|
|
|
/* master size */
|
|
|
|
unsigned int mw = 0, mh = 0;
|
|
|
|
int n, i, li, last_i = 0, nmaster_screen = 0, otherwin_screen = 0;
|
|
|
|
int screen_numbers = 1, use_screen = -1;
|
2007-09-15 02:52:41 +02:00
|
|
|
int real_ncols = 1, win_by_col = 1, current_col = 0;
|
2007-09-14 11:35:17 +02:00
|
|
|
ScreenInfo *screens_info = NULL;
|
2007-09-05 20:15:00 +02:00
|
|
|
Client *c;
|
|
|
|
|
2007-09-14 11:35:17 +02:00
|
|
|
screens_info = get_screen_info(disp, awesomeconf->statusbar, &screen_numbers);
|
|
|
|
|
2007-09-06 20:02:30 +02:00
|
|
|
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))
|
2007-09-06 20:02:30 +02:00
|
|
|
n++;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2007-09-06 20:02:30 +02:00
|
|
|
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))
|
2007-09-06 20:02:30 +02:00
|
|
|
continue;
|
2007-09-13 23:20:05 +02:00
|
|
|
|
|
|
|
if(use_screen == -1 || (screen_numbers > 1 && i && ((i - last_i) >= nmaster_screen + otherwin_screen || n == screen_numbers)))
|
|
|
|
{
|
|
|
|
use_screen++;
|
|
|
|
last_i = i;
|
|
|
|
|
|
|
|
wah = screens_info[use_screen].height;
|
|
|
|
waw = screens_info[use_screen].width;
|
|
|
|
wax = screens_info[use_screen].x_org;
|
|
|
|
way = screens_info[use_screen].y_org;
|
|
|
|
|
|
|
|
if(n >= nmaster * screen_numbers)
|
|
|
|
{
|
|
|
|
nmaster_screen = nmaster;
|
|
|
|
otherwin_screen = (n - (nmaster * screen_numbers)) / screen_numbers;
|
|
|
|
if(use_screen == 0)
|
|
|
|
otherwin_screen += (n - (nmaster * screen_numbers)) % screen_numbers;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nmaster_screen = n / screen_numbers;
|
|
|
|
/* first screen takes more master */
|
|
|
|
if(use_screen == 0)
|
|
|
|
nmaster_screen += n % screen_numbers;
|
|
|
|
otherwin_screen = 0;
|
|
|
|
}
|
|
|
|
|
2007-09-15 02:52:41 +02:00
|
|
|
if(nmaster)
|
|
|
|
{
|
|
|
|
mh = nmaster_screen ? wah / nmaster_screen : waw;
|
|
|
|
mw = otherwin_screen ? waw * mwfact : waw;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mh = mw = 0;
|
|
|
|
|
|
|
|
if(otherwin_screen < ncols)
|
|
|
|
real_ncols = otherwin_screen;
|
|
|
|
else
|
|
|
|
real_ncols = ncols;
|
2007-09-13 23:20:05 +02:00
|
|
|
}
|
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
c->ismax = False;
|
2007-09-13 23:20:05 +02:00
|
|
|
li = last_i ? i - last_i : i;
|
|
|
|
if(li < nmaster)
|
2007-09-05 20:15:00 +02:00
|
|
|
{ /* master */
|
2007-09-13 23:20:05 +02:00
|
|
|
ny = way + li * mh;
|
|
|
|
if(right)
|
|
|
|
nx = wax;
|
|
|
|
else
|
|
|
|
nx = wax + (waw - mw);
|
2007-09-05 20:15:00 +02:00
|
|
|
nw = mw - 2 * c->border;
|
2007-09-13 23:20:05 +02:00
|
|
|
nh = mh - 2 * c->border;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* tile window */
|
2007-09-15 02:52:41 +02:00
|
|
|
win_by_col = otherwin_screen / real_ncols;
|
|
|
|
|
|
|
|
if((li - nmaster) && (li - nmaster) % win_by_col == 0 && current_col < real_ncols - 1)
|
|
|
|
current_col++;
|
|
|
|
|
|
|
|
if(current_col == real_ncols - 1)
|
|
|
|
win_by_col += otherwin_screen % real_ncols;
|
|
|
|
|
|
|
|
if(otherwin_screen <= real_ncols)
|
|
|
|
nh = wah - 2 * c->border;
|
2007-09-14 20:59:37 +02:00
|
|
|
else
|
2007-09-15 02:52:41 +02:00
|
|
|
nh = (wah / win_by_col) - 2 * c->border;
|
|
|
|
|
|
|
|
nw = (waw - mw) / real_ncols - 2 * c->border;
|
|
|
|
|
|
|
|
if(li == nmaster || otherwin_screen <= real_ncols || (li - nmaster) % win_by_col == 0)
|
2007-09-13 23:20:05 +02:00
|
|
|
ny = way;
|
|
|
|
else
|
2007-09-15 02:52:41 +02:00
|
|
|
ny = way + ((li - nmaster) % win_by_col) * (nh + 2 * c->border);
|
|
|
|
|
|
|
|
nx = wax + current_col * nw + (right ? mw : 0);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2007-09-10 12:06:54 +02:00
|
|
|
resize(c, nx, ny, nw, nh, awesomeconf->resize_hints);
|
2007-09-06 20:02:30 +02:00
|
|
|
i++;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2007-09-13 23:20:05 +02:00
|
|
|
XFree(screens_info);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-09-12 16:03:42 +02:00
|
|
|
tile(Display *disp, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-09-12 16:03:42 +02:00
|
|
|
_tile(disp, awesomeconf, True);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-09-12 16:03:42 +02:00
|
|
|
tileleft(Display *disp, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-09-12 16:03:42 +02:00
|
|
|
_tile(disp, awesomeconf, False);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2007-09-12 16:03:42 +02:00
|
|
|
_bstack(Display *disp, awesome_config *awesomeconf, Bool portrait)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
int i, n, nx, ny, nw, nh, mw, mh, tw, th;
|
2007-09-12 16:03:42 +02:00
|
|
|
int wah = get_windows_area_height(disp, awesomeconf->statusbar);
|
|
|
|
int waw = get_windows_area_width(disp, awesomeconf->statusbar);
|
2007-09-05 20:15:00 +02:00
|
|
|
Client *c;
|
|
|
|
|
2007-09-06 20:02:30 +02:00
|
|
|
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))
|
2007-09-06 20:02:30 +02:00
|
|
|
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;
|
|
|
|
|
2007-09-06 20:02:30 +02:00
|
|
|
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))
|
2007-09-06 20:02:30 +02:00
|
|
|
continue;
|
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
c->ismax = False;
|
2007-09-12 16:03:42 +02:00
|
|
|
nx = get_windows_area_x(awesomeconf->statusbar);
|
|
|
|
ny = get_windows_area_y(awesomeconf->statusbar);
|
2007-09-05 20:15:00 +02:00
|
|
|
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);
|
2007-09-06 20:02:30 +02:00
|
|
|
i++;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-09-12 16:03:42 +02:00
|
|
|
bstack(Display *disp, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-09-12 16:03:42 +02:00
|
|
|
_bstack(disp, awesomeconf, False);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-09-12 16:03:42 +02:00
|
|
|
bstackportrait(Display *disp, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-09-12 16:03:42 +02:00
|
|
|
_bstack(disp, awesomeconf, True);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|