2007-10-03 17:26:14 +02:00
|
|
|
/*
|
2007-09-12 14:29:51 +02:00
|
|
|
* tile.c - tile layout
|
|
|
|
*
|
2007-10-03 17:26:14 +02:00
|
|
|
* Copyright © 2007 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>
|
|
|
|
|
2007-09-15 15:16:53 +02:00
|
|
|
#include "util.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 */
|
2007-10-03 00:30:15 +02:00
|
|
|
extern Client *clients;
|
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
|
|
|
{
|
2007-09-24 11:20:07 +02:00
|
|
|
if(!arg || (!IS_ARRANGE(layout_tile) && !IS_ARRANGE(layout_tileleft)))
|
2007-09-05 20:15:00 +02:00
|
|
|
return;
|
2007-09-14 13:43:51 +02:00
|
|
|
|
2007-10-01 13:00:13 +02:00
|
|
|
|
2007-09-15 14:20:01 +02:00
|
|
|
if((awesomeconf->nmaster = (int) compute_new_value_from_arg(arg, (double) awesomeconf->nmaster)) < 0)
|
|
|
|
awesomeconf->nmaster = 0;
|
2007-09-14 13:43:51 +02:00
|
|
|
|
2007-09-17 13:45:13 +02:00
|
|
|
arrange(disp, drawcontext, awesomeconf);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2007-09-15 13:04:36 +02:00
|
|
|
void
|
2007-10-08 18:45:05 +02:00
|
|
|
uicb_setncol(Display *disp,
|
|
|
|
DC * drawcontext,
|
|
|
|
awesome_config *awesomeconf,
|
|
|
|
const char * arg)
|
2007-09-15 13:04:36 +02:00
|
|
|
{
|
2007-09-20 22:07:59 +02:00
|
|
|
if(!arg || (!IS_ARRANGE(layout_tile) && !IS_ARRANGE(layout_tileleft)))
|
2007-09-15 13:04:36 +02:00
|
|
|
return;
|
|
|
|
|
2007-10-08 18:45:05 +02:00
|
|
|
if((awesomeconf->ncol = (int) compute_new_value_from_arg(arg, (double) awesomeconf->ncol)) < 1)
|
|
|
|
awesomeconf->ncol = 1;
|
2007-09-15 13:04:36 +02:00
|
|
|
|
2007-09-17 13:45:13 +02:00
|
|
|
arrange(disp, drawcontext, awesomeconf);
|
2007-09-15 13:04:36 +02:00
|
|
|
}
|
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
void
|
|
|
|
uicb_setmwfact(Display *disp,
|
2007-09-16 01:05:43 +02:00
|
|
|
DC *drawcontext,
|
2007-09-13 19:11:24 +02:00
|
|
|
awesome_config * awesomeconf,
|
|
|
|
const char *arg)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-10-01 13:00:13 +02:00
|
|
|
char *newarg;
|
|
|
|
|
|
|
|
if((!IS_ARRANGE(layout_tile) && !IS_ARRANGE(layout_tileleft)) || !arg)
|
2007-09-05 20:15:00 +02:00
|
|
|
return;
|
|
|
|
|
2007-10-01 13:00:13 +02:00
|
|
|
newarg = a_strdup(arg);
|
|
|
|
if(IS_ARRANGE(layout_tileleft))
|
|
|
|
{
|
|
|
|
if(newarg[0] == '+')
|
|
|
|
newarg[0] = '-';
|
|
|
|
else if(arg[0] == '-')
|
|
|
|
newarg[0] = '+';
|
|
|
|
}
|
|
|
|
|
|
|
|
if((awesomeconf->mwfact = compute_new_value_from_arg(newarg, awesomeconf->mwfact)) < 0.1)
|
2007-09-15 14:20:01 +02:00
|
|
|
awesomeconf->mwfact = 0.1;
|
|
|
|
else if(awesomeconf->mwfact > 0.9)
|
|
|
|
awesomeconf->mwfact = 0.9;
|
|
|
|
|
2007-09-17 13:45:13 +02:00
|
|
|
arrange(disp, drawcontext, awesomeconf);
|
2007-10-01 13:00:13 +02:00
|
|
|
p_delete(&newarg);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-09-17 14:07:31 +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;
|
2007-09-27 22:29:36 +02:00
|
|
|
int n, i, masterwin = 0, otherwin = 0;
|
2007-10-08 18:45:05 +02:00
|
|
|
int real_ncol = 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-10-01 20:58:29 +02:00
|
|
|
screens_info = get_screen_info(disp, awesomeconf->screen, &awesomeconf->statusbar);
|
2007-10-03 17:26:14 +02:00
|
|
|
|
2007-09-06 20:02:30 +02:00
|
|
|
for(n = 0, c = clients; c; c = c->next)
|
2007-09-24 15:37:52 +02:00
|
|
|
if(IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
|
2007-09-06 20:02:30 +02:00
|
|
|
n++;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2007-09-27 22:29:36 +02:00
|
|
|
wah = screens_info[awesomeconf->screen].height;
|
|
|
|
waw = screens_info[awesomeconf->screen].width;
|
|
|
|
wax = screens_info[awesomeconf->screen].x_org;
|
|
|
|
way = screens_info[awesomeconf->screen].y_org;
|
2007-09-13 23:20:05 +02:00
|
|
|
|
2007-09-27 22:29:36 +02:00
|
|
|
masterwin = MIN(n, awesomeconf->nmaster);
|
2007-10-03 17:26:14 +02:00
|
|
|
|
2007-09-27 22:29:36 +02:00
|
|
|
otherwin = n - masterwin;
|
2007-10-03 17:26:14 +02:00
|
|
|
|
2007-09-27 22:29:36 +02:00
|
|
|
if(otherwin < 0)
|
|
|
|
otherwin = 0;
|
2007-09-15 02:52:41 +02:00
|
|
|
|
2007-09-27 22:29:36 +02:00
|
|
|
if(awesomeconf->nmaster)
|
|
|
|
{
|
|
|
|
mh = masterwin ? wah / masterwin : waw;
|
|
|
|
mw = otherwin ? waw * awesomeconf->mwfact : waw;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mh = mw = 0;
|
2007-09-15 14:37:26 +02:00
|
|
|
|
2007-10-08 18:45:05 +02:00
|
|
|
real_ncol = MIN(otherwin, awesomeconf->ncol);
|
2007-09-15 15:48:31 +02:00
|
|
|
|
2007-09-27 22:29:36 +02:00
|
|
|
for(i = 0, c = clients; c; c = c->next)
|
|
|
|
{
|
|
|
|
if(!IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
|
|
|
|
continue;
|
2007-09-13 23:20:05 +02:00
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
c->ismax = False;
|
2007-09-27 22:29:36 +02:00
|
|
|
if(i < awesomeconf->nmaster)
|
2007-09-05 20:15:00 +02:00
|
|
|
{ /* master */
|
2007-09-27 22:29:36 +02:00
|
|
|
ny = way + i * mh;
|
|
|
|
nx = wax + (right ? 0 : waw - mw);
|
2007-09-28 11:30:51 +02:00
|
|
|
resize(c, nx, ny, mw - 2 * c->border, mh - 2 * c->border, awesomeconf, awesomeconf->resize_hints);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* tile window */
|
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
|
|
|
|
2007-10-08 18:45:05 +02:00
|
|
|
if((i - awesomeconf->nmaster) && (i - awesomeconf->nmaster) % win_by_col == 0 && 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
|
|
|
|
2007-10-08 18:45:05 +02:00
|
|
|
if(otherwin <= real_ncol)
|
2007-09-15 02:52:41 +02:00
|
|
|
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;
|
|
|
|
|
2007-10-08 18:45:05 +02:00
|
|
|
nw = (waw - mw) / real_ncol - 2 * c->border;
|
2007-09-15 02:52:41 +02:00
|
|
|
|
2007-10-08 18:45:05 +02:00
|
|
|
if(i == awesomeconf->nmaster || otherwin <= real_ncol || (i - awesomeconf->nmaster) % win_by_col == 0)
|
2007-09-13 23:20:05 +02:00
|
|
|
ny = way;
|
|
|
|
else
|
2007-09-27 22:29:36 +02:00
|
|
|
ny = way + ((i - awesomeconf->nmaster) % win_by_col) * (nh + 2 * c->border);
|
2007-09-15 02:52:41 +02:00
|
|
|
|
2007-10-09 10:45:27 +02:00
|
|
|
nx = wax + current_col * (nw + 2 * c->border) + (right ? mw : 0);
|
2007-09-28 11:30:51 +02:00
|
|
|
resize(c, nx, ny, nw, nh, awesomeconf, awesomeconf->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
|
|
|
}
|
2007-09-13 23:20:05 +02:00
|
|
|
XFree(screens_info);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-09-20 22:07:59 +02:00
|
|
|
layout_tile(Display *disp, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-09-17 14:07:31 +02:00
|
|
|
_tile(disp, awesomeconf, True);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-09-20 22:07:59 +02:00
|
|
|
layout_tileleft(Display *disp, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-09-17 14:07:31 +02:00
|
|
|
_tile(disp, awesomeconf, False);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|