2006-02-03 18:15:36 +03:00
|
|
|
/*
|
|
|
|
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
|
|
|
* See LICENSE file for license details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2006-02-19 18:21:01 +03:00
|
|
|
#include <string.h>
|
2006-02-03 18:15:36 +03:00
|
|
|
|
|
|
|
#include "wm.h"
|
|
|
|
|
|
|
|
Area *
|
2006-02-10 19:09:59 +03:00
|
|
|
alloc_area(Page *p)
|
2006-02-03 18:15:36 +03:00
|
|
|
{
|
2006-02-03 20:11:22 +03:00
|
|
|
static unsigned short id = 1;
|
2006-02-03 18:15:36 +03:00
|
|
|
Area *a = cext_emallocz(sizeof(Area));
|
2006-02-11 17:22:42 +03:00
|
|
|
a->page = p;
|
2006-02-03 18:15:36 +03:00
|
|
|
a->id = id++;
|
2006-02-19 17:40:44 +03:00
|
|
|
update_area_geometry(a);
|
2006-02-10 19:09:59 +03:00
|
|
|
p->area = (Area **)cext_array_attach((void **)p->area, a, sizeof(Area *), &p->areasz);
|
2006-02-19 12:40:09 +03:00
|
|
|
p->sel = p->narea;
|
2006-02-10 19:09:59 +03:00
|
|
|
p->narea++;
|
2006-02-03 18:15:36 +03:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2006-02-19 17:40:44 +03:00
|
|
|
void
|
|
|
|
update_area_geometry(Area *a)
|
|
|
|
{
|
|
|
|
a->rect = rect;
|
|
|
|
a->rect.height -= brect.height;
|
|
|
|
}
|
|
|
|
|
2006-02-03 18:15:36 +03:00
|
|
|
void
|
|
|
|
destroy_area(Area *a)
|
|
|
|
{
|
|
|
|
size_t i;
|
2006-02-19 17:40:44 +03:00
|
|
|
Page *p = a->page;
|
2006-02-03 18:15:36 +03:00
|
|
|
while(a->nclient)
|
|
|
|
detach_client(client[i], False);
|
|
|
|
free(a->client);
|
2006-02-19 17:40:44 +03:00
|
|
|
cext_array_detach((void **)p->area, a, &p->areasz);
|
|
|
|
p->narea--;
|
2006-02-03 18:15:36 +03:00
|
|
|
free(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-02-11 17:22:42 +03:00
|
|
|
area_to_index(Area *a)
|
2006-02-03 18:15:36 +03:00
|
|
|
{
|
|
|
|
int i;
|
2006-02-11 17:22:42 +03:00
|
|
|
Page *p = a->page;
|
2006-02-03 18:15:36 +03:00
|
|
|
for(i = 0; i < p->narea; i++)
|
|
|
|
if(p->area[i] == a)
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-02-10 17:59:30 +03:00
|
|
|
aid_to_index(Page *p, unsigned short id)
|
2006-02-03 18:15:36 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < p->narea; i++)
|
|
|
|
if(p->area[i]->id == id)
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
2006-02-19 18:21:01 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
select_area(Area *a, char *arg)
|
|
|
|
{
|
|
|
|
Area *new;
|
|
|
|
Page *p = a->page;
|
|
|
|
int i = area_to_index(a);
|
|
|
|
if(i == -1)
|
|
|
|
return;
|
|
|
|
if(!strncmp(arg, "prev", 5)) {
|
2006-02-24 11:52:20 +03:00
|
|
|
if(i == 1)
|
2006-02-19 18:21:01 +03:00
|
|
|
i = p->narea - 1;
|
|
|
|
else
|
|
|
|
i--;
|
|
|
|
} else if(!strncmp(arg, "next", 5)) {
|
|
|
|
if(i + 1 < p->narea)
|
|
|
|
i++;
|
|
|
|
else
|
2006-02-24 11:52:20 +03:00
|
|
|
i = 1;
|
2006-02-19 18:21:01 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
const char *errstr;
|
|
|
|
i = cext_strtonum(arg, 1, p->narea, &errstr);
|
|
|
|
if(errstr)
|
|
|
|
return;
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
new = p->area[i];
|
|
|
|
if(new->nclient)
|
|
|
|
focus_client(new->client[new->sel], True);
|
2006-02-20 09:46:54 +03:00
|
|
|
else
|
|
|
|
p->sel = i;
|
2006-02-19 18:21:01 +03:00
|
|
|
}
|
2006-02-24 12:06:02 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
sendto_area(Area *new, Client *c)
|
|
|
|
{
|
|
|
|
Area *a = c->area;
|
|
|
|
|
|
|
|
cext_array_detach((void **)a->client, c, &a->clientsz);
|
|
|
|
a->nclient--;
|
|
|
|
if(a->sel >= a->nclient)
|
|
|
|
a->sel = 0;
|
|
|
|
|
|
|
|
new->client = (Client **)cext_array_attach(
|
|
|
|
(void **)new->client, c, sizeof(Client *), &new->clientsz);
|
|
|
|
new->nclient++;
|
|
|
|
c->area = new;
|
|
|
|
arrange_column(a);
|
|
|
|
arrange_column(new);
|
|
|
|
focus_client(c, True);
|
|
|
|
}
|