separated tag.c into tag.c and view.c, renamed Tag to View, still some parts to be adapted

This commit is contained in:
Anselm R. Garbe 2006-03-23 10:36:51 +01:00
parent 74a25f3158
commit 04bba2a6c4
12 changed files with 468 additions and 453 deletions

View File

@ -9,7 +9,7 @@ LDFLAGS += -L../../liblitz -llitz -L../../libixp -lixp -L../../libcext -lcext
# Solaris
# LDFLAGS += -lsocket
SRC = area.c bar.c fs.c frame.c wm.c kb.c client.c event.c mouse.c rule.c tag.c
SRC = area.c bar.c fs.c frame.c wm.c kb.c client.c event.c mouse.c rule.c tag.c view.c
OBJ = ${SRC:.c=.o}
all: wmiiwm

View File

@ -9,18 +9,18 @@
#include "wm.h"
Area *
alloc_area(Tag *t)
alloc_area(View *v)
{
static unsigned short id = 1;
Area *a = cext_emallocz(sizeof(Area));
a->tag = t;
a->view = v;
a->id = id++;
a->rect = rect;
a->rect.height = rect.height - brect.height;
t->area = (Area **)cext_array_attach((void **)t->area, a,
sizeof(Area *), &t->areasz);
t->sel = t->narea;
t->narea++;
v->area = (Area **)cext_array_attach((void **)v->area, a,
sizeof(Area *), &v->areasz);
v->sel = v->narea;
v->narea++;
return a;
}
@ -28,20 +28,20 @@ void
destroy_area(Area *a)
{
unsigned int i;
Tag *t = a->tag;
View *v = a->view;
if(a->nframe)
return;
if(a->frame)
free(a->frame);
if(t->revert == area2index(a))
t->revert = 0;
if(v->revert == area2index(a))
v->revert = 0;
for(i = 0; i < nclient; i++)
if(client[i]->revert == a)
client[i]->revert = 0;
cext_array_detach((void **)t->area, a, &t->areasz);
t->narea--;
if(t->sel > 1)
t->sel--;
cext_array_detach((void **)v->area, a, &v->areasz);
v->narea--;
if(v->sel > 1)
v->sel--;
free(a);
}
@ -49,19 +49,19 @@ int
area2index(Area *a)
{
int i;
Tag *t = a->tag;
for(i = 0; i < t->narea; i++)
if(t->area[i] == a)
View *v = a->view;
for(i = 0; i < v->narea; i++)
if(v->area[i] == a)
return i;
return -1;
}
int
aid2index(Tag *t, unsigned short id)
aid2index(View *v, unsigned short id)
{
int i;
for(i = 0; i < t->narea; i++)
if(t->area[i]->id == id)
for(i = 0; i < v->narea; i++)
if(v->area[i]->id == id)
return i;
return -1;
}
@ -70,29 +70,29 @@ void
select_area(Area *a, char *arg)
{
Area *new;
Tag *t = a->tag;
View *v = a->view;
int i = area2index(a);
if(i == -1)
return;
if(i)
t->revert = i;
v->revert = i;
if(!strncmp(arg, "toggle", 7)) {
if(i)
i = 0;
else if(t->revert > 0 && t->revert < t->narea)
i = t->revert;
else if(v->revert > 0 && v->revert < v->narea)
i = v->revert;
else
i = 1;
} else if(!strncmp(arg, "prev", 5)) {
if(i>0) {
if(i == 1)
i = t->narea - 1;
i = v->narea - 1;
else
i--;
}
} else if(!strncmp(arg, "next", 5)) {
if(i>0) {
if(i + 1 < t->narea)
if(i + 1 < v->narea)
i++;
else
i = 1;
@ -100,14 +100,14 @@ select_area(Area *a, char *arg)
}
else {
const char *errstr;
i = cext_strtonum(arg, 0, t->narea - 1, &errstr);
i = cext_strtonum(arg, 0, v->narea - 1, &errstr);
if(errstr)
return;
}
new = t->area[i];
new = v->area[i];
if(new->nframe)
focus_client(new->frame[new->sel]->client);
t->sel = i;
v->sel = i;
for(i = 0; i < a->nframe; i++)
draw_client(a->frame[i]->client);
}
@ -127,7 +127,7 @@ attach_toarea(Area *a, Client *c)
static unsigned short id = 1;
Frame *f;
if(clientoftag(a->tag, c))
if(clientoftag(a->view, c))
return;
f = cext_emallocz(sizeof(Frame));
f->id = id++;
@ -153,7 +153,7 @@ void
detach_fromarea(Area *a, Client *c)
{
Frame *f;
Tag *t = a->tag;
View *v = a->view;
int i;
for(i = 0; i < c->nframe; i++)
@ -176,11 +176,11 @@ detach_fromarea(Area *a, Client *c)
arrange_area(a);
else {
if(i) {
if(t->narea > 2)
if(v->narea > 2)
destroy_area(a);
else if(!a->nframe && t->area[0]->nframe)
t->sel = 0; /* focus floating area if it contains something */
arrange_tag(t, True);
else if(!a->nframe && v->area[0]->nframe)
v->sel = 0; /* focus floating area if it contains something */
arrange_tag(v, True);
}
else if(!i && !a->nframe) {
if(c->trans) {
@ -188,12 +188,12 @@ detach_fromarea(Area *a, Client *c)
Client *cl = win2client(c->trans);
if(cl && cl->nframe) {
a = cl->frame[cl->sel]->area;
if(a->tag == t)
t->sel = area2index(a);
if(a->view == v)
v->sel = area2index(a);
}
}
else if(t->area[1]->nframe)
t->sel = 1; /* focus first col as fallback */
else if(v->area[1]->nframe)
v->sel = 1; /* focus first col as fallback */
}
}
}
@ -352,17 +352,17 @@ Fallthrough:
}
void
arrange_tag(Tag *t, Bool updategeometry)
arrange_tag(View *v, Bool updategeometry)
{
unsigned int i;
unsigned int width;
if(t->narea == 1)
if(v->narea == 1)
return;
width = rect.width / (t->narea - 1);
for(i = 1; i < t->narea; i++) {
Area *a = t->area[i];
width = rect.width / (v->narea - 1);
for(i = 1; i < v->narea; i++) {
Area *a = v->area[i];
if(updategeometry) {
a->rect.height = rect.height - brect.height;
a->rect.x = (i - 1) * width;
@ -389,16 +389,16 @@ static void
drop_resize(Frame *f, XRectangle *new)
{
Area *west = nil, *east = nil, *a = f->area;
Tag *t = a->tag;
View *v = a->view;
Frame *north = nil, *south = nil;
unsigned int i;
unsigned int min = 2 * bar_height();
Bool horiz_resize = False;
for(i = 1; (i < t->narea) && (t->area[i] != a); i++);
for(i = 1; (i < v->narea) && (v->area[i] != a); i++);
/* first managed area is indexed 1, thus (i > 1) ? ... */
west = (i > 1) ? t->area[i - 1] : nil;
east = i + 1 < t->narea ? t->area[i + 1] : nil;
west = (i > 1) ? v->area[i - 1] : nil;
east = i + 1 < v->narea ? v->area[i + 1] : nil;
for(i = 0; (i < a->nframe) && (a->frame[i] != f); i++);
north = i ? a->frame[i - 1] : nil;
@ -473,15 +473,15 @@ static void
drop_moving(Frame *f, XRectangle *new, XPoint * pt)
{
Area *tgt = nil, *src = f->area;
Tag *t = src->tag;
View *v = src->view;
unsigned int i;
if(!pt || src->nframe < 2)
return;
for(i = 1; (i < t->narea) &&
!blitz_ispointinrect(pt->x, pt->y, &t->area[i]->rect); i++);
if((tgt = ((i < t->narea) ? t->area[i] : nil))) {
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))) {
if(tgt != src) {
send2area(tgt, src, f->client);
arrange_area(tgt);

View File

@ -63,14 +63,14 @@ update_bar_geometry()
DefaultDepth(dpy, screen));
XSync(dpy, False);
draw_bar();
for(i = 0; i < ntag; i++) {
for(j = 1; j < tag[i]->narea; j++) {
Area *a = tag[i]->area[j];
for(i = 0; i < nview; i++) {
for(j = 1; j < view[i]->narea; j++) {
Area *a = view[i]->area[j];
a->rect.height = rect.height - brect.height;
arrange_area(a);
}
for(j = 0; j < tag[i]->area[0]->nframe; j++) {
Frame *f = tag[i]->area[0]->frame[j];
for(j = 0; j < view[i]->area[0]->nframe; j++) {
Frame *f = view[i]->area[0]->frame[j];
resize_client(f->client, &f->rect, False);
}
}

View File

@ -82,7 +82,7 @@ focus_client(Client *c)
Frame *f = c->frame[c->sel];
int i = area2index(f->area);
f->area->tag->sel = i;
f->area->view->sel = i;
f->area->sel = frame2index(f);
if(old && (old != c)) {
grab_mouse(old->win, AnyModifier, Button1);
@ -92,7 +92,7 @@ focus_client(Client *c)
grab_mouse(c->win, Mod1Mask, Button1);
grab_mouse(c->win, Mod1Mask, Button3);
restack_tag(f->area->tag);
restack_tag(f->area->view);
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
draw_client(c);
@ -317,7 +317,7 @@ gravitate(Client *c, Bool invert)
void
manage_client(Client *c)
{
Tag *t;
View *v;
Client *trans;
unsigned int i;
@ -331,16 +331,16 @@ manage_client(Client *c)
reparent_client(c, c->framewin, c->rect.x, c->rect.y);
t = ntag ? tag[sel] : alloc_tag(def.tag);
v = nview ? view[sel] : alloc_tag(def.tag);
if(!c->ntag) {
for(i = 0; i < t->ntag; i++) {
cext_strlcpy(c->tag[i], t->tag[i], sizeof(c->tag[i]));
for(i = 0; i < v->ntag; i++) {
cext_strlcpy(c->tag[i], v->tag[i], sizeof(c->tag[i]));
c->ntag++;
}
}
else if((c->ntag == 1) && !strncmp(c->tag[0], "~", 2)) {
for(i = 0; i < t->ntag && i + 1 < MAX_TAGS; i++) {
cext_strlcpy(c->tag[i + 1], t->tag[i], sizeof(c->tag[i + 1]));
for(i = 0; i < v->ntag && i + 1 < MAX_TAGS; i++) {
cext_strlcpy(c->tag[i + 1], v->tag[i], sizeof(c->tag[i + 1]));
c->ntag++;
}
}
@ -363,8 +363,8 @@ destroy_client(Client *c)
XGrabServer(dpy);
XSetErrorHandler(dummy_error_handler);
for(i = 0; i < ntag; i++)
detach_fromtag(tag[i], c);
for(i = 0; i < nview; i++)
detach_fromtag(view[i], c);
unmap_client(c);
@ -381,7 +381,7 @@ destroy_client(Client *c)
update_tags();
free(c);
if((cl = sel_client_of_tag(tag[sel])))
if((cl = sel_client_of_tag(view[sel])))
focus_client(cl);
XSync(dpy, False);
@ -392,7 +392,7 @@ destroy_client(Client *c)
Client *
sel_client()
{
return ntag ? sel_client_of_tag(tag[sel]) : nil;
return nview ? sel_client_of_tag(view[sel]) : nil;
}
static void
@ -445,7 +445,7 @@ resize_client(Client *c, XRectangle *r, Bool ignore_xcall)
match_sizehints(c);
if(!ignore_xcall) {
if(f->area->tag == tag[sel])
if(f->area->view == view[sel])
XMoveResizeWindow(dpy, c->framewin, f->rect.x,
f->rect.y, f->rect.width, f->rect.height);
else
@ -498,7 +498,7 @@ send2area_client(Client *c, char *arg)
const char *errstr;
Frame *f = c->frame[c->sel];
Area *to, *a = f->area;
Tag *t = a->tag;
View *v = a->view;
int i = area2index(a);
if(i == -1)
@ -506,34 +506,34 @@ send2area_client(Client *c, char *arg)
if(!strncmp(arg, "new", 4) && i) {
if(a->nframe == 1)
return;
to = alloc_area(t);
arrange_tag(t, True);
to = alloc_area(v);
arrange_tag(v, True);
}
else if(!strncmp(arg, "prev", 5) && i) {
if(i == 1)
to = t->area[t->narea - 1];
to = v->area[v->narea - 1];
else
to = t->area[i - 1];
to = v->area[i - 1];
}
else if(!strncmp(arg, "next", 5) && i) {
if(i < t->narea - 1)
to = t->area[i + 1];
if(i < v->narea - 1)
to = v->area[i + 1];
else
to = t->area[1];
to = v->area[1];
}
else if(!strncmp(arg, "toggle", 7)) {
if(i)
to = t->area[0];
else if(c->revert && c->revert != t->area[0])
to = v->area[0];
else if(c->revert && c->revert != v->area[0])
to = c->revert;
else
to = t->area[1];
to = v->area[1];
}
else {
i = cext_strtonum(arg, 0, t->narea - 1, &errstr);
i = cext_strtonum(arg, 0, v->narea - 1, &errstr);
if(errstr)
return;
to = t->area[i];
to = v->area[i];
}
send2area(to, a, c);
}
@ -558,14 +558,14 @@ void
focus(Client *c)
{
Frame *f = c->nframe ? c->frame[c->sel] : nil;
Tag *t;
View *v;
if(!f)
return;
t = f->area->tag;
if(tag[sel] != t)
focus_tag(t);
v = f->area->view;
if(view[sel] != v)
focus_tag(v);
focus_client(c);
}

View File

@ -147,7 +147,7 @@ handle_configurerequest(XEvent *e)
wc.border_width = 1;
wc.sibling = None;
wc.stack_mode = ev->detail;
if(f->area->tag != tag[sel])
if(f->area->view != view[sel])
f->rect.x += 2 * rect.width;
XConfigureWindow(dpy, c->framewin, ev->value_mask, &wc);
configure_client(c);

View File

@ -130,9 +130,9 @@ decode_qpath(Qid *qid, unsigned char *type, int *i1, int *i2, int *i3)
}
}
if(i2id && (*i1 != -1)) {
*i2 = aid2index(tag[*i1], i2id);
*i2 = aid2index(view[*i1], i2id);
if(i3id && (*i2 != -1))
*i3 = frid2index(tag[*i1]->area[*i2], i3id);
*i3 = frid2index(view[*i1]->area[*i2], i3id);
}
}
}
@ -164,7 +164,7 @@ qid2name(Qid *qid)
case FsDarea:
if(i1 == -1 || i2 == -1)
return nil;
if(tag[i1]->sel == i2)
if(view[i1]->sel == i2)
return "sel";
snprintf(buf, sizeof(buf), "%u", i2);
return buf;
@ -178,7 +178,7 @@ qid2name(Qid *qid)
case FsDclient:
if(i1 == -1 || i2 == -1 || i3 == -1)
return nil;
if(tag[i1]->area[i2]->sel == i3)
if(view[i1]->area[i2]->sel == i3)
return "sel";
snprintf(buf, sizeof(buf), "%u", i3);
return buf;
@ -331,13 +331,13 @@ mkqid(Qid *dir, char *wname, Qid *new)
break;
case FsDview:
new->type = IXP_QTDIR;
new->path = mkqpath(FsDview, ntag ? tag[sel]->id : 0, 0, 0);
new->path = mkqpath(FsDview, nview ? view[sel]->id : 0, 0, 0);
break;
case FsDarea:
if(dir_i1 == -1 || dir_type != FsDview)
return -1;
{
Tag *p = tag[dir_i1];
View *p = view[dir_i1];
new->type = IXP_QTDIR;
if(!strncmp(wname, "sel", 4)) {
new->path = mkqpath(FsDarea, p->id, p->area[p->sel]->id, 0);
@ -354,7 +354,7 @@ mkqid(Qid *dir, char *wname, Qid *new)
if(dir_i1 == -1 || dir_i2 == -1 || dir_type != FsDarea)
return -1;
{
Tag *p = tag[dir_i1];
View *p = view[dir_i1];
Area *a = p->area[dir_i2];
new->type = IXP_QTDIR;
if(!strncmp(wname, "sel", 4)) {
@ -500,7 +500,7 @@ type2stat(Stat *stat, char *wname, Qid *dir)
break;
case FsFgeom:
if(dir_type == FsDclient) {
f = tag[dir_i1]->area[dir_i2]->frame[dir_i3];
f = view[dir_i1]->area[dir_i2]->frame[dir_i3];
snprintf(buf, sizeof(buf), "%d %d %d %d", f->rect.x, f->rect.y,
f->rect.width, f->rect.height);
}
@ -517,7 +517,7 @@ type2stat(Stat *stat, char *wname, Qid *dir)
break;
case FsFclass:
if(dir_type == FsDclient) {
f = tag[dir_i1]->area[dir_i2]->frame[dir_i3];
f = view[dir_i1]->area[dir_i2]->frame[dir_i3];
return mkstat(stat, dir, wname, strlen(f->client->classinst), DMREAD);
}
else
@ -525,7 +525,7 @@ type2stat(Stat *stat, char *wname, Qid *dir)
break;
case FsFname:
if(dir_type == FsDclient) {
f = tag[dir_i1]->area[dir_i2]->frame[dir_i3];
f = view[dir_i1]->area[dir_i2]->frame[dir_i3];
return mkstat(stat, dir, wname, strlen(f->client->name), DMREAD);
}
else
@ -534,7 +534,7 @@ type2stat(Stat *stat, char *wname, Qid *dir)
case FsFtags:
switch(dir_type) {
case FsDclient:
f = tag[dir_i1]->area[dir_i2]->frame[dir_i3];
f = view[dir_i1]->area[dir_i2]->frame[dir_i3];
tags2str(buf, sizeof(buf), f->client->tag, f->client->ntag);
return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE);
break;
@ -563,7 +563,7 @@ type2stat(Stat *stat, char *wname, Qid *dir)
return mkstat(stat, dir, wname, (dir_i1 == nlabel) ? 0 : strlen(label[dir_i1]->data), DMREAD | DMWRITE);
break;
case FsFmode:
return mkstat(stat, dir, wname, strlen(mode2str(tag[dir_i1]->area[dir_i2]->mode)), DMREAD | DMWRITE);
return mkstat(stat, dir, wname, strlen(mode2str(view[dir_i1]->area[dir_i2]->mode)), DMREAD | DMWRITE);
break;
case FsFcolors:
case FsFselcolors:
@ -792,11 +792,11 @@ xread(IXPConn *c, Fcall *fcall)
case FsDview:
/* jump to offset */
len = type2stat(&stat, "tag", &m->qid);
if(ntag) {
if(nview) {
len += type2stat(&stat, "ctl", &m->qid);
if(tag[i1]->narea)
if(view[i1]->narea)
len += type2stat(&stat, "sel", &m->qid);
for(i = 0; i < tag[i1]->narea; i++) {
for(i = 0; i < view[i1]->narea; i++) {
snprintf(buf, sizeof(buf), "%u", i);
len += type2stat(&stat, buf, &m->qid);
if(len <= fcall->offset)
@ -804,7 +804,7 @@ xread(IXPConn *c, Fcall *fcall)
break;
}
/* offset found, proceeding */
for(; i < tag[i1]->narea; i++) {
for(; i < view[i1]->narea; i++) {
snprintf(buf, sizeof(buf), "%u", i);
len = type2stat(&stat, buf, &m->qid);
if(fcall->count + len > fcall->iounit)
@ -819,9 +819,9 @@ xread(IXPConn *c, Fcall *fcall)
len = type2stat(&stat, "ctl", &m->qid);
if(i2)
len += type2stat(&stat, "mode", &m->qid);
if(tag[i1]->area[i2]->nframe)
if(view[i1]->area[i2]->nframe)
len += type2stat(&stat, "sel", &m->qid);
for(i = 0; i < tag[i1]->area[i2]->nframe; i++) {
for(i = 0; i < view[i1]->area[i2]->nframe; i++) {
snprintf(buf, sizeof(buf), "%u", i);
len += type2stat(&stat, buf, &m->qid);
if(len <= fcall->offset)
@ -829,7 +829,7 @@ xread(IXPConn *c, Fcall *fcall)
break;
}
/* offset found, proceeding */
for(; i < tag[i1]->area[i2]->nframe; i++) {
for(; i < view[i1]->area[i2]->nframe; i++) {
snprintf(buf, sizeof(buf), "%u", i);
len = type2stat(&stat, buf, &m->qid);
if(fcall->count + len > fcall->iounit)
@ -972,14 +972,14 @@ xread(IXPConn *c, Fcall *fcall)
case FsDview:
fcall->count = type2stat(&stat, "tag", &m->qid);
p = ixp_enc_stat(p, &stat);
if(ntag) {
if(nview) {
fcall->count += type2stat(&stat, "ctl", &m->qid);
p = ixp_enc_stat(p, &stat);
if(tag[i1]->narea) {
if(view[i1]->narea) {
fcall->count += type2stat(&stat, "sel", &m->qid);
p = ixp_enc_stat(p, &stat);
}
for(i = 0; i < tag[i1]->narea; i++) {
for(i = 0; i < view[i1]->narea; i++) {
snprintf(buf, sizeof(buf), "%u", i);
len = type2stat(&stat, buf, &m->qid);
if(fcall->count + len > fcall->iounit)
@ -996,11 +996,11 @@ xread(IXPConn *c, Fcall *fcall)
fcall->count += type2stat(&stat, "mode", &m->qid);
p = ixp_enc_stat(p, &stat);
}
if(tag[i1]->area[i2]->nframe) {
if(view[i1]->area[i2]->nframe) {
fcall->count += type2stat(&stat, "sel", &m->qid);
p = ixp_enc_stat(p, &stat);
}
for(i = 0; i < tag[i1]->area[i2]->nframe; i++) {
for(i = 0; i < view[i1]->area[i2]->nframe; i++) {
snprintf(buf, sizeof(buf), "%u", i);
len = type2stat(&stat, buf, &m->qid);
if(fcall->count + len > fcall->iounit)
@ -1037,7 +1037,7 @@ xread(IXPConn *c, Fcall *fcall)
break;
case FsFgeom:
if(m->qid.dir_type == FsDclient) {
f = tag[i1]->area[i2]->frame[i3];
f = view[i1]->area[i2]->frame[i3];
snprintf(buf, sizeof(buf), "%d %d %d %d", f->rect.x, f->rect.y,
f->rect.width, f->rect.height);
}
@ -1056,8 +1056,8 @@ xread(IXPConn *c, Fcall *fcall)
break;
case FsFclass:
if(m->qid.dir_type == FsDclient) {
if((fcall->count = strlen(tag[i1]->area[i2]->frame[i3]->client->classinst)))
memcpy(p, tag[i1]->area[i2]->frame[i3]->client->classinst, fcall->count);
if((fcall->count = strlen(view[i1]->area[i2]->frame[i3]->client->classinst)))
memcpy(p, view[i1]->area[i2]->frame[i3]->client->classinst, fcall->count);
}
else {
if((fcall->count = strlen(client[i1]->classinst)))
@ -1066,8 +1066,8 @@ xread(IXPConn *c, Fcall *fcall)
break;
case FsFname:
if(m->qid.dir_type == FsDclient) {
if((fcall->count = strlen(tag[i1]->area[i2]->frame[i3]->client->name)))
memcpy(p, tag[i1]->area[i2]->frame[i3]->client->name, fcall->count);
if((fcall->count = strlen(view[i1]->area[i2]->frame[i3]->client->name)))
memcpy(p, view[i1]->area[i2]->frame[i3]->client->name, fcall->count);
}
else {
if((fcall->count = strlen(client[i1]->name)))
@ -1078,7 +1078,7 @@ xread(IXPConn *c, Fcall *fcall)
switch(m->qid.dir_type) {
case FsDclient:
{
Client *c = tag[i1]->area[i2]->frame[i3]->client;
Client *c = view[i1]->area[i2]->frame[i3]->client;
tags2str(buf, sizeof(buf), c->tag, c->ntag);
if((fcall->count = strlen(buf)))
memcpy(p, buf, fcall->count);
@ -1154,7 +1154,7 @@ xread(IXPConn *c, Fcall *fcall)
case FsFmode:
if(!i2)
return Enofile;
snprintf(buf, sizeof(buf), "%s", mode2str(tag[i1]->area[i2]->mode));
snprintf(buf, sizeof(buf), "%s", mode2str(view[i1]->area[i2]->mode));
fcall->count = strlen(buf);
memcpy(p, buf, fcall->count);
break;
@ -1190,7 +1190,7 @@ draw_clients()
unsigned int i, j;
for(i = 0; i < nclient; i++)
for(j = 0; j < client[i]->nframe; j++)
if(client[i]->frame[j]->area->tag == tag[sel])
if(client[i]->frame[j]->area->view == view[sel])
draw_client(client[i]);
}
@ -1227,18 +1227,18 @@ xwrite(IXPConn *c, Fcall *fcall)
break;
case FsDview:
if(!strncmp(buf, "select ", 7))
if(ntag)
select_area(tag[i1]->area[tag[i1]->sel], &buf[7]);
if(nview)
select_area(view[i1]->area[view[i1]->sel], &buf[7]);
break;
case FsDarea:
if(!strncmp(buf, "select ", 7)) {
Area *a = tag[i1]->area[i2];
Area *a = view[i1]->area[i2];
if(a->nframe)
select_client(a->frame[a->sel]->client, &buf[7]);
}
break;
case FsDclient:
f = tag[i1]->area[i2]->frame[i3];
f = view[i1]->area[i2]->frame[i3];
if(!strncmp(buf, "kill", 5))
kill_client(f->client);
else if(!strncmp(buf, "sendto ", 7))
@ -1283,7 +1283,7 @@ xwrite(IXPConn *c, Fcall *fcall)
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
if(m->qid.dir_type == FsDclient) {
f = tag[i1]->area[i2]->frame[i3];
f = view[i1]->area[i2]->frame[i3];
f->client->ntag = str2tags(f->client->tag, buf);
}
else
@ -1296,7 +1296,7 @@ xwrite(IXPConn *c, Fcall *fcall)
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
if(m->qid.dir_type == FsDclient) {
f = tag[i1]->area[i2]->frame[i3];
f = view[i1]->area[i2]->frame[i3];
blitz_strtorect(&rect, &f->rect, buf);
if(i2)
resize_area(f->client, &f->rect, nil);
@ -1396,8 +1396,8 @@ xwrite(IXPConn *c, Fcall *fcall)
buf[fcall->count] = 0;
if((i = str2mode(buf)) == -1)
return Ebadvalue;
tag[i1]->area[i2]->mode = i;
arrange_area(tag[i1]->area[i2]);
view[i1]->area[i2]->mode = i;
arrange_area(view[i1]->area[i2]);
break;
case FsFevent:
if(fcall->count > sizeof(buf))

View File

@ -182,14 +182,14 @@ emulate_key_press(unsigned long mod, KeyCode key)
}
static Key **
match_keys(Key **t, unsigned int n, unsigned long mod, KeyCode keycode, Bool next, unsigned int *nres)
match_keys(Key **keys, unsigned int n, unsigned long mod, KeyCode keycode, Bool next, unsigned int *nres)
{
Key **result = nil;
unsigned int ressz = 0;
unsigned int i = 0;
*nres = 0;
for(i = 0; i < n; i++) {
Key *k = next ? t[i]->next : t[i];
Key *k = next ? keys[i]->next : keys[i];
if(k && (k->mod == mod) && (k->key == keycode)) {
result = (Key **)cext_array_attach((void **)result, k, sizeof(Key *), &ressz);
(*nres)++;

View File

@ -244,7 +244,7 @@ mouse_move(Client *c)
int snaph = rect.height * def.snap / 1000;
unsigned int num;
unsigned int dmask;
XRectangle *rects = rectangles(c->frame[c->sel]->area->tag,
XRectangle *rects = rectangles(c->frame[c->sel]->area->view,
area2index(c->frame[c->sel]->area) == 0, &num);
XRectangle frect = c->frame[c->sel]->rect;
XPoint pt;
@ -493,7 +493,7 @@ mouse_resize(Client *c, Align align)
int snaph = rect.height * def.snap / 1000;
unsigned int dmask;
unsigned int num;
XRectangle *rects = rectangles(c->frame[c->sel]->area->tag,
XRectangle *rects = rectangles(c->frame[c->sel]->area->view,
area2index(c->frame[c->sel]->area) == 0, &num);
XRectangle frect = c->frame[c->sel]->rect;
XRectangle origin = frect;

View File

@ -10,7 +10,7 @@
#include "wm.h"
static Bool
Bool
istag(char **tags, unsigned int ntags, char *tag)
{
unsigned int i;
@ -20,238 +20,28 @@ istag(char **tags, unsigned int ntags, char *tag)
return False;
}
Tag *
alloc_tag(char *name)
{
static unsigned short id = 1;
Tag *t = cext_emallocz(sizeof(Tag));
t->id = id++;
t->ntag = str2tags(t->tag, name);
alloc_area(t);
alloc_area(t);
tag = (Tag **)cext_array_attach((void **)tag, t, sizeof(Tag *), &tagsz);
ntag++;
focus_tag(t);
return t;
}
static void
destroy_tag(Tag *t)
{
while(t->narea)
destroy_area(t->area[0]);
cext_array_detach((void **)tag, t, &tagsz);
ntag--;
if(sel >= ntag)
sel = 0;
free(t);
}
int
tag2index(Tag *t)
{
int i;
for(i = 0; i < ntag; i++)
if(t == tag[i])
return i;
return -1;
}
static void
update_frame_selectors(Tag *t)
{
unsigned int i, j;
/* select correct frames of clients */
for(i = 0; i < nclient; i++)
for(j = 0; j < client[i]->nframe; j++)
if(client[i]->frame[j]->area->tag == t)
client[i]->sel = j;
}
void
focus_tag(Tag *t)
{
char buf[256];
char name[256];
unsigned int i;
if(!ntag)
return;
XGrabServer(dpy);
sel = tag2index(t);
update_frame_selectors(t);
/* gives all(!) clients proper geometry (for use of different tags) */
for(i = 0; i < nclient; i++)
if(client[i]->nframe) {
Frame *f = client[i]->frame[client[i]->sel];
if(f->area->tag == t) {
XMoveWindow(dpy, client[i]->framewin, f->rect.x, f->rect.y);
if(client[i]->nframe > 1)
resize_client(client[i], &f->rect, False);
draw_client(client[i]);
}
else
XMoveWindow(dpy, client[i]->framewin, 2 * rect.width + f->rect.x, f->rect.y);
}
tags2str(name, sizeof(name), t->tag, t->ntag);
snprintf(buf, sizeof(buf), "FocusTag %s\n", name);
write_event(buf, True);
XSync(dpy, False);
XUngrabServer(dpy);
}
XRectangle *
rectangles(Tag *t, Bool isfloat, unsigned int *num)
{
XRectangle *result = nil;
unsigned int i;
*num = 0;
if(isfloat)
*num = t->area[0]->nframe;
else {
for(i = 1; i < t->narea; i++)
*num += t->area[i]->nframe;
}
if(*num) {
result = cext_emallocz(*num * sizeof(XRectangle));
if(isfloat) {
for(i = 0; i < *num; i++)
result[i] = t->area[0]->frame[0]->rect;
}
else {
unsigned int j, n = 0;
for(i = 1; i < t->narea; i++) {
for(j = 0; j < t->area[i]->nframe; j++)
result[n++] = t->area[i]->frame[j]->rect;
}
}
}
return result;
}
int
tid2index(unsigned short id)
{
int i;
for(i = 0; i < ntag; i++)
if(tag[i]->id == id)
return i;
return -1;
}
Tag *
get_tag(char *name)
{
unsigned int i, j, ntags;
Tag *t = nil;
char tname[256];
char tags[MAX_TAGS][MAX_TAGLEN];
for(i = 0; i < ntag; i++) {
t = tag[i];
tags2str(tname, sizeof(tname), t->tag, t->ntag);
if(!strncmp(tname, name, strlen(name)))
return t;
}
ntags = str2tags(tags, name);
for(i = 0; i < nclient; i++)
for(j = 0; j < ntags; j++)
if(clienthastag(client[i], tags[j]))
goto Createtag;
return nil;
Createtag:
t = alloc_tag(name);
for(i = 0; i < nclient; i++)
for(j = 0; j < ntags; j++)
if(clienthastag(client[i], tags[j]) && !clientoftag(t, client[i]))
attach_totag(t, client[i]);
return t;
}
static Bool
hasclient(Tag *t)
{
unsigned int i;
for(i = 0; i < t->narea; i++)
if(t->area[i]->nframe)
return True;
return False;
}
void
select_tag(char *arg)
{
int i;
Client *c;
Tag *t = get_tag(arg);
if(!t)
return;
cext_strlcpy(def.tag, arg, sizeof(def.tag));
if(!istag(ctag, nctag, arg)) {
char buf[256];
ctag = (char **)cext_array_attach((void **)ctag, strdup(arg),
sizeof(char *), &ctagsz);
nctag++;
snprintf(buf, sizeof(buf), "NewTag %s\n", arg);
write_event(buf, True);
}
focus_tag(t);
/* cleanup on select */
for(i = 0; i < ntag; i++)
if(!hasclient(tag[i])) {
destroy_tag(tag[i]);
i--;
}
if((c = sel_client_of_tag(t)))
focus_client(c);
}
Bool
clientoftag(Tag *t, Client *c)
{
unsigned int i;
for(i = 0; i < t->narea; i++)
if(clientofarea(t->area[i], c))
return True;
return False;
}
static void
organize_client(Tag *t, Client *c)
organize_client(View *v, Client *c)
{
unsigned int i;
Bool hastag = False;
for(i = 0; i < t->ntag; i++) {
if(clienthastag(c, t->tag[i]))
for(i = 0; i < v->ntag; i++) {
if(clienthastag(c, v->tag[i]))
hastag = True;
break;
}
if(hastag) {
if(!clientoftag(t, c)) {
if(!clientoftag(v, c)) {
/*fprintf(stderr, "org attach %s?\n", c->name);*/
attach_totag(t, c);
attach_totag(v, c);
}
}
else {
if(clientoftag(t, c)) {
if(clientoftag(v, c)) {
/*fprintf(stderr, "org detach %s?\n", c->name);*/
detach_fromtag(t, c);
detach_fromtag(v, c);
}
}
}
@ -276,9 +66,9 @@ update_tags()
}
}
for(i = 0; i < ntag; i++)
if(hasclient(tag[i])) {
tags2str(buf, sizeof(buf), tag[i]->tag, tag[i]->ntag);
for(i = 0; i < nview; i++)
if(hasclient(view[i])) {
tags2str(buf, sizeof(buf), view[i]->tag, view[i]->ntag);
if(!istag(newctag, nnewctag, buf)) {
newctag = (char **)cext_array_attach((void **)newctag, strdup(buf),
sizeof(char *), &newctagsz);
@ -305,91 +95,20 @@ update_tags()
nctag = nnewctag;
ctagsz = newctagsz;
for(i = 0; ntag && (i < nclient); i++) {
for(j = 0; j < ntag; j++) {
Tag *t = tag[j];
for(i = 0; nview && (i < nclient); i++) {
for(j = 0; j < nview; j++) {
View *v = view[j];
if(j == sel)
continue;
organize_client(t, client[i]);
organize_client(v, client[i]);
}
organize_client(tag[sel], client[i]);
organize_client(view[sel], client[i]);
}
if(!ntag && nctag)
if(!nview && nctag)
select_tag(ctag[0]);
}
void
detach_fromtag(Tag *t, Client *c)
{
int i;
Client *cl;
for(i = 0; i < t->narea; i++) {
if(clientofarea(t->area[i], c)) {
detach_fromarea(t->area[i], c);
XMoveWindow(dpy, c->framewin, 2 * rect.width, 0);
}
}
if((cl = sel_client_of_tag(t)))
focus_client(cl);
}
void
attach_totag(Tag *t, Client *c)
{
Area *a;
if(c->trans || clienthastag(c, "~"))
a = t->area[0];
else
a = t->area[t->sel];
attach_toarea(a, c);
map_client(c);
XMapWindow(dpy, c->framewin);
if(t == tag[sel])
focus_client(c);
}
Client *
sel_client_of_tag(Tag *t)
{
if(t) {
Area *a = t->narea ? t->area[t->sel] : nil;
return (a && a->nframe) ? a->frame[a->sel]->client : nil;
}
return nil;
}
void
restack_tag(Tag *t)
{
unsigned int i, j, n = 0;
static Window *wins = nil;
static unsigned int winssz = 0;
if(nclient > winssz) {
winssz = 2 * nclient;
free(wins);
wins = cext_emallocz(sizeof(Window) * winssz);
}
for(i = 0; i < t->narea; i++) {
Area *a = t->area[i];
if(a->nframe) {
wins[n++] = a->frame[a->sel]->client->framewin;
for(j = 0; j < a->nframe; j++) {
if(j == a->sel)
continue;
wins[n++] = a->frame[j]->client->framewin;
}
}
}
if(n)
XRestackWindows(dpy, wins, n);
}
unsigned int
str2tags(char tags[MAX_TAGS][MAX_TAGLEN], const char *stags)
{

292
cmd/wm/view.c Normal file
View File

@ -0,0 +1,292 @@
/*
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xatom.h>
#include "wm.h"
View *
alloc_tag(char *name)
{
static unsigned short id = 1;
View *v = cext_emallocz(sizeof(View));
v->id = id++;
v->ntag = str2tags(v->tag, name);
alloc_area(v);
alloc_area(v);
view = (View **)cext_array_attach((void **)view, v, sizeof(View *), &viewsz);
nview++;
focus_tag(v);
return v;
}
static void
destroy_tag(View *v)
{
while(v->narea)
destroy_area(v->area[0]);
cext_array_detach((void **)view, v, &viewsz);
nview--;
if(sel >= nview)
sel = 0;
free(v);
}
int
tag2index(View *v)
{
int i;
for(i = 0; i < nview; i++)
if(v == view[i])
return i;
return -1;
}
static void
update_frame_selectors(View *v)
{
unsigned int i, j;
/* select correct frames of clients */
for(i = 0; i < nclient; i++)
for(j = 0; j < client[i]->nframe; j++)
if(client[i]->frame[j]->area->view == v)
client[i]->sel = j;
}
void
focus_tag(View *v)
{
char buf[256];
char name[256];
unsigned int i;
if(!nview)
return;
XGrabServer(dpy);
sel = tag2index(v);
update_frame_selectors(v);
/* gives all(!) clients proper geometry (for use of different tags) */
for(i = 0; i < nclient; i++)
if(client[i]->nframe) {
Frame *f = client[i]->frame[client[i]->sel];
if(f->area->view == v) {
XMoveWindow(dpy, client[i]->framewin, f->rect.x, f->rect.y);
if(client[i]->nframe > 1)
resize_client(client[i], &f->rect, False);
draw_client(client[i]);
}
else
XMoveWindow(dpy, client[i]->framewin, 2 * rect.width + f->rect.x, f->rect.y);
}
tags2str(name, sizeof(name), v->tag, v->ntag);
snprintf(buf, sizeof(buf), "FocusTag %s\n", name);
write_event(buf, True);
XSync(dpy, False);
XUngrabServer(dpy);
}
XRectangle *
rectangles(View *v, Bool isfloat, unsigned int *num)
{
XRectangle *result = nil;
unsigned int i;
*num = 0;
if(isfloat)
*num = v->area[0]->nframe;
else {
for(i = 1; i < v->narea; i++)
*num += v->area[i]->nframe;
}
if(*num) {
result = cext_emallocz(*num * sizeof(XRectangle));
if(isfloat) {
for(i = 0; i < *num; i++)
result[i] = v->area[0]->frame[0]->rect;
}
else {
unsigned int j, n = 0;
for(i = 1; i < v->narea; i++) {
for(j = 0; j < v->area[i]->nframe; j++)
result[n++] = v->area[i]->frame[j]->rect;
}
}
}
return result;
}
int
tid2index(unsigned short id)
{
int i;
for(i = 0; i < nview; i++)
if(view[i]->id == id)
return i;
return -1;
}
View *
get_tag(char *name)
{
unsigned int i, j, ntags;
View *v = nil;
char vname[256];
char tags[MAX_TAGS][MAX_TAGLEN];
for(i = 0; i < nview; i++) {
v = view[i];
tags2str(vname, sizeof(vname), v->tag, v->ntag);
if(!strncmp(vname, name, strlen(name)))
return v;
}
ntags = str2tags(tags, name);
for(i = 0; i < nclient; i++)
for(j = 0; j < ntags; j++)
if(clienthastag(client[i], tags[j]))
goto Createtag;
return nil;
Createtag:
v = alloc_tag(name);
for(i = 0; i < nclient; i++)
for(j = 0; j < ntags; j++)
if(clienthastag(client[i], tags[j]) && !clientoftag(v, client[i]))
attach_totag(v, client[i]);
return v;
}
Bool
hasclient(View *v)
{
unsigned int i;
for(i = 0; i < v->narea; i++)
if(v->area[i]->nframe)
return True;
return False;
}
void
select_tag(char *arg)
{
int i;
Client *c;
View *v = get_tag(arg);
if(!v)
return;
cext_strlcpy(def.tag, arg, sizeof(def.tag));
if(!istag(ctag, nctag, arg)) {
char buf[256];
ctag = (char **)cext_array_attach((void **)ctag, strdup(arg),
sizeof(char *), &ctagsz);
nctag++;
snprintf(buf, sizeof(buf), "NewTag %s\n", arg);
write_event(buf, True);
}
focus_tag(v);
/* cleanup on select */
for(i = 0; i < nview; i++)
if(!hasclient(view[i])) {
destroy_tag(view[i]);
i--;
}
if((c = sel_client_of_tag(v)))
focus_client(c);
}
Bool
clientoftag(View *v, Client *c)
{
unsigned int i;
for(i = 0; i < v->narea; i++)
if(clientofarea(v->area[i], c))
return True;
return False;
}
void
detach_fromtag(View *v, Client *c)
{
int i;
Client *cl;
for(i = 0; i < v->narea; i++) {
if(clientofarea(v->area[i], c)) {
detach_fromarea(v->area[i], c);
XMoveWindow(dpy, c->framewin, 2 * rect.width, 0);
}
}
if((cl = sel_client_of_tag(v)))
focus_client(cl);
}
void
attach_totag(View *v, Client *c)
{
Area *a;
if(c->trans || clienthastag(c, "~"))
a = v->area[0];
else
a = v->area[v->sel];
attach_toarea(a, c);
map_client(c);
XMapWindow(dpy, c->framewin);
if(v == view[sel])
focus_client(c);
}
Client *
sel_client_of_tag(View *v)
{
if(v) {
Area *a = v->narea ? v->area[v->sel] : nil;
return (a && a->nframe) ? a->frame[a->sel]->client : nil;
}
return nil;
}
void
restack_tag(View *v)
{
unsigned int i, j, n = 0;
static Window *wins = nil;
static unsigned int winssz = 0;
if(nclient > winssz) {
winssz = 2 * nclient;
free(wins);
wins = cext_emallocz(sizeof(Window) * winssz);
}
for(i = 0; i < v->narea; i++) {
Area *a = v->area[i];
if(a->nframe) {
wins[n++] = a->frame[a->sel]->client->framewin;
for(j = 0; j < a->nframe; j++) {
if(j == a->sel)
continue;
wins[n++] = a->frame[j]->client->framewin;
}
}
}
if(n)
XRestackWindows(dpy, wins, n);
}

View File

@ -296,8 +296,8 @@ main(int argc, char *argv[])
ixp_server_open_conn(&srv, ConnectionNumber(dpy), check_x_event, nil);
init_x_event_handler();
nctag = ctagsz = ntag = nclient = tagsz = clientsz = sel = 0;
tag = nil;
nctag = ctagsz = nview = nclient = viewsz = clientsz = sel = 0;
view = nil;
ctag = nil;
client = nil;

View File

@ -75,12 +75,12 @@ enum {
#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask)
#define WM_PROTOCOL_DELWIN 1
typedef struct Tag Tag;
typedef struct View View;
typedef struct Area Area;
typedef struct Frame Frame;
typedef struct Client Client;
struct Tag {
struct View {
char tag[MAX_TAGS][MAX_TAGLEN];
unsigned int ntag;
unsigned short id;
@ -94,7 +94,7 @@ struct Tag {
struct Area {
unsigned short id;
Frame **frame;
Tag *tag;
View *view;
unsigned int framesz;
unsigned int sel;
unsigned int nframe;
@ -166,9 +166,9 @@ typedef struct {
} Default;
/* global variables */
Tag **tag;
unsigned int ntag;
unsigned int tagsz;
View **view;
unsigned int nview;
unsigned int viewsz;
unsigned int sel;
Client **client;
unsigned int nclient;
@ -205,15 +205,15 @@ Cursor cursor[CurLast];
unsigned int valid_mask, num_lock_mask;
/* area.c */
Area *alloc_area(Tag *t);
Area *alloc_area(View *t);
void destroy_area(Area *a);
int area2index(Area *a);
int aid2index(Tag *t, unsigned short id);
int aid2index(View *t, unsigned short id);
void select_area(Area *a, char *arg);
void send2area(Area *to, Area *from, Client *c);
void attach_toarea(Area *a, Client *c);
void detach_fromarea(Area *a, Client *c);
void arrange_tag(Tag *t, Bool updategeometry);
void arrange_tag(View *t, Bool updategeometry);
void arrange_area(Area *a);
void resize_area(Client *c, XRectangle *r, XPoint *pt);
int str2mode(char *arg);
@ -284,21 +284,25 @@ void ungrab_mouse(Window w, unsigned long mod, unsigned int button);
void match_tags(Client *c);
/* tag.c */
Tag *alloc_tag(char *name);
void focus_tag(Tag *t);
XRectangle *rectangles(Tag *t, Bool isfloat, unsigned int *num);
int tid2index(unsigned short id);
void select_tag(char *arg);
int tag2index(Tag *t);
void update_tags();
Bool clientoftag(Tag *t, Client *c);
void detach_fromtag(Tag *t, Client *c);
void attach_totag(Tag *t, Client *c);
Client *sel_client_of_tag(Tag *t);
void restack_tag(Tag *t);
unsigned int str2tags(char tags[MAX_TAGS][MAX_TAGLEN], const char *stags);
void tags2str(char *stags, unsigned int stagsz,
char tags[MAX_TAGS][MAX_TAGLEN], unsigned int ntags);
Bool istag(char **tags, unsigned int ntags, char *tag);
void update_tags();
/* view */
View *alloc_tag(char *name);
void focus_tag(View *v);
XRectangle *rectangles(View *v, Bool isfloat, unsigned int *num);
int tid2index(unsigned short id);
void select_tag(char *arg);
int tag2index(View *v);
Bool clientoftag(View *v, Client *c);
void detach_fromtag(View *v, Client *c);
void attach_totag(View *v, Client *c);
Client *sel_client_of_tag(View *v);
void restack_tag(View *v);
Bool hasclient(View *v);
/* wm.c */
void scan_wins();