awesome/layouts/tile.c

205 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>
*
* 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 "util.h"
#include "screen.h"
#include "awesome.h"
#include "tag.h"
#include "layout.h"
#include "layouts/tile.h"
2007-09-05 20:15:00 +02:00
/* extern */
extern Client *sel, *clients;
void
2007-09-11 15:53:03 +02:00
uicb_setnmaster(Display *disp,
DC * drawcontext,
awesome_config *awesomeconf,
const char * arg)
2007-09-05 20:15:00 +02:00
{
2007-09-15 14:20:01 +02:00
if(!arg || (!IS_ARRANGE(tile) && !IS_ARRANGE(tileleft)))
2007-09-05 20:15:00 +02:00
return;
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-15 14:20:01 +02:00
arrange(disp, drawcontext, awesomeconf);
2007-09-05 20:15:00 +02:00
}
void
uicb_setncols(Display *disp,
DC * drawcontext,
awesome_config *awesomeconf,
const char * arg)
{
2007-09-15 14:20:01 +02:00
if(!arg || (!IS_ARRANGE(tile) && !IS_ARRANGE(tileleft)))
return;
2007-09-15 14:20:01 +02:00
if((awesomeconf->ncols = (int) compute_new_value_from_arg(arg, (double) awesomeconf->ncols)) < 1)
awesomeconf->ncols = 1;
2007-09-15 14:20:01 +02:00
arrange(disp, drawcontext, awesomeconf);
}
2007-09-05 20:15:00 +02:00
void
uicb_setmwfact(Display *disp,
DC *drawcontext,
awesome_config * awesomeconf,
const char *arg)
2007-09-05 20:15:00 +02:00
{
2007-09-15 12:37:34 +02:00
if(!IS_ARRANGE(tile) && !IS_ARRANGE(tileleft))
2007-09-05 20:15:00 +02:00
return;
2007-09-15 14:20:01 +02:00
if((awesomeconf->mwfact = compute_new_value_from_arg(arg, awesomeconf->mwfact)) < 0.1)
awesomeconf->mwfact = 0.1;
else if(awesomeconf->mwfact > 0.9)
awesomeconf->mwfact = 0.9;
arrange(disp, drawcontext, awesomeconf);
2007-09-05 20:15:00 +02:00
}
static void
_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-15 14:26:55 +02:00
int n, i, li, last_i = 0, masterwin = 0, otherwin = 0;
2007-09-13 23:20:05 +02:00
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;
ScreenInfo *screens_info = NULL;
2007-09-05 20:15:00 +02:00
Client *c;
screens_info = get_screen_info(disp, awesomeconf->statusbar, &screen_numbers);
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
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-13 23:20:05 +02:00
2007-09-15 14:23:18 +02:00
if(use_screen == -1
|| (screen_numbers > 1
&& i
2007-09-15 14:26:55 +02:00
&& ((i - last_i) >= masterwin + otherwin
2007-09-15 14:23:18 +02:00
|| n == screen_numbers)))
2007-09-13 23:20:05 +02:00
{
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;
2007-09-15 14:20:01 +02:00
if(n >= awesomeconf->nmaster * screen_numbers)
2007-09-13 23:20:05 +02:00
{
2007-09-15 14:26:55 +02:00
masterwin = awesomeconf->nmaster;
otherwin = (n - (awesomeconf->nmaster * screen_numbers)) / screen_numbers;
2007-09-13 23:20:05 +02:00
if(use_screen == 0)
2007-09-15 14:26:55 +02:00
otherwin += (n - (awesomeconf->nmaster * screen_numbers)) % screen_numbers;
2007-09-13 23:20:05 +02:00
}
else
{
2007-09-15 14:26:55 +02:00
masterwin = n / screen_numbers;
2007-09-13 23:20:05 +02:00
/* first screen takes more master */
if(use_screen == 0)
2007-09-15 14:26:55 +02:00
masterwin += n % screen_numbers;
otherwin = 0;
2007-09-13 23:20:05 +02:00
}
2007-09-15 14:20:01 +02:00
if(awesomeconf->nmaster)
2007-09-15 02:52:41 +02:00
{
2007-09-15 14:26:55 +02:00
mh = masterwin ? wah / masterwin : waw;
mw = otherwin ? waw * awesomeconf->mwfact : waw;
2007-09-15 02:52:41 +02:00
}
else
mh = mw = 0;
2007-09-15 14:37:26 +02:00
mw -= 2 * c->border;
2007-09-15 14:40:08 +02:00
mh -= 2 * c->border;
2007-09-15 14:37:26 +02:00
2007-09-15 14:26:55 +02:00
if(otherwin < awesomeconf->ncols)
real_ncols = otherwin;
2007-09-15 02:52:41 +02:00
else
2007-09-15 14:20:01 +02:00
real_ncols = awesomeconf->ncols;
current_col = 0;
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;
2007-09-15 14:20:01 +02:00
if(li < awesomeconf->nmaster)
2007-09-05 20:15:00 +02:00
{ /* master */
2007-09-15 14:40:08 +02:00
ny = way + li * (mh + 2 * c->border);
nx = wax + (right ? 0 : waw - (mw + 2 * c->border));
resize(c, nx, ny, mw, mh, awesomeconf->resize_hints);
2007-09-05 20:15:00 +02:00
}
else
{ /* tile window */
2007-09-15 14:26:55 +02:00
win_by_col = otherwin / real_ncols;
2007-09-15 02:52:41 +02:00
2007-09-15 14:20:01 +02:00
if((li - awesomeconf->nmaster) && (li - awesomeconf->nmaster) % win_by_col == 0 && current_col < real_ncols - 1)
2007-09-15 02:52:41 +02:00
current_col++;
if(current_col == real_ncols - 1)
2007-09-15 14:26:55 +02:00
win_by_col += otherwin % real_ncols;
2007-09-15 02:52:41 +02:00
2007-09-15 14:26:55 +02:00
if(otherwin <= real_ncols)
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-09-15 14:37:26 +02:00
nw = (waw - (mw + 2 * c->border)) / real_ncols - 2 * c->border;
2007-09-15 02:52:41 +02:00
2007-09-15 14:26:55 +02:00
if(li == awesomeconf->nmaster || otherwin <= real_ncols || (li - awesomeconf->nmaster) % win_by_col == 0)
2007-09-13 23:20:05 +02:00
ny = way;
else
2007-09-15 14:20:01 +02:00
ny = way + ((li - awesomeconf->nmaster) % win_by_col) * (nh + 2 * c->border);
2007-09-15 02:52:41 +02:00
2007-09-15 14:37:26 +02:00
nx = wax + current_col * nw + (right ? mw + 2 * c->border : 0);
resize(c, nx, ny, nw, nh, awesomeconf->resize_hints);
2007-09-05 20:15:00 +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
tile(Display *disp, awesome_config *awesomeconf)
2007-09-05 20:15:00 +02:00
{
_tile(disp, awesomeconf, True);
2007-09-05 20:15:00 +02:00
}
void
tileleft(Display *disp, awesome_config *awesomeconf)
2007-09-05 20:15:00 +02:00
{
_tile(disp, awesomeconf, False);
2007-09-05 20:15:00 +02:00
}