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-03-23 12:36:51 +03:00
|
|
|
alloc_area(View *v)
|
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-03-23 12:36:51 +03:00
|
|
|
a->view = v;
|
2006-02-03 18:15:36 +03:00
|
|
|
a->id = id++;
|
2006-03-11 23:48:02 +03:00
|
|
|
a->rect = rect;
|
|
|
|
a->rect.height = rect.height - brect.height;
|
2006-03-23 12:36:51 +03:00
|
|
|
v->area = (Area **)cext_array_attach((void **)v->area, a,
|
|
|
|
sizeof(Area *), &v->areasz);
|
|
|
|
v->sel = v->narea;
|
|
|
|
v->narea++;
|
2006-03-23 01:16:23 +03:00
|
|
|
return a;
|
2006-02-03 18:15:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
destroy_area(Area *a)
|
|
|
|
{
|
2006-03-11 22:50:53 +03:00
|
|
|
unsigned int i;
|
2006-03-23 12:36:51 +03:00
|
|
|
View *v = a->view;
|
2006-03-05 03:55:45 +03:00
|
|
|
if(a->nframe)
|
2006-03-02 21:58:54 +03:00
|
|
|
return;
|
2006-03-05 03:55:45 +03:00
|
|
|
if(a->frame)
|
|
|
|
free(a->frame);
|
2006-03-23 12:36:51 +03:00
|
|
|
if(v->revert == area2index(a))
|
|
|
|
v->revert = 0;
|
2006-03-11 22:50:53 +03:00
|
|
|
for(i = 0; i < nclient; i++)
|
|
|
|
if(client[i]->revert == a)
|
|
|
|
client[i]->revert = 0;
|
2006-03-23 12:36:51 +03:00
|
|
|
cext_array_detach((void **)v->area, a, &v->areasz);
|
|
|
|
v->narea--;
|
|
|
|
if(v->sel > 1)
|
|
|
|
v->sel--;
|
2006-02-03 18:15:36 +03:00
|
|
|
free(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-03-01 09:51:04 +03:00
|
|
|
area2index(Area *a)
|
2006-02-03 18:15:36 +03:00
|
|
|
{
|
|
|
|
int i;
|
2006-03-23 12:36:51 +03:00
|
|
|
View *v = a->view;
|
|
|
|
for(i = 0; i < v->narea; i++)
|
|
|
|
if(v->area[i] == a)
|
2006-02-03 18:15:36 +03:00
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-03-23 12:36:51 +03:00
|
|
|
aid2index(View *v, unsigned short id)
|
2006-02-03 18:15:36 +03:00
|
|
|
{
|
|
|
|
int i;
|
2006-03-23 12:36:51 +03:00
|
|
|
for(i = 0; i < v->narea; i++)
|
|
|
|
if(v->area[i]->id == id)
|
2006-02-03 18:15:36 +03:00
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
2006-02-19 18:21:01 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
select_area(Area *a, char *arg)
|
|
|
|
{
|
|
|
|
Area *new;
|
2006-03-23 12:36:51 +03:00
|
|
|
View *v = a->view;
|
2006-03-01 09:51:04 +03:00
|
|
|
int i = area2index(a);
|
2006-03-31 09:57:33 +04:00
|
|
|
|
2006-02-19 18:21:01 +03:00
|
|
|
if(i == -1)
|
|
|
|
return;
|
2006-03-11 22:50:53 +03:00
|
|
|
if(i)
|
2006-03-23 12:36:51 +03:00
|
|
|
v->revert = i;
|
2006-03-31 09:57:33 +04:00
|
|
|
|
2006-03-11 22:37:29 +03:00
|
|
|
if(!strncmp(arg, "toggle", 7)) {
|
|
|
|
if(i)
|
|
|
|
i = 0;
|
2006-03-23 12:36:51 +03:00
|
|
|
else if(v->revert > 0 && v->revert < v->narea)
|
|
|
|
i = v->revert;
|
2006-03-11 22:37:29 +03:00
|
|
|
else
|
|
|
|
i = 1;
|
|
|
|
} else if(!strncmp(arg, "prev", 5)) {
|
2006-03-23 17:58:36 +03:00
|
|
|
if(i > 0) {
|
2006-03-18 19:24:02 +03:00
|
|
|
if(i == 1)
|
2006-03-23 12:36:51 +03:00
|
|
|
i = v->narea - 1;
|
2006-03-18 19:24:02 +03:00
|
|
|
else
|
|
|
|
i--;
|
|
|
|
}
|
2006-02-19 18:21:01 +03:00
|
|
|
} else if(!strncmp(arg, "next", 5)) {
|
2006-03-23 17:58:36 +03:00
|
|
|
if(i > 0) {
|
2006-03-23 12:36:51 +03:00
|
|
|
if(i + 1 < v->narea)
|
2006-03-18 19:24:02 +03:00
|
|
|
i++;
|
|
|
|
else
|
|
|
|
i = 1;
|
|
|
|
}
|
2006-02-19 18:21:01 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
const char *errstr;
|
2006-03-23 12:36:51 +03:00
|
|
|
i = cext_strtonum(arg, 0, v->narea - 1, &errstr);
|
2006-02-19 18:21:01 +03:00
|
|
|
if(errstr)
|
|
|
|
return;
|
|
|
|
}
|
2006-03-23 12:36:51 +03:00
|
|
|
new = v->area[i];
|
2006-03-05 03:55:45 +03:00
|
|
|
if(new->nframe)
|
|
|
|
focus_client(new->frame[new->sel]->client);
|
2006-03-23 12:36:51 +03:00
|
|
|
v->sel = i;
|
2006-03-11 22:59:40 +03:00
|
|
|
for(i = 0; i < a->nframe; i++)
|
|
|
|
draw_client(a->frame[i]->client);
|
2006-03-31 09:57:33 +04:00
|
|
|
|
|
|
|
if(!new->nframe) {
|
|
|
|
update_view_label(v);
|
|
|
|
draw_bar();
|
|
|
|
}
|
2006-02-19 18:21:01 +03:00
|
|
|
}
|
2006-02-24 12:06:02 +03:00
|
|
|
|
|
|
|
void
|
2006-03-08 18:05:09 +03:00
|
|
|
send2area(Area *to, Area *from, Client *c)
|
2006-02-24 12:06:02 +03:00
|
|
|
{
|
2006-03-11 22:50:53 +03:00
|
|
|
c->revert = from;
|
2006-03-27 09:46:12 +04:00
|
|
|
detach_fromarea(from, c);
|
2006-03-02 19:38:15 +03:00
|
|
|
attach_toarea(to, c);
|
2006-02-28 10:51:53 +03:00
|
|
|
focus_client(c);
|
2006-02-24 12:06:02 +03:00
|
|
|
}
|
2006-03-02 12:26:30 +03:00
|
|
|
|
|
|
|
void
|
2006-03-02 19:38:15 +03:00
|
|
|
attach_toarea(Area *a, Client *c)
|
2006-03-02 12:26:30 +03:00
|
|
|
{
|
2006-03-05 03:55:45 +03:00
|
|
|
static unsigned short id = 1;
|
2006-03-06 18:35:07 +03:00
|
|
|
Frame *f;
|
2006-03-23 18:12:06 +03:00
|
|
|
|
2006-03-23 12:43:57 +03:00
|
|
|
if(clientofview(a->view, c))
|
2006-03-06 18:35:07 +03:00
|
|
|
return;
|
2006-03-31 09:57:33 +04:00
|
|
|
c->floating = !area2index(a); /* set floating flag */
|
2006-03-06 18:35:07 +03:00
|
|
|
f = cext_emallocz(sizeof(Frame));
|
2006-03-05 03:55:45 +03:00
|
|
|
f->id = id++;
|
|
|
|
f->area = a;
|
|
|
|
f->client = c;
|
|
|
|
f->rect = c->rect;
|
2006-03-23 01:16:23 +03:00
|
|
|
f->rect.width += 2 * def.border;
|
|
|
|
f->rect.height += def.border + bar_height();
|
2006-03-07 01:55:47 +03:00
|
|
|
c->frame = (Frame **)cext_array_attach(
|
|
|
|
(void **)c->frame, f, sizeof(Frame *), &c->framesz);
|
|
|
|
c->nframe++;
|
|
|
|
c->sel = c->nframe - 1;
|
2006-03-05 03:55:45 +03:00
|
|
|
a->frame = (Frame **)cext_array_attach(
|
|
|
|
(void **)a->frame, f, sizeof(Frame *), &a->framesz);
|
|
|
|
a->nframe++;
|
2006-03-27 10:38:17 +04:00
|
|
|
a->sel = a->nframe - 1;
|
2006-03-02 21:58:54 +03:00
|
|
|
if(area2index(a)) /* column */
|
2006-03-27 10:38:17 +04:00
|
|
|
arrange_column(a);
|
2006-03-02 21:58:54 +03:00
|
|
|
else /* floating */
|
2006-03-15 18:00:39 +03:00
|
|
|
resize_client(c, &f->rect, False);
|
2006-03-02 12:26:30 +03:00
|
|
|
}
|
|
|
|
|
2006-03-02 15:37:52 +03:00
|
|
|
void
|
2006-03-27 09:46:12 +04:00
|
|
|
detach_fromarea(Area *a, Client *c)
|
2006-03-02 15:37:52 +03:00
|
|
|
{
|
2006-03-07 01:55:47 +03:00
|
|
|
Frame *f;
|
2006-03-23 12:36:51 +03:00
|
|
|
View *v = a->view;
|
2006-03-07 01:55:47 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < c->nframe; i++)
|
|
|
|
if(c->frame[i]->area == a) {
|
|
|
|
f = c->frame[i];
|
|
|
|
break;
|
|
|
|
}
|
2006-03-06 19:22:54 +03:00
|
|
|
|
2006-03-07 01:55:47 +03:00
|
|
|
cext_array_detach((void **)c->frame, f, &c->framesz);
|
2006-03-05 03:55:45 +03:00
|
|
|
cext_array_detach((void **)a->frame, f, &a->framesz);
|
|
|
|
free(f);
|
2006-03-07 01:55:47 +03:00
|
|
|
c->nframe--;
|
2006-03-09 00:41:45 +03:00
|
|
|
if(c->sel > 0)
|
|
|
|
c->sel--;
|
2006-03-05 03:55:45 +03:00
|
|
|
a->nframe--;
|
2006-03-09 00:41:45 +03:00
|
|
|
if(a->sel > 0)
|
|
|
|
a->sel--;
|
2006-03-27 09:17:47 +04:00
|
|
|
|
2006-03-09 13:42:32 +03:00
|
|
|
i = area2index(a);
|
|
|
|
if(i && a->nframe)
|
2006-03-27 10:38:17 +04:00
|
|
|
arrange_column(a);
|
2006-03-04 11:23:17 +03:00
|
|
|
else {
|
2006-03-09 14:44:38 +03:00
|
|
|
if(i) {
|
2006-03-23 12:36:51 +03:00
|
|
|
if(v->narea > 2)
|
2006-03-09 14:44:38 +03:00
|
|
|
destroy_area(a);
|
2006-03-23 12:36:51 +03:00
|
|
|
else if(!a->nframe && v->area[0]->nframe)
|
|
|
|
v->sel = 0; /* focus floating area if it contains something */
|
2006-03-27 09:17:47 +04:00
|
|
|
arrange_view(v, True);
|
2006-03-09 14:44:38 +03:00
|
|
|
}
|
2006-03-09 02:27:12 +03:00
|
|
|
else if(!i && !a->nframe) {
|
|
|
|
if(c->trans) {
|
|
|
|
/* focus area of transient, if possible */
|
|
|
|
Client *cl = win2client(c->trans);
|
|
|
|
if(cl && cl->nframe) {
|
|
|
|
a = cl->frame[cl->sel]->area;
|
2006-03-23 12:36:51 +03:00
|
|
|
if(a->view == v)
|
|
|
|
v->sel = area2index(a);
|
2006-03-09 02:27:12 +03:00
|
|
|
}
|
|
|
|
}
|
2006-03-23 12:36:51 +03:00
|
|
|
else if(v->area[1]->nframe)
|
|
|
|
v->sel = 1; /* focus first col as fallback */
|
2006-03-09 02:27:12 +03:00
|
|
|
}
|
2006-03-04 11:23:17 +03:00
|
|
|
}
|
2006-03-02 17:28:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2006-03-05 02:11:08 +03:00
|
|
|
mode2str(int mode)
|
2006-03-02 17:28:55 +03:00
|
|
|
{
|
|
|
|
switch(mode) {
|
2006-03-05 02:11:08 +03:00
|
|
|
case Colequal: return "equal"; break;
|
|
|
|
case Colstack: return "stack"; break;
|
|
|
|
case Colmax: return "max"; break;
|
2006-03-02 17:28:55 +03:00
|
|
|
default: break;
|
|
|
|
}
|
2006-03-23 18:12:06 +03:00
|
|
|
return nil;
|
2006-03-02 17:28:55 +03:00
|
|
|
}
|
|
|
|
|
2006-03-05 02:11:08 +03:00
|
|
|
int
|
|
|
|
str2mode(char *arg)
|
2006-03-02 17:28:55 +03:00
|
|
|
{
|
|
|
|
if(!strncmp("equal", arg, 6))
|
2006-03-05 02:11:08 +03:00
|
|
|
return Colequal;
|
2006-03-02 17:28:55 +03:00
|
|
|
if(!strncmp("stack", arg, 6))
|
2006-03-05 02:11:08 +03:00
|
|
|
return Colstack;
|
2006-03-02 17:28:55 +03:00
|
|
|
if(!strncmp("max", arg, 4))
|
2006-03-05 02:11:08 +03:00
|
|
|
return Colmax;
|
2006-03-02 17:28:55 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
relax_area(Area *a)
|
|
|
|
{
|
2006-03-04 11:23:17 +03:00
|
|
|
unsigned int i, yoff, h, hdiff;
|
2006-03-12 13:00:39 +03:00
|
|
|
Bool fallthrough = False;
|
2006-03-02 17:28:55 +03:00
|
|
|
|
2006-03-05 03:55:45 +03:00
|
|
|
if(!a->nframe)
|
2006-03-02 17:28:55 +03:00
|
|
|
return;
|
|
|
|
|
2006-03-12 13:00:39 +03:00
|
|
|
switch(a->mode) {
|
|
|
|
case Colequal:
|
|
|
|
h = a->rect.height;
|
|
|
|
h /= a->nframe;
|
|
|
|
if(h < 2 * bar_height())
|
|
|
|
fallthrough = True;
|
|
|
|
break;
|
|
|
|
case Colstack:
|
|
|
|
yoff = a->rect.y;
|
|
|
|
h = a->rect.height - (a->nframe - 1) * bar_height();
|
|
|
|
if(h < 3 * bar_height())
|
|
|
|
fallthrough = True;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fallthrough) {
|
|
|
|
for(i = 0; i < a->nframe; i++) {
|
|
|
|
Frame *f = a->frame[i];
|
|
|
|
f->rect.x = a->rect.x + (a->rect.width - f->rect.width) / 2;
|
2006-03-13 10:22:21 +03:00
|
|
|
f->rect.y = a->rect.y + (a->rect.height - f->rect.height) / 2;
|
2006-03-15 18:00:39 +03:00
|
|
|
resize_client(f->client, &f->rect, False);
|
2006-03-12 13:00:39 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-02 17:28:55 +03:00
|
|
|
/* some relaxing from potential increment gaps */
|
2006-03-04 11:23:17 +03:00
|
|
|
h = 0;
|
2006-03-05 03:55:45 +03:00
|
|
|
for(i = 0; i < a->nframe; i++) {
|
|
|
|
Frame *f = a->frame[i];
|
2006-03-27 11:38:41 +04:00
|
|
|
if(a->mode == Colmax) {
|
2006-03-05 03:55:45 +03:00
|
|
|
if(h < f->rect.height)
|
|
|
|
h = f->rect.height;
|
2006-03-02 17:28:55 +03:00
|
|
|
}
|
|
|
|
else
|
2006-03-05 03:55:45 +03:00
|
|
|
h += f->rect.height;
|
2006-03-02 17:28:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* try to add rest space to all clients if not COL_STACK mode */
|
2006-03-05 02:11:08 +03:00
|
|
|
if(a->mode != Colstack) {
|
2006-03-05 03:55:45 +03:00
|
|
|
for(i = 0; (h < a->rect.height) && (i < a->nframe); i++) {
|
|
|
|
Frame *f = a->frame[i];
|
|
|
|
unsigned int tmp = f->rect.height;
|
|
|
|
f->rect.height += (a->rect.height - h);
|
2006-03-15 18:00:39 +03:00
|
|
|
resize_client(f->client, &f->rect, True);
|
2006-03-05 03:55:45 +03:00
|
|
|
h += (f->rect.height - tmp);
|
2006-03-02 17:28:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-05 03:55:45 +03:00
|
|
|
hdiff = (a->rect.height - h) / a->nframe;
|
2006-03-02 17:28:55 +03:00
|
|
|
yoff = a->rect.y + hdiff / 2;
|
2006-03-05 03:55:45 +03:00
|
|
|
for(i = 0; i < a->nframe; i++) {
|
|
|
|
Frame *f = a->frame[i];
|
|
|
|
f->rect.x = a->rect.x + (a->rect.width - f->rect.width) / 2;
|
|
|
|
f->rect.y = yoff;
|
2006-03-27 11:38:41 +04:00
|
|
|
if(a->mode != Colmax)
|
2006-03-05 03:55:45 +03:00
|
|
|
yoff = f->rect.y + f->rect.height + hdiff;
|
2006-03-15 18:00:39 +03:00
|
|
|
resize_client(f->client, &f->rect, False);
|
2006-03-02 17:28:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-03-27 10:38:17 +04:00
|
|
|
arrange_column(Area *a)
|
2006-03-02 17:28:55 +03:00
|
|
|
{
|
|
|
|
unsigned int i, yoff, h;
|
|
|
|
|
2006-03-05 03:55:45 +03:00
|
|
|
if(!a->nframe)
|
2006-03-02 17:28:55 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch(a->mode) {
|
2006-03-05 02:11:08 +03:00
|
|
|
case Colequal:
|
2006-03-02 17:28:55 +03:00
|
|
|
h = a->rect.height;
|
2006-03-05 03:55:45 +03:00
|
|
|
h /= a->nframe;
|
2006-03-12 12:51:12 +03:00
|
|
|
if(h < 2 * bar_height())
|
|
|
|
goto Fallthrough;
|
2006-03-05 03:55:45 +03:00
|
|
|
for(i = 0; i < a->nframe; i++) {
|
|
|
|
Frame *f = a->frame[i];
|
|
|
|
f->rect = a->rect;
|
|
|
|
f->rect.y += i * h;
|
|
|
|
if(i + 1 < a->nframe)
|
|
|
|
f->rect.height = h;
|
2006-03-02 17:28:55 +03:00
|
|
|
else
|
2006-03-05 03:55:45 +03:00
|
|
|
f->rect.height =
|
|
|
|
a->rect.height - f->rect.y + a->rect.y;
|
2006-03-15 18:00:39 +03:00
|
|
|
resize_client(f->client, &f->rect, True);
|
2006-03-02 17:28:55 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-03-05 02:11:08 +03:00
|
|
|
case Colstack:
|
2006-03-02 17:28:55 +03:00
|
|
|
yoff = a->rect.y;
|
2006-03-05 03:55:45 +03:00
|
|
|
h = a->rect.height - (a->nframe - 1) * bar_height();
|
2006-03-12 12:51:12 +03:00
|
|
|
if(h < 3 * bar_height())
|
|
|
|
goto Fallthrough;
|
2006-03-05 03:55:45 +03:00
|
|
|
for(i = 0; i < a->nframe; i++) {
|
|
|
|
Frame *f = a->frame[i];
|
|
|
|
f->rect = a->rect;
|
|
|
|
f->rect.y = yoff;
|
2006-03-02 17:28:55 +03:00
|
|
|
if(i == a->sel)
|
2006-03-05 03:55:45 +03:00
|
|
|
f->rect.height = h;
|
2006-03-02 17:28:55 +03:00
|
|
|
else
|
2006-03-05 03:55:45 +03:00
|
|
|
f->rect.height = bar_height();
|
|
|
|
yoff += f->rect.height;
|
2006-03-15 18:00:39 +03:00
|
|
|
resize_client(f->client, &f->rect, True);
|
2006-03-02 17:28:55 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-03-12 12:51:12 +03:00
|
|
|
Fallthrough:
|
2006-03-05 02:11:08 +03:00
|
|
|
case Colmax:
|
2006-03-05 03:55:45 +03:00
|
|
|
for(i = 0; i < a->nframe; i++) {
|
|
|
|
Frame *f = a->frame[i];
|
|
|
|
f->rect = a->rect;
|
2006-03-15 18:00:39 +03:00
|
|
|
resize_client(f->client, &f->rect, True);
|
2006-03-02 17:28:55 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
relax_area(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
match_horiz(Area *a, XRectangle *r)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2006-03-05 03:55:45 +03:00
|
|
|
for(i = 0; i < a->nframe; i++) {
|
|
|
|
Frame *f = a->frame[i];
|
2006-03-23 01:16:23 +03:00
|
|
|
f->rect.x = r->x;
|
|
|
|
f->rect.width = r->width;
|
|
|
|
resize_client(f->client, &f->rect, False);
|
|
|
|
}
|
2006-03-02 17:28:55 +03:00
|
|
|
}
|
|
|
|
|
2006-03-27 11:01:05 +04:00
|
|
|
|
2006-03-02 17:28:55 +03:00
|
|
|
static void
|
2006-03-05 03:55:45 +03:00
|
|
|
drop_resize(Frame *f, XRectangle *new)
|
2006-03-02 17:28:55 +03:00
|
|
|
{
|
2006-03-23 01:16:23 +03:00
|
|
|
Area *west = nil, *east = nil, *a = f->area;
|
2006-03-23 12:36:51 +03:00
|
|
|
View *v = a->view;
|
2006-03-23 01:16:23 +03:00
|
|
|
Frame *north = nil, *south = nil;
|
2006-03-02 17:28:55 +03:00
|
|
|
unsigned int i;
|
2006-03-28 00:04:38 +04:00
|
|
|
unsigned int min_height = 2 * bar_height();
|
2006-03-02 17:28:55 +03:00
|
|
|
|
2006-03-23 12:36:51 +03:00
|
|
|
for(i = 1; (i < v->narea) && (v->area[i] != a); i++);
|
2006-03-02 17:28:55 +03:00
|
|
|
/* first managed area is indexed 1, thus (i > 1) ? ... */
|
2006-03-23 12:36:51 +03:00
|
|
|
west = (i > 1) ? v->area[i - 1] : nil;
|
|
|
|
east = i + 1 < v->narea ? v->area[i + 1] : nil;
|
2006-03-02 17:28:55 +03:00
|
|
|
|
2006-03-10 00:47:22 +03:00
|
|
|
for(i = 0; (i < a->nframe) && (a->frame[i] != f); i++);
|
2006-03-23 01:16:23 +03:00
|
|
|
north = i ? a->frame[i - 1] : nil;
|
|
|
|
south = i + 1 < a->nframe ? a->frame[i + 1] : nil;
|
|
|
|
|
2006-03-27 11:01:05 +04:00
|
|
|
/* validate (and trim if necessary) horizontal resize */
|
|
|
|
if(new->width < MIN_COLWIDTH) {
|
|
|
|
if(new->x + new->width == f->rect.x + f->rect.width)
|
|
|
|
new->x = a->rect.x + a->rect.width - MIN_COLWIDTH;
|
|
|
|
new->width = MIN_COLWIDTH;
|
|
|
|
}
|
2006-03-23 01:16:23 +03:00
|
|
|
if(west && (new->x != f->rect.x)) {
|
2006-03-23 23:39:02 +03:00
|
|
|
if(new->x < 0 || new->x < (west->rect.x + MIN_COLWIDTH)) {
|
|
|
|
new->width -= (west->rect.x + MIN_COLWIDTH) - new->x;
|
|
|
|
new->x = west->rect.x + MIN_COLWIDTH;
|
2006-03-23 01:16:23 +03:00
|
|
|
}
|
2006-03-27 11:01:05 +04:00
|
|
|
} else {
|
|
|
|
new->width += new->x - a->rect.x;
|
|
|
|
new->x = a->rect.x;
|
|
|
|
}
|
|
|
|
if(east && (new->x + new->width != f->rect.x + f->rect.width)) {
|
|
|
|
if((new->x + new->width) > (east->rect.x + east->rect.width - MIN_COLWIDTH))
|
|
|
|
new->width = (east->rect.x + east->rect.width - MIN_COLWIDTH) - new->x;
|
|
|
|
} else
|
|
|
|
new->width = (a->rect.x + a->rect.width) - new->x;
|
|
|
|
if(new->width < MIN_COLWIDTH)
|
|
|
|
goto AfterHorizontal;
|
|
|
|
|
|
|
|
/* horizontal resize */
|
|
|
|
if(west && (new->x != a->rect.x)) {
|
2006-03-23 01:16:23 +03:00
|
|
|
west->rect.width = new->x - west->rect.x;
|
|
|
|
a->rect.width += a->rect.x - new->x;
|
|
|
|
a->rect.x = new->x;
|
2006-03-27 11:01:05 +04:00
|
|
|
match_horiz(a, &a->rect);
|
2006-03-23 01:16:23 +03:00
|
|
|
match_horiz(west, &west->rect);
|
2006-03-02 17:28:55 +03:00
|
|
|
relax_area(west);
|
2006-03-23 01:16:23 +03:00
|
|
|
}
|
2006-03-27 11:01:05 +04:00
|
|
|
if(east && (new->x + new->width != a->rect.x + a->rect.width)) {
|
2006-03-23 01:16:23 +03:00
|
|
|
east->rect.width -= new->x + new->width - east->rect.x;
|
|
|
|
east->rect.x = new->x + new->width;
|
|
|
|
a->rect.width = (new->x + new->width) - a->rect.x;
|
2006-03-27 11:01:05 +04:00
|
|
|
match_horiz(a, &a->rect);
|
2006-03-23 01:16:23 +03:00
|
|
|
match_horiz(east, &east->rect);
|
2006-03-02 17:28:55 +03:00
|
|
|
relax_area(east);
|
2006-03-19 21:20:07 +03:00
|
|
|
}
|
2006-03-27 11:01:05 +04:00
|
|
|
AfterHorizontal:
|
2006-03-23 01:16:23 +03:00
|
|
|
|
2006-03-28 00:04:38 +04:00
|
|
|
/* skip vertical resize unless the column is in equal mode */
|
2006-03-27 10:38:17 +04:00
|
|
|
if(a->mode != Colequal)
|
2006-03-23 01:16:23 +03:00
|
|
|
goto AfterVertical;
|
2006-03-28 00:04:38 +04:00
|
|
|
|
|
|
|
/* validate (and trim if necessary) vertical resize */
|
2006-03-28 22:17:44 +04:00
|
|
|
if(new->height < min_height) {
|
|
|
|
if(f->rect.height < min_height && (new->y == f->rect.y || new->y + new->height == f->rect.y + f->rect.height))
|
|
|
|
goto AfterVertical;
|
2006-03-28 00:04:38 +04:00
|
|
|
if(new->y + new->height == f->rect.y + f->rect.height)
|
2006-03-28 22:17:44 +04:00
|
|
|
new->y = f->rect.y + f->rect.height - min_height;
|
|
|
|
new->height = min_height;
|
2006-03-28 00:04:38 +04:00
|
|
|
}
|
|
|
|
if(north && (new->y != f->rect.y))
|
|
|
|
if(new->y < 0 || new->y < (north->rect.y + min_height)) {
|
|
|
|
new->height -= (north->rect.y + min_height) - new->y;
|
|
|
|
new->y = north->rect.y + min_height;
|
|
|
|
}
|
|
|
|
if(south && (new->y + new->height != f->rect.y + f->rect.height)) {
|
|
|
|
if((new->y + new->height) > (south->rect.y + south->rect.height - min_height))
|
|
|
|
new->height = (south->rect.y + south->rect.height - min_height) - new->y;
|
|
|
|
}
|
2006-03-28 22:17:44 +04:00
|
|
|
if(new->height < min_height)
|
2006-03-28 00:04:38 +04:00
|
|
|
goto AfterVertical;
|
|
|
|
|
2006-03-23 01:16:23 +03:00
|
|
|
/* vertical resize */
|
|
|
|
if(north && (new->y != f->rect.y)) {
|
|
|
|
north->rect.height = new->y - north->rect.y;
|
|
|
|
f->rect.height += f->rect.y - new->y;
|
|
|
|
f->rect.y = new->y;
|
|
|
|
resize_client(north->client, &north->rect, False);
|
|
|
|
resize_client(f->client, &f->rect, False);
|
|
|
|
}
|
|
|
|
if(south && (new->y + new->height != f->rect.y + f->rect.height)) {
|
|
|
|
south->rect.height -= new->y + new->height - south->rect.y;
|
|
|
|
south->rect.y = new->y + new->height;
|
|
|
|
f->rect.y = new->y;
|
|
|
|
f->rect.height = new->height;
|
|
|
|
resize_client(f->client, &f->rect, False);
|
|
|
|
resize_client(south->client, &south->rect, False);
|
|
|
|
}
|
2006-03-17 23:42:32 +03:00
|
|
|
AfterVertical:
|
2006-03-16 20:58:52 +03:00
|
|
|
|
2006-03-23 01:16:23 +03:00
|
|
|
relax_area(a);
|
2006-03-02 17:28:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-03-05 03:55:45 +03:00
|
|
|
drop_moving(Frame *f, XRectangle *new, XPoint * pt)
|
2006-03-02 17:28:55 +03:00
|
|
|
{
|
2006-03-23 01:16:23 +03:00
|
|
|
Area *tgt = nil, *src = f->area;
|
2006-03-23 12:36:51 +03:00
|
|
|
View *v = src->view;
|
2006-03-02 17:28:55 +03:00
|
|
|
unsigned int i;
|
|
|
|
|
2006-03-23 01:16:23 +03:00
|
|
|
if(!pt || src->nframe < 2)
|
|
|
|
return;
|
2006-03-02 17:28:55 +03:00
|
|
|
|
2006-03-23 12:36:51 +03:00
|
|
|
for(i = 1; (i < v->narea) &&
|
|
|
|
!blitz_ispointinrect(pt->x, pt->y, &v->area[i]->rect); i++);
|
|
|
|
if((tgt = ((i < v->narea) ? v->area[i] : nil))) {
|
2006-03-27 09:46:12 +04:00
|
|
|
if(tgt != src)
|
2006-03-08 18:05:09 +03:00
|
|
|
send2area(tgt, src, f->client);
|
2006-03-23 01:16:23 +03:00
|
|
|
else {
|
2006-03-05 03:55:45 +03:00
|
|
|
for(i = 0; (i < src->nframe) && !blitz_ispointinrect(
|
|
|
|
pt->x, pt->y, &src->frame[i]->rect); i++);
|
|
|
|
if((i < src->nframe) && (f != src->frame[i])) {
|
|
|
|
unsigned int j = frame2index(f);
|
|
|
|
Frame *tmp = src->frame[j];
|
|
|
|
src->frame[j] = src->frame[i];
|
|
|
|
src->frame[i] = tmp;
|
2006-03-27 10:38:17 +04:00
|
|
|
arrange_column(src);
|
2006-03-05 03:55:45 +03:00
|
|
|
focus_client(f->client);
|
2006-03-23 01:16:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-03-02 17:28:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
resize_area(Client *c, XRectangle *r, XPoint *pt)
|
|
|
|
{
|
2006-03-07 01:55:47 +03:00
|
|
|
Frame *f = c->frame[c->sel];
|
2006-03-23 01:16:23 +03:00
|
|
|
if((f->rect.width == r->width) && (f->rect.height == r->height))
|
|
|
|
drop_moving(f, r, pt);
|
|
|
|
else
|
|
|
|
drop_resize(f, r);
|
2006-03-02 17:28:55 +03:00
|
|
|
}
|
2006-03-06 19:22:54 +03:00
|
|
|
|
|
|
|
Bool
|
|
|
|
clientofarea(Area *a, Client *c)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for(i = 0; i < a->nframe; i++)
|
|
|
|
if(a->frame[i]->client == c)
|
|
|
|
return True;
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|