From 03cb248e711a127a5804e797c74c699c9ae2206b Mon Sep 17 00:00:00 2001 From: "Anselm R. Garbe" Date: Sun, 2 Apr 2006 22:53:56 +0200 Subject: [PATCH] applied the changes made by Icarus Sparry --- cmd/wm/Makefile | 2 + cmd/wm/area.c | 191 +++++++++++++++++++++-------------------- cmd/wm/bar.c | 87 ++++++++++--------- cmd/wm/client.c | 142 +++++++++++++++--------------- cmd/wm/event.c | 22 ++--- cmd/wm/frame.c | 14 +-- cmd/wm/fs.c | 218 +++++++++++++++++++++++------------------------ cmd/wm/kb.c | 28 +++--- cmd/wm/mouse.c | 16 ++-- cmd/wm/rule.c | 3 +- cmd/wm/tag.c | 61 +++++++------ cmd/wm/view.c | 141 +++++++++++++++--------------- cmd/wm/wm.c | 30 +++---- cmd/wm/wm.h | 49 +++++------ config.mk | 6 +- libcext/Makefile | 4 +- libcext/cext.h | 12 +++ 17 files changed, 541 insertions(+), 485 deletions(-) diff --git a/cmd/wm/Makefile b/cmd/wm/Makefile index a0d9ac88..951c9217 100644 --- a/cmd/wm/Makefile +++ b/cmd/wm/Makefile @@ -19,6 +19,8 @@ all: wmiiwm @echo CC $< @${CC} -c ${CFLAGS} $< +${OBJ}: wm.h + wmiiwm: ${OBJ} @echo LD $@ @${CC} -o $@ ${OBJ} ${LDFLAGS} diff --git a/cmd/wm/area.c b/cmd/wm/area.c index a251a66e..f976fa78 100644 --- a/cmd/wm/area.c +++ b/cmd/wm/area.c @@ -8,6 +8,14 @@ #include "wm.h" +/* We expect the optimiser to remove this function, It is included to ensure type safeness. + */ +static evector_t * +area_to_evector(area_vec_t *view) +{ + return (evector_t *) view; +} + Area * alloc_area(View *v) { @@ -17,10 +25,8 @@ alloc_area(View *v) a->id = id++; a->rect = rect; a->rect.height = rect.height - brect.height; - v->area = (Area **)cext_array_attach((void **)v->area, a, - sizeof(Area *), &v->areasz); - v->sel = v->narea; - v->narea++; + cext_evector_attach(area_to_evector(&v->area), a); + v->sel = v->area.size -1; return a; } @@ -29,17 +35,16 @@ destroy_area(Area *a) { unsigned int i; View *v = a->view; - if(a->nframe) + if(a->frame.size) return; - if(a->frame) - free(a->frame); + if(a->frame.data) + free(a->frame.data); 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 **)v->area, a, &v->areasz); - v->narea--; + for(i = 0; i < client.size; i++) + if(client.data[i]->revert == a) + client.data[i]->revert = 0; + cext_evector_detach(area_to_evector(&v->area), a); if(v->sel > 1) v->sel--; free(a); @@ -50,8 +55,8 @@ area2index(Area *a) { int i; View *v = a->view; - for(i = 0; i < v->narea; i++) - if(v->area[i] == a) + for(i = 0; i < v->area.size; i++) + if(v->area.data[i] == a) return i; return -1; } @@ -60,8 +65,8 @@ int aid2index(View *v, unsigned short id) { int i; - for(i = 0; i < v->narea; i++) - if(v->area[i]->id == id) + for(i = 0; i < v->area.size; i++) + if(v->area.data[i]->id == id) return i; return -1; } @@ -81,20 +86,20 @@ select_area(Area *a, char *arg) if(!strncmp(arg, "toggle", 7)) { if(i) i = 0; - else if(v->revert > 0 && v->revert < v->narea) + else if(v->revert > 0 && v->revert < v->area.size) i = v->revert; else i = 1; } else if(!strncmp(arg, "prev", 5)) { if(i > 0) { if(i == 1) - i = v->narea - 1; + i = v->area.size - 1; else i--; } } else if(!strncmp(arg, "next", 5)) { if(i > 0) { - if(i + 1 < v->narea) + if(i + 1 < v->area.size) i++; else i = 1; @@ -102,18 +107,18 @@ select_area(Area *a, char *arg) } else { const char *errstr; - i = cext_strtonum(arg, 0, v->narea - 1, &errstr); + i = cext_strtonum(arg, 0, v->area.size - 1, &errstr); if(errstr) return; } - new = v->area[i]; - if(new->nframe) - focus_client(new->frame[new->sel]->client); + new = v->area.data[i]; + if(new->frame.size) + focus_client(new->frame.data[new->sel]->client); v->sel = i; - for(i = 0; i < a->nframe; i++) - draw_client(a->frame[i]->client); + for(i = 0; i < a->frame.size; i++) + draw_client(a->frame.data[i]->client); - if(!new->nframe) { + if(!new->frame.size) { update_view_label(v); draw_bar(); } @@ -128,6 +133,14 @@ send2area(Area *to, Area *from, Client *c) focus_client(c); } +/* We expect the optimiser to remove this function, It is included to ensure type safeness. + */ +static evector_t * +frame_to_evector(frame_vec_t *view) +{ + return (evector_t *) view; +} + void attach_toarea(Area *a, Client *c) { @@ -144,14 +157,10 @@ attach_toarea(Area *a, Client *c) f->rect = c->rect; f->rect.width += 2 * def.border; f->rect.height += def.border + bar_height(); - c->frame = (Frame **)cext_array_attach( - (void **)c->frame, f, sizeof(Frame *), &c->framesz); - c->nframe++; - c->sel = c->nframe - 1; - a->frame = (Frame **)cext_array_attach( - (void **)a->frame, f, sizeof(Frame *), &a->framesz); - a->nframe++; - a->sel = a->nframe - 1; + cext_evector_attach(frame_to_evector(&c->frame), f); + c->sel = c->frame.size - 1; + cext_evector_attach(frame_to_evector(&a->frame),f); + a->sel = a->frame.size - 1; if(area2index(a)) /* column */ arrange_column(a); else /* floating */ @@ -161,48 +170,46 @@ attach_toarea(Area *a, Client *c) void detach_fromarea(Area *a, Client *c) { - Frame *f; + Frame *f = nil; View *v = a->view; int i; - for(i = 0; i < c->nframe; i++) - if(c->frame[i]->area == a) { - f = c->frame[i]; + for(i = 0; i < c->frame.size; i++) + if(c->frame.data[i]->area == a) { + f = c->frame.data[i]; break; } - cext_array_detach((void **)c->frame, f, &c->framesz); - cext_array_detach((void **)a->frame, f, &a->framesz); + cext_evector_detach(frame_to_evector(&c->frame), f); + cext_evector_detach(frame_to_evector(&a->frame), f); free(f); - c->nframe--; if(c->sel > 0) c->sel--; - a->nframe--; if(a->sel > 0) a->sel--; i = area2index(a); - if(i && a->nframe) + if(i && a->frame.size) arrange_column(a); else { if(i) { - if(v->narea > 2) + if(v->area.size > 2) destroy_area(a); - else if(!a->nframe && v->area[0]->nframe) + else if(!a->frame.size && v->area.data[0]->frame.size) v->sel = 0; /* focus floating area if it contains something */ arrange_view(v, True); } - else if(!i && !a->nframe) { + else if(!i && !a->frame.size) { if(c->trans) { /* focus area of transient, if possible */ Client *cl = win2client(c->trans); - if(cl && cl->nframe) { - a = cl->frame[cl->sel]->area; + if(cl && cl->frame.size) { + a = cl->frame.data[cl->sel]->area; if(a->view == v) v->sel = area2index(a); } } - else if(v->area[1]->nframe) + else if(v->area.data[1]->frame.size) v->sel = 1; /* focus first col as fallback */ } } @@ -238,19 +245,19 @@ relax_area(Area *a) unsigned int i, yoff, h, hdiff; Bool fallthrough = False; - if(!a->nframe) + if(!a->frame.size) return; switch(a->mode) { case Colequal: h = a->rect.height; - h /= a->nframe; + h /= a->frame.size; if(h < 2 * bar_height()) fallthrough = True; break; case Colstack: yoff = a->rect.y; - h = a->rect.height - (a->nframe - 1) * bar_height(); + h = a->rect.height - (a->frame.size - 1) * bar_height(); if(h < 3 * bar_height()) fallthrough = True; break; @@ -259,8 +266,8 @@ relax_area(Area *a) } if(fallthrough) { - for(i = 0; i < a->nframe; i++) { - Frame *f = a->frame[i]; + for(i = 0; i < a->frame.size; i++) { + Frame *f = a->frame.data[i]; f->rect.x = a->rect.x + (a->rect.width - f->rect.width) / 2; f->rect.y = a->rect.y + (a->rect.height - f->rect.height) / 2; resize_client(f->client, &f->rect, False); @@ -270,8 +277,8 @@ relax_area(Area *a) /* some relaxing from potential increment gaps */ h = 0; - for(i = 0; i < a->nframe; i++) { - Frame *f = a->frame[i]; + for(i = 0; i < a->frame.size; i++) { + Frame *f = a->frame.data[i]; if(a->mode == Colmax) { if(h < f->rect.height) h = f->rect.height; @@ -282,8 +289,8 @@ relax_area(Area *a) /* try to add rest space to all clients if not COL_STACK mode */ if(a->mode != Colstack) { - for(i = 0; (h < a->rect.height) && (i < a->nframe); i++) { - Frame *f = a->frame[i]; + for(i = 0; (h < a->rect.height) && (i < a->frame.size); i++) { + Frame *f = a->frame.data[i]; unsigned int tmp = f->rect.height; f->rect.height += (a->rect.height - h); resize_client(f->client, &f->rect, True); @@ -291,10 +298,10 @@ relax_area(Area *a) } } - hdiff = (a->rect.height - h) / a->nframe; + hdiff = (a->rect.height - h) / a->frame.size; yoff = a->rect.y + hdiff / 2; - for(i = 0; i < a->nframe; i++) { - Frame *f = a->frame[i]; + for(i = 0; i < a->frame.size; i++) { + Frame *f = a->frame.data[i]; f->rect.x = a->rect.x + (a->rect.width - f->rect.width) / 2; f->rect.y = yoff; if(a->mode != Colmax) @@ -308,20 +315,20 @@ arrange_column(Area *a) { unsigned int i, yoff, h; - if(!a->nframe) + if(!a->frame.size) return; switch(a->mode) { case Colequal: h = a->rect.height; - h /= a->nframe; + h /= a->frame.size; if(h < 2 * bar_height()) goto Fallthrough; - for(i = 0; i < a->nframe; i++) { - Frame *f = a->frame[i]; + for(i = 0; i < a->frame.size; i++) { + Frame *f = a->frame.data[i]; f->rect = a->rect; f->rect.y += i * h; - if(i + 1 < a->nframe) + if(i + 1 < a->frame.size) f->rect.height = h; else f->rect.height = @@ -331,11 +338,11 @@ arrange_column(Area *a) break; case Colstack: yoff = a->rect.y; - h = a->rect.height - (a->nframe - 1) * bar_height(); + h = a->rect.height - (a->frame.size - 1) * bar_height(); if(h < 3 * bar_height()) goto Fallthrough; - for(i = 0; i < a->nframe; i++) { - Frame *f = a->frame[i]; + for(i = 0; i < a->frame.size; i++) { + Frame *f = a->frame.data[i]; f->rect = a->rect; f->rect.y = yoff; if(i == a->sel) @@ -348,8 +355,8 @@ arrange_column(Area *a) break; Fallthrough: case Colmax: - for(i = 0; i < a->nframe; i++) { - Frame *f = a->frame[i]; + for(i = 0; i < a->frame.size; i++) { + Frame *f = a->frame.data[i]; f->rect = a->rect; resize_client(f->client, &f->rect, True); } @@ -366,8 +373,8 @@ match_horiz(Area *a, XRectangle *r) { unsigned int i; - for(i = 0; i < a->nframe; i++) { - Frame *f = a->frame[i]; + for(i = 0; i < a->frame.size; i++) { + Frame *f = a->frame.data[i]; f->rect.x = r->x; f->rect.width = r->width; resize_client(f->client, &f->rect, False); @@ -384,14 +391,14 @@ drop_resize(Frame *f, XRectangle *new) unsigned int i; unsigned int min_height = 2 * bar_height(); - for(i = 1; (i < v->narea) && (v->area[i] != a); i++); + for(i = 1; (i < v->area.size) && (v->area.data[i] != a); i++); /* first managed area is indexed 1, thus (i > 1) ? ... */ - west = (i > 1) ? v->area[i - 1] : nil; - east = i + 1 < v->narea ? v->area[i + 1] : nil; + west = (i > 1) ? v->area.data[i - 1] : nil; + east = i + 1 < v->area.size ? v->area.data[i + 1] : nil; - for(i = 0; (i < a->nframe) && (a->frame[i] != f); i++); - north = i ? a->frame[i - 1] : nil; - south = i + 1 < a->nframe ? a->frame[i + 1] : nil; + for(i = 0; (i < a->frame.size) && (a->frame.data[i] != f); i++); + north = i ? a->frame.data[i - 1] : nil; + south = i + 1 < a->frame.size ? a->frame.data[i + 1] : nil; /* validate (and trim if necessary) horizontal resize */ if(new->width < MIN_COLWIDTH) { @@ -487,22 +494,22 @@ drop_moving(Frame *f, XRectangle *new, XPoint * pt) View *v = src->view; unsigned int i; - if(!pt || src->nframe < 2) + if(!pt || src->frame.size < 2) return; - 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))) { + for(i = 1; (i < v->area.size) && + !blitz_ispointinrect(pt->x, pt->y, &v->area.data[i]->rect); i++); + if((tgt = ((i < v->area.size) ? v->area.data[i] : nil))) { if(tgt != src) send2area(tgt, src, f->client); else { - 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])) { + for(i = 0; (i < src->frame.size) && !blitz_ispointinrect( + pt->x, pt->y, &src->frame.data[i]->rect); i++); + if((i < src->frame.size) && (f != src->frame.data[i])) { unsigned int j = frame2index(f); - Frame *tmp = src->frame[j]; - src->frame[j] = src->frame[i]; - src->frame[i] = tmp; + Frame *tmp = src->frame.data[j]; + src->frame.data[j] = src->frame.data[i]; + src->frame.data[i] = tmp; arrange_column(src); focus_client(f->client); } @@ -513,7 +520,7 @@ drop_moving(Frame *f, XRectangle *new, XPoint * pt) void resize_area(Client *c, XRectangle *r, XPoint *pt) { - Frame *f = c->frame[c->sel]; + Frame *f = c->frame.data[c->sel]; if((f->rect.width == r->width) && (f->rect.height == r->height)) drop_moving(f, r, pt); else @@ -524,8 +531,8 @@ Bool clientofarea(Area *a, Client *c) { unsigned int i; - for(i = 0; i < a->nframe; i++) - if(a->frame[i]->client == c) + for(i = 0; i < a->frame.size; i++) + if(a->frame.data[i]->client == c) return True; return False; } diff --git a/cmd/wm/bar.c b/cmd/wm/bar.c index 969cc20c..d9fdb61c 100644 --- a/cmd/wm/bar.c +++ b/cmd/wm/bar.c @@ -42,6 +42,14 @@ comp_label_name(const void *l1, const void *l2) return strcmp(ll1->name, ll2->name); } +/* We expect the optimiser to remove this function, It is included to ensure type safeness. + */ +static evector_t * +label_to_evector(label_vec_t *view) +{ + return (evector_t *) view; +} + Label * get_label(char *name, Bool intern) { @@ -56,11 +64,9 @@ get_label(char *name, Bool intern) cext_strlcpy(l->name, name, sizeof(l->name)); cext_strlcpy(l->colstr, def.selcolor, sizeof(l->colstr)); l->color = def.sel; - label = (Label **)cext_array_attach((void **)label, l, - sizeof(Label *), &labelsz); - nlabel++; - qsort(label, nlabel, sizeof(Label *), comp_label_name); - qsort(label, nlabel, sizeof(Label *), comp_label_intern); + cext_evector_attach(label_to_evector(&label), l); + qsort(label.data, label.size, sizeof(Label *), comp_label_name); + qsort(label.data, label.size, sizeof(Label *), comp_label_intern); return l; } @@ -68,8 +74,7 @@ get_label(char *name, Bool intern) void destroy_label(Label *l) { - cext_array_detach((void **)label, l, &labelsz); - nlabel--; + cext_evector_detach(label_to_evector(&label), l); } unsigned int @@ -92,14 +97,14 @@ update_bar_geometry() DefaultDepth(dpy, screen)); XSync(dpy, False); draw_bar(); - for(i = 0; i < nview; i++) { - for(j = 1; j < view[i]->narea; j++) { - Area *a = view[i]->area[j]; + for(i = 0; i < view.size; i++) { + for(j = 1; j < view.data[i]->area.size; j++) { + Area *a = view.data[i]->area.data[j]; a->rect.height = rect.height - brect.height; arrange_column(a); } - for(j = 0; j < view[i]->area[0]->nframe; j++) { - Frame *f = view[i]->area[0]->frame[j]; + for(j = 0; j < view.data[i]->area.data[0]->frame.size; j++) { + Frame *f = view.data[i]->area.data[0]->frame.data[j]; resize_client(f->client, &f->rect, False); } } @@ -123,13 +128,13 @@ draw_bar() blitz_drawlabel(dpy, &d); blitz_drawborder(dpy, &d); - if(!nlabel) + if(!label.size) return; - for(i = 0; (i < nlabel) && (w < brect.width); i++) { - l = label[i]; + for(i = 0; (i < label.size) && (w < brect.width); i++) { + l = label.data[i]; if(l->intern) { - if(nview && !strncmp(l->name, def.tag, sizeof(l->name))) + if(view.size && !strncmp(l->name, def.tag, sizeof(l->name))) l->color = def.sel; else l->color = def.norm; @@ -143,26 +148,26 @@ draw_bar() w += l->rect.width; } - if(i != nlabel) { /* give all labels same width */ - w = brect.width / nlabel; - for(i = 0; i < nlabel; i++) { - l = label[i]; + if(i != label.size) { /* give all labels same width */ + w = brect.width / label.size; + for(i = 0; i < label.size; i++) { + l = label.data[i]; l->rect.x = i * w; l->rect.width = w; } } else { /* expand label properly */ - for(exp = 0; (exp < nlabel) && (label[exp]->intern); exp++); - if(exp == nlabel) + for(exp = 0; (exp < label.size) && (label.data[exp]->intern); exp++); + if(exp == label.size) exp = -1; else - label[exp]->rect.width += (brect.width - w); - for(i = 1; i < nlabel; i++) - label[i]->rect.x = label[i - 1]->rect.x + label[i - 1]->rect.width; + label.data[exp]->rect.width += (brect.width - w); + for(i = 1; i < label.size; i++) + label.data[i]->rect.x = label.data[i - 1]->rect.x + label.data[i - 1]->rect.width; } - for(i = 0; i < nlabel; i++) { - l = label[i]; + for(i = 0; i < label.size; i++) { + l = label.data[i]; d.color = l->color; d.rect = l->rect; d.data = l->data; @@ -181,8 +186,8 @@ int label2index(Label *l) { int i; - for(i = 0; i < nlabel; i++) - if(label[i] == l) + for(i = 0; i < label.size; i++) + if(label.data[i] == l) return i; return -1; } @@ -191,8 +196,8 @@ int lid2index(unsigned short id) { int i; - for(i = 0; i < nlabel; i++) - if(label[i]->id == id) + for(i = 0; i < label.size; i++) + if(label.data[i]->id == id) return i; return -1; } @@ -204,9 +209,9 @@ name2label(const char *name) unsigned int i; cext_strlcpy(buf, name, sizeof(buf)); - for(i = 0; i < nlabel; i++) - if(!strncmp(label[i]->name, name, sizeof(label[i]->name))) - return label[i]; + for(i = 0; i < label.size; i++) + if(!strncmp(label.data[i]->name, name, sizeof(label.data[i]->name))) + return label.data[i]; return nil; } @@ -216,19 +221,19 @@ update_bar_tags() unsigned int i; Label *l = nil; - for(i = 0; (i < nlabel) && label[i]->intern; i++) { - l = label[i]; + for(i = 0; (i < label.size) && label.data[i]->intern; i++) { + l = label.data[i]; if(!istag(l->name) && !name2view(l->name)) { destroy_label(l); i--; } } - for(i = 0; i < ntag; i++) { - l = get_label(tag[i], True); - cext_strlcpy(l->data, tag[i], sizeof(l->data)); + for(i = 0; i < tag.size; i++) { + l = get_label(tag.data[i], True); + cext_strlcpy(l->data, tag.data[i], sizeof(l->data)); } - for(i = 0; i < nview; i++) - update_view_label(view[i]); + for(i = 0; i < view.size; i++) + update_view_label(view.data[i]); draw_bar(); } diff --git a/cmd/wm/client.c b/cmd/wm/client.c index 4c6324f1..3358ea67 100644 --- a/cmd/wm/client.c +++ b/cmd/wm/client.c @@ -12,6 +12,14 @@ #define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask) +/* We expect the optimiser to remove this function, It is included to ensure type safeness. + */ +static evector_t * +client_to_evector(client_vec_t *view) +{ + return (evector_t *) view; +} + Client * alloc_client(Window w, XWindowAttributes *wa) { @@ -59,10 +67,7 @@ alloc_client(Window w, XWindowAttributes *wa) CWOverrideRedirect | CWBackPixmap | CWEventMask, &fwa); c->gc = XCreateGC(dpy, c->framewin, 0, 0); XSync(dpy, False); - client = (Client **)cext_array_attach((void **)client, c, - sizeof(Client *), &clientsz); - nclient++; - + cext_evector_attach(client_to_evector(&client), c); return c; } @@ -81,7 +86,7 @@ void focus_client(Client *c) { Client *old = sel_client(); - Frame *f = c->frame[c->sel]; + Frame *f = c->frame.data[c->sel]; View *v = f->area->view; int i = area2index(f->area); @@ -137,7 +142,7 @@ void configure_client(Client *c) { XConfigureEvent e; - Frame *f = c->frame[c->sel]; + Frame *f = c->frame.data[c->sel]; e.type = ConfigureNotify; e.event = c->win; e.window = c->win; @@ -200,7 +205,7 @@ update_client_property(Client *c, XPropertyEvent *e) cext_strlcpy(c->name, (char*) name.value, sizeof(c->name)); free(name.value); } - if(c->nframe) + if(c->frame.size) draw_client(c); break; case XA_WM_TRANSIENT_FOR: @@ -221,7 +226,7 @@ draw_client(Client *c) Draw d = { 0 }; char buf[512]; - if(!c->nframe) + if(!c->frame.size) return; /* might not have been attached atm */ d.drawable = c->framewin; @@ -235,7 +240,7 @@ draw_client(Client *c) /* draw border */ if(def.border) { - d.rect = c->frame[c->sel]->rect; + d.rect = c->frame.data[c->sel]->rect; d.rect.x = d.rect.y = 0; d.notch = &c->rect; blitz_drawlabel(dpy, &d); @@ -249,12 +254,12 @@ draw_client(Client *c) tags2str(buf, sizeof(buf), c->tag, c->ntag); d.align = WEST; d.rect.x = d.rect.height + XTextWidth(xfont, buf, strlen(buf)); - d.rect.width = c->frame[c->sel]->rect.width - d.rect.x; + d.rect.width = c->frame.data[c->sel]->rect.width - d.rect.x; d.data = c->name; blitz_drawlabel(dpy, &d); blitz_drawborder(dpy, &d); - if(c->frame[c->sel]->area->mode == Colmax) { + if(c->frame.data[c->sel]->area->mode == Colmax) { /* invert tag label */ unsigned long tmp = d.color.fg; d.color.fg = d.color.bg; @@ -349,7 +354,7 @@ manage_client(Client *c) reparent_client(c, c->framewin, c->rect.x, c->rect.y); - v = nview ? view[sel] : alloc_view(def.tag); + v = view.size ? view.data[sel] : alloc_view(def.tag); if(!c->ntag) { for(i = 0; i < v->ntag; i++) { cext_strlcpy(c->tag[i], v->tag[i], sizeof(c->tag[i])); @@ -375,25 +380,24 @@ destroy_client(Client *c) XGrabServer(dpy); XSetErrorHandler(dummy_error_handler); - for(i = 0; i < nview; i++) - detach_fromview(view[i], c); + for(i = 0; i < view.size; i++) + detach_fromview(view.data[i], c); unmap_client(c); - if(c->nframe) { - c->rect.x = c->frame[c->sel]->rect.x; - c->rect.y = c->frame[c->sel]->rect.y; + if(c->frame.size) { + c->rect.x = c->frame.data[c->sel]->rect.x; + c->rect.y = c->frame.data[c->sel]->rect.y; } reparent_client(c, root, c->rect.x, c->rect.y); XFreeGC(dpy, c->gc); XDestroyWindow(dpy, c->framewin); - cext_array_detach((void **)client, c, &clientsz); - nclient--; + cext_evector_detach(client_to_evector(&client), c); update_tags(); free(c); - if((cl = sel_client_of_view(view[sel]))) + if((cl = sel_client_of_view(view.data[sel]))) focus_client(cl); XSync(dpy, False); @@ -404,7 +408,7 @@ destroy_client(Client *c) Client * sel_client() { - return nview ? sel_client_of_view(view[sel]) : nil; + return view.size ? sel_client_of_view(view.data[sel]) : nil; } static void @@ -437,27 +441,27 @@ match_sizehints(Client *c) h = c->size.min_height; } /* client_width = base_width + i * c->size.width_inc for an integer i */ - w = c->frame[c->sel]->rect.width - 2 * def.border - w; + w = c->frame.data[c->sel]->rect.width - 2 * def.border - w; if(s->width_inc > 0) - c->frame[c->sel]->rect.width -= w % s->width_inc; + c->frame.data[c->sel]->rect.width -= w % s->width_inc; - h = c->frame[c->sel]->rect.height - def.border - bar_height() - h; + h = c->frame.data[c->sel]->rect.height - def.border - bar_height() - h; if(s->height_inc > 0) - c->frame[c->sel]->rect.height -= h % s->height_inc; + c->frame.data[c->sel]->rect.height -= h % s->height_inc; } } void resize_client(Client *c, XRectangle *r, Bool ignore_xcall) { - Frame *f = c->frame[c->sel]; + Frame *f = c->frame.data[c->sel]; f->rect = *r; if((f->area->mode != Colstack) || (f->area->sel == frame2index(f))) match_sizehints(c); if(!ignore_xcall) { - if(f->area->view == view[sel]) + if(f->area->view == view.data[sel]) XMoveResizeWindow(dpy, c->framewin, f->rect.x, f->rect.y, f->rect.width, f->rect.height); else @@ -479,35 +483,35 @@ resize_client(Client *c, XRectangle *r, Bool ignore_xcall) void select_client(Client *c, char *arg) { - Frame *f = c->frame[c->sel]; + Frame *f = c->frame.data[c->sel]; Area *a = f->area; int i = frame2index(f); if(i == -1) return; if(!strncmp(arg, "prev", 5)) { if(!i) - i = a->nframe - 1; + i = a->frame.size - 1; else i--; } else if(!strncmp(arg, "next", 5)) { - if(i + 1 < a->nframe) + if(i + 1 < a->frame.size) i++; else i = 0; } else { const char *errstr; - i = cext_strtonum(arg, 0, a->nframe - 1, &errstr); + i = cext_strtonum(arg, 0, a->frame.size - 1, &errstr); if(errstr) return; } - focus_client(a->frame[i]->client); + focus_client(a->frame.data[i]->client); } void swap_client(Client *c, char *arg) { - Frame *f = c->frame[c->sel]; + Frame *f = c->frame.data[c->sel]; Area *o, *a = f->area; View *v = a->view; int i = area2index(a), j = frame2index(f); @@ -517,22 +521,22 @@ swap_client(Client *c, char *arg) if(!strncmp(arg, "prev", 5) && i) { if(i == 1) - o = v->area[v->narea - 1]; + o = v->area.data[v->area.size - 1]; else - o = v->area[i - 1]; + o = v->area.data[i - 1]; goto Swaparea; } else if(!strncmp(arg, "next", 5) && i) { - if(i < v->narea - 1) - o = v->area[i + 1]; + if(i < v->area.size - 1) + o = v->area.data[i + 1]; else - o = v->area[1]; + o = v->area.data[1]; Swaparea: if(o == a) return; - a->frame[j] = o->frame[o->sel]; - a->frame[j]->area = a; - o->frame[o->sel] = f; + a->frame.data[j] = o->frame.data[o->sel]; + a->frame.data[j]->area = a; + o->frame.data[o->sel] = f; f->area = o; arrange_column(o); } @@ -540,17 +544,17 @@ Swaparea: if(j) i = j - 1; else - i = a->nframe - 1; - a->frame[j] = a->frame[i]; - a->frame[i] = f; + i = a->frame.size - 1; + a->frame.data[j] = a->frame.data[i]; + a->frame.data[i] = f; } else if(!strncmp(arg, "down", 5) && i) { - if(j + 1 < a->nframe) + if(j + 1 < a->frame.size) i = j + 1; else i = 0; - a->frame[j] = a->frame[i]; - a->frame[i] = f; + a->frame.data[j] = a->frame.data[i]; + a->frame.data[i] = f; } if(area2index(a)) arrange_column(a); @@ -561,7 +565,7 @@ void send2area_client(Client *c, char *arg) { const char *errstr; - Frame *f = c->frame[c->sel]; + Frame *f = c->frame.data[c->sel]; Area *to, *a = f->area; View *v = a->view; int i = area2index(a); @@ -569,36 +573,36 @@ send2area_client(Client *c, char *arg) if(i == -1) return; if(!strncmp(arg, "new", 4) && i) { - if(a->nframe == 1 || v->narea - 1 >= rect.width / MIN_COLWIDTH) + if(a->frame.size == 1 || v->area.size - 1 >= rect.width / MIN_COLWIDTH) return; to = alloc_area(v); arrange_view(v, True); } else if(!strncmp(arg, "prev", 5) && i) { if(i == 1) - to = v->area[v->narea - 1]; + to = v->area.data[v->area.size - 1]; else - to = v->area[i - 1]; + to = v->area.data[i - 1]; } else if(!strncmp(arg, "next", 5) && i) { - if(i < v->narea - 1) - to = v->area[i + 1]; + if(i < v->area.size - 1) + to = v->area.data[i + 1]; else - to = v->area[1]; + to = v->area.data[1]; } else if(!strncmp(arg, "toggle", 7)) { if(i) - to = v->area[0]; - else if(c->revert && c->revert != v->area[0]) + to = v->area.data[0]; + else if(c->revert && c->revert != v->area.data[0]) to = c->revert; else - to = v->area[1]; + to = v->area.data[1]; } else { - i = cext_strtonum(arg, 0, v->narea - 1, &errstr); + i = cext_strtonum(arg, 0, v->area.size - 1, &errstr); if(errstr) return; - to = v->area[i]; + to = v->area.data[i]; } send2area(to, a, c); } @@ -607,13 +611,13 @@ void resize_all_clients() { unsigned int i; - for(i = 0; i < nclient; i++) { - Client *c = client[i]; - if(c->nframe && c->frame[c->sel]->area) { - if(area2index(c->frame[c->sel]->area)) - resize_area(c, &c->frame[c->sel]->rect, nil); + for(i = 0; i < client.size; i++) { + Client *c = client.data[i]; + if(c->frame.size && c->frame.data[c->sel]->area) { + if(area2index(c->frame.data[c->sel]->area)) + resize_area(c, &c->frame.data[c->sel]->rect, nil); else - resize_client(c, &c->frame[c->sel]->rect, False); + resize_client(c, &c->frame.data[c->sel]->rect, False); } } } @@ -622,14 +626,14 @@ resize_all_clients() void focus(Client *c) { - Frame *f = c->nframe ? c->frame[c->sel] : nil; + Frame *f = c->frame.size ? c->frame.data[c->sel] : nil; View *v; if(!f) return; v = f->area->view; - if(view[sel] != v) + if(view.data[sel] != v) focus_view(v); focus_client(c); } @@ -638,8 +642,8 @@ int cid2index(unsigned short id) { int i; - for(i = 0; i < nclient; i++) - if(client[i]->id == id) + for(i = 0; i < client.size; i++) + if(client.data[i]->id == id) return i; return -1; } diff --git a/cmd/wm/event.c b/cmd/wm/event.c index 99632acd..26f3297d 100644 --- a/cmd/wm/event.c +++ b/cmd/wm/event.c @@ -60,10 +60,10 @@ handle_buttonpress(XEvent *e) static char buf[32]; if(ev->window == barwin) { unsigned int i; - for(i = 0; i < nlabel; i++) - if(blitz_ispointinrect(ev->x, ev->y, &label[i]->rect)) { + for(i = 0; i < label.size; i++) + if(blitz_ispointinrect(ev->x, ev->y, &label.data[i]->rect)) { snprintf(buf, sizeof(buf), "LabelClick %s %d\n", - label[i]->name, ev->button); + label.data[i]->name, ev->button); write_event(buf); return; } @@ -85,9 +85,9 @@ handle_buttonpress(XEvent *e) else mouse_move(c); } - if(c->nframe) { + if(c->frame.size) { snprintf(buf, sizeof(buf), "ClientClick %d %d\n", - frame2index(c->frame[c->sel]) + 1, ev->button); + frame2index(c->frame.data[c->sel]) + 1, ev->button); write_event(buf); } } @@ -106,7 +106,7 @@ handle_configurerequest(XEvent *e) if(c) { gravitate(c, True); - if(c->nframe && (area2index(c->frame[c->sel]->area) == 0)) { + if(c->frame.size && (area2index(c->frame.data[c->sel]->area) == 0)) { if(ev->value_mask & CWX) c->rect.x = ev->x; if(ev->value_mask & CWY) @@ -121,8 +121,8 @@ handle_configurerequest(XEvent *e) gravitate(c, False); - if(c->nframe) { - Frame *f = c->frame[c->sel]; + if(c->frame.size) { + Frame *f = c->frame.data[c->sel]; f->rect.x = wc.x = c->rect.x - def.border; f->rect.y = wc.y = c->rect.y - bar_height(); f->rect.width = wc.width = c->rect.width + 2 * def.border; @@ -131,7 +131,7 @@ handle_configurerequest(XEvent *e) wc.border_width = 1; wc.sibling = None; wc.stack_mode = ev->detail; - if(f->area->view != view[sel]) + if(f->area->view != view.data[sel]) f->rect.x += 2 * rect.width; XConfigureWindow(dpy, c->framewin, ev->value_mask, &wc); configure_client(c); @@ -143,10 +143,10 @@ handle_configurerequest(XEvent *e) wc.width = ev->width; wc.height = ev->height; - if(c && c->nframe) { + if(c && c->frame.size) { wc.x = def.border; wc.y = bar_height(); - if(area2index(c->frame[c->sel]->area) > 0) { + if(area2index(c->frame.data[c->sel]->area) > 0) { wc.width = c->rect.width; wc.height = c->rect.height; } diff --git a/cmd/wm/frame.c b/cmd/wm/frame.c index 932d46f2..8525d037 100644 --- a/cmd/wm/frame.c +++ b/cmd/wm/frame.c @@ -9,8 +9,8 @@ int frid2index(Area *a, unsigned short id) { int i; - for(i = 0; i < a->nframe; i++) - if(a->frame[i]->id == id) + for(i = 0; i < a->frame.size; i++) + if(a->frame.data[i]->id == id) return i; return -1; } @@ -20,8 +20,8 @@ frame2index(Frame *f) { int i; Area *a = f->area; - for(i = 0; i < a->nframe; i++) - if(a->frame[i] == f) + for(i = 0; i < a->frame.size; i++) + if(a->frame.data[i] == f) return i; return -1; } @@ -30,8 +30,8 @@ Client * win2clientframe(Window w) { unsigned int i; - for(i = 0; (i < clientsz) && client[i]; i++) - if(client[i]->framewin == w) - return client[i]; + for(i = 0; (i < client.size) && client.data[i]; i++) + if(client.data[i]->framewin == w) + return client.data[i]; return nil; } diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c index 78853e56..8a659a3d 100644 --- a/cmd/wm/fs.c +++ b/cmd/wm/fs.c @@ -126,9 +126,9 @@ decode_qpath(Qid *qid, unsigned char *type, int *i1, int *i2, int *i3) } } if(i2id && (*i1 != -1)) { - *i2 = aid2index(view[*i1], i2id); + *i2 = aid2index(view.data[*i1], i2id); if(i3id && (*i2 != -1)) - *i3 = frid2index(view[*i1]->area[*i2], i3id); + *i3 = frid2index(view.data[*i1]->area.data[*i2], i3id); } } } @@ -155,12 +155,12 @@ qid2name(Qid *qid) case FsDlabel: if(i1 == -1) return nil; - return label[i1]->name; + return label.data[i1]->name; break; case FsDarea: if(i1 == -1 || i2 == -1) return nil; - if(view[i1]->sel == i2) + if(view.data[i1]->sel == i2) return "sel"; snprintf(buf, sizeof(buf), "%u", i2); return buf; @@ -174,7 +174,7 @@ qid2name(Qid *qid) case FsDclient: if(i1 == -1 || i2 == -1 || i3 == -1) return nil; - if(view[i1]->area[i2]->sel == i3) + if(view.data[i1]->area.data[i2]->sel == i3) return "sel"; snprintf(buf, sizeof(buf), "%u", i3); return buf; @@ -317,22 +317,22 @@ mkqid(Qid *dir, char *wname, Qid *new) break; case FsDview: new->type = IXP_QTDIR; - new->path = mkqpath(FsDview, nview ? view[sel]->id : 0, 0, 0); + new->path = mkqpath(FsDview, view.size ? view.data[sel]->id : 0, 0, 0); break; case FsDarea: if(dir_i1 == -1 || dir_type != FsDview) return -1; { - View *p = view[dir_i1]; + View *p = view.data[dir_i1]; new->type = IXP_QTDIR; if(!strncmp(wname, "sel", 4)) { - new->path = mkqpath(FsDarea, p->id, p->area[p->sel]->id, 0); + new->path = mkqpath(FsDarea, p->id, p->area.data[p->sel]->id, 0); } else { i = cext_strtonum(wname, 0, 0xffff, &err); - if(err || (i >= p->narea)) + if(err || (i >= p->area.size)) return -1; - new->path = mkqpath(FsDarea, p->id, p->area[i]->id, 0); + new->path = mkqpath(FsDarea, p->id, p->area.data[i]->id, 0); } } break; @@ -340,19 +340,19 @@ mkqid(Qid *dir, char *wname, Qid *new) if(dir_i1 == -1 || dir_i2 == -1 || dir_type != FsDarea) return -1; { - View *p = view[dir_i1]; - Area *a = p->area[dir_i2]; + View *p = view.data[dir_i1]; + Area *a = p->area.data[dir_i2]; new->type = IXP_QTDIR; if(!strncmp(wname, "sel", 4)) { - if(!a->nframe) + if(!a->frame.size) return -1; - new->path = mkqpath(FsDclient, p->id, a->id, a->frame[a->sel]->id); + new->path = mkqpath(FsDclient, p->id, a->id, a->frame.data[a->sel]->id); } else { i = cext_strtonum(wname, 0, 0xffff, &err); - if(err || (i >= a->nframe)) + if(err || (i >= a->frame.size)) return -1; - new->path = mkqpath(FsDclient, p->id, a->id, a->frame[i]->id); + new->path = mkqpath(FsDclient, p->id, a->id, a->frame.data[i]->id); } } break; @@ -360,9 +360,9 @@ mkqid(Qid *dir, char *wname, Qid *new) if(dir_type != FsDclients) return -1; i = cext_strtonum(wname, 0, 0xffff, &err); - if(err || (i >= nclient)) + if(err || (i >= client.size)) return -1; - new->path = mkqpath(FsDGclient, client[i]->id, 0, 0); + new->path = mkqpath(FsDGclient, client.data[i]->id, 0, 0); break; case FsDlabel: if(dir_type != FsDbar) @@ -481,12 +481,12 @@ type2stat(Stat *stat, char *wname, Qid *dir) break; case FsFgeom: if(dir_type == FsDclient) { - f = view[dir_i1]->area[dir_i2]->frame[dir_i3]; + f = view.data[dir_i1]->area.data[dir_i2]->frame.data[dir_i3]; snprintf(buf, sizeof(buf), "%d %d %d %d", f->rect.x, f->rect.y, f->rect.width, f->rect.height); } else { - Client *c = client[dir_i1]; + Client *c = client.data[dir_i1]; snprintf(buf, sizeof(buf), "%d %d %d %d", c->rect.x, c->rect.y, c->rect.width, c->rect.height); } @@ -494,36 +494,36 @@ type2stat(Stat *stat, char *wname, Qid *dir) break; case FsFclass: if(dir_type == FsDclient) { - f = view[dir_i1]->area[dir_i2]->frame[dir_i3]; + f = view.data[dir_i1]->area.data[dir_i2]->frame.data[dir_i3]; return mkstat(stat, dir, wname, strlen(f->client->classinst), DMREAD); } else - return mkstat(stat, dir, wname, strlen(client[dir_i1]->classinst), DMREAD); + return mkstat(stat, dir, wname, strlen(client.data[dir_i1]->classinst), DMREAD); break; case FsFname: if(dir_type == FsDclient) { - f = view[dir_i1]->area[dir_i2]->frame[dir_i3]; + f = view.data[dir_i1]->area.data[dir_i2]->frame.data[dir_i3]; return mkstat(stat, dir, wname, strlen(f->client->name), DMREAD); } else - return mkstat(stat, dir, wname, strlen(client[dir_i1]->name), DMREAD); + return mkstat(stat, dir, wname, strlen(client.data[dir_i1]->name), DMREAD); break; case FsFtags: switch(dir_type) { case FsDclient: - f = view[dir_i1]->area[dir_i2]->frame[dir_i3]; + f = view.data[dir_i1]->area.data[dir_i2]->frame.data[dir_i3]; tags2str(buf, sizeof(buf), f->client->tag, f->client->ntag); return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE); break; case FsDGclient: - tags2str(buf, sizeof(buf), client[dir_i1]->tag, client[dir_i1]->ntag); + tags2str(buf, sizeof(buf), client.data[dir_i1]->tag, client.data[dir_i1]->ntag); return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE); break; default: { unsigned int i, len = 0; - for(i = 0; i < ntag; i++) - len += strlen(tag[i]) + 1; + for(i = 0; i < tag.size; i++) + len += strlen(tag.data[i]) + 1; return mkstat(stat, dir, wname, len, DMREAD); } break; @@ -534,10 +534,10 @@ type2stat(Stat *stat, char *wname, Qid *dir) return mkstat(stat, dir, wname, strlen(def.tag), DMREAD); break; case FsFdata: - return mkstat(stat, dir, wname, (dir_i1 == nlabel) ? 0 : strlen(label[dir_i1]->data), DMREAD | DMWRITE); + return mkstat(stat, dir, wname, (dir_i1 == label.size) ? 0 : strlen(label.data[dir_i1]->data), DMREAD | DMWRITE); break; case FsFmode: - return mkstat(stat, dir, wname, strlen(mode2str(view[dir_i1]->area[dir_i2]->mode)), DMREAD | DMWRITE); + return mkstat(stat, dir, wname, strlen(mode2str(view.data[dir_i1]->area.data[dir_i2]->mode)), DMREAD | DMWRITE); break; case FsFcolors: case FsFselcolors: @@ -685,7 +685,7 @@ xremove(IXPConn *c, Fcall *fcall) switch(type) { case FsDlabel: { - Label *l = label[i1]; + Label *l = label.data[i1]; if(l->intern) return Enoperm; /* now detach the label */ @@ -726,7 +726,7 @@ xread(IXPConn *c, Fcall *fcall) case FsDclients: /* jump to offset */ len = 0; - for(i = 0; i < nclient; i++) { + for(i = 0; i < client.size; i++) { snprintf(buf, sizeof(buf), "%u", i); len += type2stat(&stat, buf, &m->qid); if(len <= fcall->offset) @@ -734,7 +734,7 @@ xread(IXPConn *c, Fcall *fcall) break; } /* offset found, proceeding */ - for(; i < nclient; i++) { + for(; i < client.size; i++) { snprintf(buf, sizeof(buf), "%u", i); len = type2stat(&stat, buf, &m->qid); if(fcall->count + len > fcall->iounit) @@ -746,15 +746,15 @@ xread(IXPConn *c, Fcall *fcall) case FsDbar: /* jump to offset */ len = 0; - for(i = 0; i < nlabel; i++) { - len += type2stat(&stat, label[i]->name, &m->qid); + for(i = 0; i < label.size; i++) { + len += type2stat(&stat, label.data[i]->name, &m->qid); if(len <= fcall->offset) continue; break; } /* offset found, proceeding */ - for(; i < nlabel; i++) { - len = type2stat(&stat, label[i]->name, &m->qid); + for(; i < label.size; i++) { + len = type2stat(&stat, label.data[i]->name, &m->qid); if(fcall->count + len > fcall->iounit) break; fcall->count += len; @@ -764,11 +764,11 @@ xread(IXPConn *c, Fcall *fcall) case FsDview: /* jump to offset */ len = type2stat(&stat, "tag", &m->qid); - if(nview) { + if(view.size) { len += type2stat(&stat, "ctl", &m->qid); - if(view[i1]->narea) + if(view.data[i1]->area.size) len += type2stat(&stat, "sel", &m->qid); - for(i = 0; i < view[i1]->narea; i++) { + for(i = 0; i < view.data[i1]->area.size; i++) { snprintf(buf, sizeof(buf), "%u", i); len += type2stat(&stat, buf, &m->qid); if(len <= fcall->offset) @@ -776,7 +776,7 @@ xread(IXPConn *c, Fcall *fcall) break; } /* offset found, proceeding */ - for(; i < view[i1]->narea; i++) { + for(; i < view.data[i1]->area.size; i++) { snprintf(buf, sizeof(buf), "%u", i); len = type2stat(&stat, buf, &m->qid); if(fcall->count + len > fcall->iounit) @@ -791,9 +791,9 @@ xread(IXPConn *c, Fcall *fcall) len = type2stat(&stat, "ctl", &m->qid); if(i2) len += type2stat(&stat, "mode", &m->qid); - if(view[i1]->area[i2]->nframe) + if(view.data[i1]->area.data[i2]->frame.size) len += type2stat(&stat, "sel", &m->qid); - for(i = 0; i < view[i1]->area[i2]->nframe; i++) { + for(i = 0; i < view.data[i1]->area.data[i2]->frame.size; i++) { snprintf(buf, sizeof(buf), "%u", i); len += type2stat(&stat, buf, &m->qid); if(len <= fcall->offset) @@ -801,7 +801,7 @@ xread(IXPConn *c, Fcall *fcall) break; } /* offset found, proceeding */ - for(; i < view[i1]->area[i2]->nframe; i++) { + for(; i < view.data[i1]->area.data[i2]->frame.size; i++) { snprintf(buf, sizeof(buf), "%u", i); len = type2stat(&stat, buf, &m->qid); if(fcall->count + len > fcall->iounit) @@ -847,17 +847,17 @@ xread(IXPConn *c, Fcall *fcall) if(m->qid.dir_type == FsDroot) { len = 0; /* jump to offset */ - for(i = 0; i < ntag; i++) { - len += strlen(tag[i]) + 1; + for(i = 0; i < tag.size; i++) { + len += strlen(tag.data[i]) + 1; if(len <= fcall->offset) continue; } /* offset found, proceeding */ - for(; i < ntag; i++) { - len = strlen(tag[i]) + 1; + for(; i < tag.size; i++) { + len = strlen(tag.data[i]) + 1; if(fcall->count + len > fcall->iounit) break; - memcpy(p + fcall->count, tag[i], len - 1); + memcpy(p + fcall->count, tag.data[i], len - 1); memcpy(p + fcall->count + len - 1, "\n", 1); fcall->count += len; } @@ -878,11 +878,11 @@ xread(IXPConn *c, Fcall *fcall) p = ixp_enc_stat(p, &stat); fcall->count += type2stat(&stat, "bar", &m->qid); p = ixp_enc_stat(p, &stat); - if(ntag) { + if(tag.size) { fcall->count += type2stat(&stat, "tags", &m->qid); p = ixp_enc_stat(p, &stat); } - if(nclient) { + if(client.size) { fcall->count += type2stat(&stat, "clients", &m->qid); p = ixp_enc_stat(p, &stat); } @@ -890,7 +890,7 @@ xread(IXPConn *c, Fcall *fcall) p = ixp_enc_stat(p, &stat); break; case FsDclients: - for(i = 0; i < nclient; i++) { + for(i = 0; i < client.size; i++) { snprintf(buf, sizeof(buf), "%u", i); len = type2stat(&stat, buf, &m->qid); if(fcall->count + len > fcall->iounit) @@ -900,8 +900,8 @@ xread(IXPConn *c, Fcall *fcall) } break; case FsDbar: - for(i = 0; i < nlabel; i++) { - len = type2stat(&stat, label[i]->name, &m->qid); + for(i = 0; i < label.size; i++) { + len = type2stat(&stat, label.data[i]->name, &m->qid); if(fcall->count + len > fcall->iounit) break; fcall->count += len; @@ -909,7 +909,7 @@ xread(IXPConn *c, Fcall *fcall) } break; case FsDlabel: - if(i1 >= nlabel) + if(i1 >= label.size) return Enofile; fcall->count = type2stat(&stat, "colors", &m->qid); p = ixp_enc_stat(p, &stat); @@ -933,14 +933,14 @@ xread(IXPConn *c, Fcall *fcall) case FsDview: fcall->count = type2stat(&stat, "tag", &m->qid); p = ixp_enc_stat(p, &stat); - if(nview) { + if(view.size) { fcall->count += type2stat(&stat, "ctl", &m->qid); p = ixp_enc_stat(p, &stat); - if(view[i1]->narea) { + if(view.data[i1]->area.size) { fcall->count += type2stat(&stat, "sel", &m->qid); p = ixp_enc_stat(p, &stat); } - for(i = 0; i < view[i1]->narea; i++) { + for(i = 0; i < view.data[i1]->area.size; i++) { snprintf(buf, sizeof(buf), "%u", i); len = type2stat(&stat, buf, &m->qid); if(fcall->count + len > fcall->iounit) @@ -957,11 +957,11 @@ xread(IXPConn *c, Fcall *fcall) fcall->count += type2stat(&stat, "mode", &m->qid); p = ixp_enc_stat(p, &stat); } - if(view[i1]->area[i2]->nframe) { + if(view.data[i1]->area.data[i2]->frame.size) { fcall->count += type2stat(&stat, "sel", &m->qid); p = ixp_enc_stat(p, &stat); } - for(i = 0; i < view[i1]->area[i2]->nframe; i++) { + for(i = 0; i < view.data[i1]->area.data[i2]->frame.size; i++) { snprintf(buf, sizeof(buf), "%u", i); len = type2stat(&stat, buf, &m->qid); if(fcall->count + len > fcall->iounit) @@ -998,12 +998,12 @@ xread(IXPConn *c, Fcall *fcall) break; case FsFgeom: if(m->qid.dir_type == FsDclient) { - f = view[i1]->area[i2]->frame[i3]; + f = view.data[i1]->area.data[i2]->frame.data[i3]; snprintf(buf, sizeof(buf), "%d %d %d %d", f->rect.x, f->rect.y, f->rect.width, f->rect.height); } else { - Client *c = client[i1]; + Client *c = client.data[i1]; snprintf(buf, sizeof(buf), "%d %d %d %d", c->rect.x, c->rect.y, c->rect.width, c->rect.height); } @@ -1012,45 +1012,45 @@ xread(IXPConn *c, Fcall *fcall) break; case FsFclass: if(m->qid.dir_type == FsDclient) { - if((fcall->count = strlen(view[i1]->area[i2]->frame[i3]->client->classinst))) - memcpy(p, view[i1]->area[i2]->frame[i3]->client->classinst, fcall->count); + if((fcall->count = strlen(view.data[i1]->area.data[i2]->frame.data[i3]->client->classinst))) + memcpy(p, view.data[i1]->area.data[i2]->frame.data[i3]->client->classinst, fcall->count); } else { - if((fcall->count = strlen(client[i1]->classinst))) - memcpy(p, client[i1]->classinst, fcall->count); + if((fcall->count = strlen(client.data[i1]->classinst))) + memcpy(p, client.data[i1]->classinst, fcall->count); } break; case FsFname: if(m->qid.dir_type == FsDclient) { - if((fcall->count = strlen(view[i1]->area[i2]->frame[i3]->client->name))) - memcpy(p, view[i1]->area[i2]->frame[i3]->client->name, fcall->count); + if((fcall->count = strlen(view.data[i1]->area.data[i2]->frame.data[i3]->client->name))) + memcpy(p, view.data[i1]->area.data[i2]->frame.data[i3]->client->name, fcall->count); } else { - if((fcall->count = strlen(client[i1]->name))) - memcpy(p, client[i1]->name, fcall->count); + if((fcall->count = strlen(client.data[i1]->name))) + memcpy(p, client.data[i1]->name, fcall->count); } break; case FsFtags: switch(m->qid.dir_type) { case FsDclient: { - Client *c = view[i1]->area[i2]->frame[i3]->client; + Client *c = view.data[i1]->area.data[i2]->frame.data[i3]->client; tags2str(buf, sizeof(buf), c->tag, c->ntag); if((fcall->count = strlen(buf))) memcpy(p, buf, fcall->count); } break; case FsDGclient: - tags2str(buf, sizeof(buf), client[i1]->tag, client[i1]->ntag); + tags2str(buf, sizeof(buf), client.data[i1]->tag, client.data[i1]->ntag); if((fcall->count = strlen(buf))) memcpy(p, buf, fcall->count); break; default: - for(i = 0; i < ntag; i++) { - len = strlen(tag[i]) + 1; + for(i = 0; i < tag.size; i++) { + len = strlen(tag.data[i]) + 1; if(fcall->count + len > fcall->iounit) break; - memcpy(p + fcall->count, tag[i], len - 1); + memcpy(p + fcall->count, tag.data[i], len - 1); memcpy(p + fcall->count + len - 1, "\n", 1); fcall->count += len; } @@ -1058,20 +1058,20 @@ xread(IXPConn *c, Fcall *fcall) } break; case FsFdata: - if(i1 >= nlabel) + if(i1 >= label.size) return Enofile; - if((fcall->count = strlen(label[i1]->data))) - memcpy(p, label[i1]->data, fcall->count); + if((fcall->count = strlen(label.data[i1]->data))) + memcpy(p, label.data[i1]->data, fcall->count); break; case FsFtag: if((fcall->count = strlen(def.tag))) memcpy(p, def.tag, fcall->count); break; case FsFcolors: - if(i1 >= nlabel) + if(i1 >= label.size) return Enofile; - if((fcall->count = strlen(label[i1]->colstr))) - memcpy(p, label[i1]->colstr, fcall->count); + if((fcall->count = strlen(label.data[i1]->colstr))) + memcpy(p, label.data[i1]->colstr, fcall->count); break; case FsFselcolors: if((fcall->count = strlen(def.selcolor))) @@ -1106,7 +1106,7 @@ xread(IXPConn *c, Fcall *fcall) case FsFmode: if(!i2) return Enofile; - snprintf(buf, sizeof(buf), "%s", mode2str(view[i1]->area[i2]->mode)); + snprintf(buf, sizeof(buf), "%s", mode2str(view.data[i1]->area.data[i2]->mode)); fcall->count = strlen(buf); memcpy(p, buf, fcall->count); break; @@ -1140,10 +1140,10 @@ static void 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->view == view[sel]) - draw_client(client[i]); + for(i = 0; i < client.size; i++) + for(j = 0; j < client.data[i]->frame.size; j++) + if(client.data[i]->frame.data[j]->area->view == view.data[sel]) + draw_client(client.data[i]); } static char * @@ -1179,18 +1179,18 @@ xwrite(IXPConn *c, Fcall *fcall) break; case FsDview: if(!strncmp(buf, "select ", 7)) - if(nview) - select_area(view[i1]->area[view[i1]->sel], &buf[7]); + if(view.size) + select_area(view.data[i1]->area.data[view.data[i1]->sel], &buf[7]); break; case FsDarea: if(!strncmp(buf, "select ", 7)) { - Area *a = view[i1]->area[i2]; - if(a->nframe) - select_client(a->frame[a->sel]->client, &buf[7]); + Area *a = view.data[i1]->area.data[i2]; + if(a->frame.size) + select_client(a->frame.data[a->sel]->client, &buf[7]); } break; case FsDclient: - f = view[i1]->area[i2]->frame[i3]; + f = view.data[i1]->area.data[i2]->frame.data[i3]; if(!strncmp(buf, "kill", 5)) kill_client(f->client); else if(!strncmp(buf, "sendto ", 7)) @@ -1200,7 +1200,7 @@ xwrite(IXPConn *c, Fcall *fcall) break; case FsDGclient: if(!strncmp(buf, "kill", 5)) - kill_client(client[i1]); + kill_client(client.data[i1]); break; default: break; @@ -1225,13 +1225,13 @@ xwrite(IXPConn *c, Fcall *fcall) memcpy(buf, fcall->data, fcall->count); buf[fcall->count] = 0; if(m->qid.dir_type == FsDclient) { - f = view[i1]->area[i2]->frame[i3]; + f = view.data[i1]->area.data[i2]->frame.data[i3]; f->client->ntag = str2tags(f->client->tag, buf); } else - client[i1]->ntag = str2tags(client[i1]->tag, buf); + client.data[i1]->ntag = str2tags(client.data[i1]->tag, buf); update_tags(); - draw_client(client[i1]); + draw_client(client.data[i1]); break; case FsFgeom: if(fcall->count > sizeof(buf)) @@ -1239,7 +1239,7 @@ xwrite(IXPConn *c, Fcall *fcall) memcpy(buf, fcall->data, fcall->count); buf[fcall->count] = 0; if(m->qid.dir_type == FsDclient) { - f = view[i1]->area[i2]->frame[i3]; + f = view.data[i1]->area.data[i2]->frame.data[i3]; blitz_strtorect(&rect, &f->rect, buf); if(i2) resize_area(f->client, &f->rect, nil); @@ -1249,19 +1249,19 @@ xwrite(IXPConn *c, Fcall *fcall) break; case FsFdata: len = fcall->count; - if(len >= sizeof(label[i1]->data)) - len = sizeof(label[i1]->data) - 1; - memcpy(label[i1]->data, fcall->data, len); - label[i1]->data[len] = 0; + if(len >= sizeof(label.data[i1]->data)) + len = sizeof(label.data[i1]->data) - 1; + memcpy(label.data[i1]->data, fcall->data, len); + label.data[i1]->data[len] = 0; draw_bar(); break; case FsFcolors: - if((i1 >= nlabel) || (fcall->count != 23) || (fcall->data[0] != '#') + if((i1 >= label.size) || (fcall->count != 23) || (fcall->data[0] != '#') || (fcall->data[8] != '#') || (fcall->data[16] != '#')) return Ebadvalue; - memcpy(label[i1]->colstr, fcall->data, fcall->count); - label[i1]->colstr[fcall->count] = 0; - blitz_loadcolor(dpy, screen, label[i1]->colstr, &label[i1]->color); + memcpy(label.data[i1]->colstr, fcall->data, fcall->count); + label.data[i1]->colstr[fcall->count] = 0; + blitz_loadcolor(dpy, screen, label.data[i1]->colstr, &label.data[i1]->color); draw_bar(); break; case FsFselcolors: @@ -1328,10 +1328,10 @@ xwrite(IXPConn *c, Fcall *fcall) buf[fcall->count] = 0; if((i = str2mode(buf)) == -1) return Ebadvalue; - view[i1]->area[i2]->mode = i; - arrange_column(view[i1]->area[i2]); - if(view[i1]->area[i2]->nframe == 1) /* little hack to update the taglabel */ - draw_client(view[i1]->area[i2]->frame[view[i1]->area[i2]->sel]->client); + view.data[i1]->area.data[i2]->mode = i; + arrange_column(view.data[i1]->area.data[i2]); + if(view.data[i1]->area.data[i2]->frame.size == 1) /* little hack to update the taglabel */ + draw_client(view.data[i1]->area.data[i2]->frame.data[view.data[i1]->area.data[i2]->sel]->client); break; case FsFevent: if(fcall->count > sizeof(buf)) diff --git a/cmd/wm/kb.c b/cmd/wm/kb.c index 8b9c03e4..8ea84efe 100644 --- a/cmd/wm/kb.c +++ b/cmd/wm/kb.c @@ -86,12 +86,20 @@ static Key * name2key(const char *name) { unsigned int i; - for(i = 0; i < nkey; i++) - if(!strncmp(key[i]->name, name, sizeof(key[i]->name))) - return key[i]; + for(i = 0; i < key.size; i++) + if(!strncmp(key.data[i]->name, name, sizeof(key.data[i]->name))) + return key.data[i]; return nil; } +/* We expect the optimiser to remove this function, It is included to ensure type safeness. + */ +static evector_t * +key_to_evector(key_vec_t *view) +{ + return (evector_t *) view; +} + static Key * get_key(const char *name) { @@ -128,8 +136,7 @@ get_key(const char *name) } if(r) { r->id = id++; - key = (Key **)cext_array_attach((void **)key, r, sizeof(Key *), &keysz); - nkey++; + cext_evector_attach(key_to_evector(&key), r); } return r; @@ -139,8 +146,7 @@ void destroy_key(Key *k) { Key *n; - cext_array_detach((void **)key, k, &keysz); - nkey--; + cext_evector_detach(key_to_evector(&key), k); while(k) { n = k->next; free(k); @@ -240,7 +246,7 @@ handle_key(Window w, unsigned long mod, KeyCode keycode) { unsigned int nfound; char buf[128]; - Key **found = match_keys(key, nkey, mod, keycode, False, &nfound); + Key **found = match_keys(key.data, key.size, mod, keycode, False, &nfound); switch(nfound) { case 0: XBell(dpy, 0); @@ -269,9 +275,9 @@ update_keys() init_lock_modifiers(); - while(nkey) { - ungrab_key(key[0]); - destroy_key(key[0]); + while(key.size) { + ungrab_key(key.data[0]); + destroy_key(key.data[0]); } for(l = p = def.keys; p && *p;) { diff --git a/cmd/wm/mouse.c b/cmd/wm/mouse.c index e23e5225..ccc700f6 100644 --- a/cmd/wm/mouse.c +++ b/cmd/wm/mouse.c @@ -233,9 +233,9 @@ 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->view, - area2index(c->frame[c->sel]->area) == 0, &num); - XRectangle frect = c->frame[c->sel]->rect; + XRectangle *rects = rectangles(c->frame.data[c->sel]->area->view, + area2index(c->frame.data[c->sel]->area) == 0, &num); + XRectangle frect = c->frame.data[c->sel]->rect; XPoint pt; XQueryPointer(dpy, c->framewin, &dummy, &dummy, &i, &i, &wex, &wey, &dmask); @@ -259,7 +259,7 @@ mouse_move(Client *c) case ButtonRelease: if(!first) { draw_pseudo_border(&frect); - if(area2index(c->frame[c->sel]->area)) + if(area2index(c->frame.data[c->sel]->area)) resize_area(c, &frect, &pt); else resize_client(c, &frect, False); @@ -475,9 +475,9 @@ 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->view, - area2index(c->frame[c->sel]->area) == 0, &num); - XRectangle frect = c->frame[c->sel]->rect; + XRectangle *rects = rectangles(c->frame.data[c->sel]->area->view, + area2index(c->frame.data[c->sel]->area) == 0, &num); + XRectangle frect = c->frame.data[c->sel]->rect; XRectangle origin = frect; XQueryPointer(dpy, c->framewin, &dummy, &dummy, &i, &i, &ox, &oy, &dmask); @@ -501,7 +501,7 @@ mouse_resize(Client *c, Align align) draw_pseudo_border(&frect); pt.x = px; pt.y = py; - if(area2index(c->frame[c->sel]->area)) + if(area2index(c->frame.data[c->sel]->area)) resize_area(c, &frect, &pt); else resize_client(c, &frect, False); diff --git a/cmd/wm/rule.c b/cmd/wm/rule.c index 776756b2..21ba7752 100644 --- a/cmd/wm/rule.c +++ b/cmd/wm/rule.c @@ -39,7 +39,7 @@ update_rules() { unsigned int i; int mode = IGNORE; - char *p, *r, *t, regex[256], tags[256]; + char *p, *r=nil, *t=nil, regex[256], tags[256]; if(!def.rules || !strlen(def.rules)) return; @@ -81,6 +81,7 @@ update_rules() mode = IGNORE; *r = 0; rule[i].is_valid = !regcomp(&rule[i].regex, regex, 0); + /* Is there a memory leak here if the rule is invalid? */ } else { *r = *p; diff --git a/cmd/wm/tag.c b/cmd/wm/tag.c index 62dc91d1..a597ed41 100644 --- a/cmd/wm/tag.c +++ b/cmd/wm/tag.c @@ -12,8 +12,8 @@ Bool istag(char *t) { unsigned int i; - for(i = 0; i < ntag; i++) - if(!strncmp(tag[i], t, strlen(t))) + for(i = 0; i < tag.size; i++) + if(!strncmp(tag.data[i], t, strlen(t))) return True; return False; } @@ -44,46 +44,59 @@ organize_client(View *v, Client *c) } } + +/* We expect the optimiser to remove this function, It is included to ensure type safeness. + */ +static evector_t * +tag_to_evector(tag_vec_t *view) +{ + return (evector_t *) view; +} + +void +ensure_tag(char *arg) +{ + if(!istag(arg)) { + cext_evector_attach(tag_to_evector(&tag), strdup(arg)); + } +} + void update_tags() { unsigned int i, j; - for(i = 0; i < ntag; i++) { - free(tag[i]); - tag[i] = nil; + for(i = 0; i < tag.size; i++) { + free(tag.data[i]); + tag.data[i] = nil; } - ntag = 0; + tag.size = 0; - for(i = 0; i < nclient; i++) { - for(j = 0; j < client[i]->ntag; j++) { - if(!istag(client[i]->tag[j])) { - tag = (char **)cext_array_attach((void **)tag, strdup(client[i]->tag[j]), - sizeof(char *), &tagsz); - ntag++; - } + for(i = 0; i < client.size; i++) { + for(j = 0; j < client.data[i]->ntag; j++) { + ensure_tag(client.data[i]->tag[j]); } } - for(i = 0; nview && (i < nclient); i++) { - for(j = 0; j < nview; j++) { - View *v = view[j]; + for(i = 0; view.size && (i < client.size); i++) { + for(j = 0; j < view.size; j++) { + View *v = view.data[j]; if(j == sel) continue; - organize_client(v, client[i]); + organize_client(v, client.data[i]); } - organize_client(view[sel], client[i]); + organize_client(view.data[sel], client.data[i]); } - if(nview && !hasclient(view[sel])) { - destroy_view(view[sel]); - if(nview) - focus_view(view[sel]); + if(view.size && !hasclient(view.data[sel])) { + destroy_view(view.data[sel]); + if(view.size) + focus_view(view.data[sel]); else update_bar_tags(); } - if(!nview && ntag) - select_view(tag[0]); + if(!view.size && tag.size) + select_view(tag.data[0]); else update_bar_tags(); } diff --git a/cmd/wm/view.c b/cmd/wm/view.c index 494bab89..46b8aefe 100644 --- a/cmd/wm/view.c +++ b/cmd/wm/view.c @@ -8,6 +8,14 @@ #include "wm.h" +/* We expect the optimiser to remove this function, It is included to ensure type safeness. + */ +static evector_t * +view_to_evector(view_vec_t *view) +{ + return (evector_t *) view; +} + View * alloc_view(char *name) { @@ -18,20 +26,19 @@ alloc_view(char *name) v->ntag = str2tags(v->tag, name); alloc_area(v); alloc_area(v); - view = (View **)cext_array_attach((void **)view, v, sizeof(View *), &viewsz); - sel = nview++; + sel = view.size; + cext_evector_attach(view_to_evector(&view), v); return v; } void destroy_view(View *v) { - while(v->narea) - destroy_area(v->area[0]); + while(v->area.size) + destroy_area(v->area.data[0]); - cext_array_detach((void **)view, v, &viewsz); - nview--; - if(sel >= nview) + cext_evector_detach(view_to_evector(&view), v); + if(sel >= view.size) sel = 0; free(v); @@ -41,8 +48,8 @@ int view2index(View *v) { int i; - for(i = 0; i < nview; i++) - if(v == view[i]) + for(i = 0; i < view.size; i++) + if(v == view.data[i]) return i; return -1; } @@ -53,10 +60,10 @@ 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; + for(i = 0; i < client.size; i++) + for(j = 0; j < client.data[i]->frame.size; j++) + if(client.data[i]->frame.data[j]->area->view == v) + client.data[i]->sel = j; } void @@ -67,9 +74,9 @@ focus_view(View *v) char vname[256]; /* cleanup other empty views */ - for(i = 0; i < nview; i++) - if(!hasclient(view[i])) { - destroy_view(view[i]); + for(i = 0; i < view.size; i++) + if(!hasclient(view.data[i])) { + destroy_view(view.data[i]); i--; } @@ -82,17 +89,17 @@ focus_view(View *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]; + for(i = 0; i < client.size; i++) + if(client.data[i]->frame.size) { + Frame *f = client.data[i]->frame.data[client.data[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]); + XMoveWindow(dpy, client.data[i]->framewin, f->rect.x, f->rect.y); + if(client.data[i]->frame.size > 1) + resize_client(client.data[i], &f->rect, False); + draw_client(client.data[i]); } else - XMoveWindow(dpy, client[i]->framewin, + XMoveWindow(dpy, client.data[i]->framewin, 2 * rect.width + f->rect.x, f->rect.y); } if((c = sel_client_of_view(v))) @@ -110,23 +117,23 @@ rectangles(View *v, Bool isfloat, unsigned int *num) *num = 0; if(isfloat) - *num = v->area[0]->nframe; + *num = v->area.data[0]->frame.size; else { - for(i = 1; i < v->narea; i++) - *num += v->area[i]->nframe; + for(i = 1; i < v->area.size; i++) + *num += v->area.data[i]->frame.size; } if(*num) { result = cext_emallocz(*num * sizeof(XRectangle)); if(isfloat) { for(i = 0; i < *num; i++) - result[i] = v->area[0]->frame[0]->rect; + result[i] = v->area.data[0]->frame.data[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; + for(i = 1; i < v->area.size; i++) { + for(j = 0; j < v->area.data[i]->frame.size; j++) + result[n++] = v->area.data[i]->frame.data[j]->rect; } } } @@ -137,8 +144,8 @@ int vid2index(unsigned short id) { int i; - for(i = 0; i < nview; i++) - if(view[i]->id == id) + for(i = 0; i < view.size; i++) + if(view.data[i]->id == id) return i; return -1; } @@ -150,8 +157,8 @@ name2view(char *name) char vname[256]; unsigned int i; - for(i = 0; i < nview; i++) { - v = view[i]; + for(i = 0; i < view.size; i++) { + v = view.data[i]; tags2str(vname, sizeof(vname), v->tag, v->ntag); if(!strncmp(vname, name, strlen(name))) return v; @@ -171,18 +178,18 @@ get_view(char *name) return v; ntags = str2tags(tags, name); - for(i = 0; i < nclient; i++) + for(i = 0; i < client.size; i++) for(j = 0; j < ntags; j++) - if(clienthastag(client[i], tags[j])) + if(clienthastag(client.data[i], tags[j])) goto Createview; return nil; Createview: v = alloc_view(name); - for(i = 0; i < nclient; i++) + for(i = 0; i < client.size; i++) for(j = 0; j < ntags; j++) - if(clienthastag(client[i], tags[j]) && !clientofview(v, client[i])) - attach_toview(v, client[i]); + if(clienthastag(client.data[i], tags[j]) && !clientofview(v, client.data[i])) + attach_toview(v, client.data[i]); return v; } @@ -190,8 +197,8 @@ Bool hasclient(View *v) { unsigned int i; - for(i = 0; i < v->narea; i++) - if(v->area[i]->nframe) + for(i = 0; i < v->area.size; i++) + if(v->area.data[i]->frame.size) return True; return False; } @@ -202,11 +209,7 @@ select_view(char *arg) View *v = get_view(arg); if(!v) return; - if(!istag(arg)) { - tag = (char **)cext_array_attach((void **)tag, strdup(arg), - sizeof(char *), &tagsz); - ntag++; - } + ensure_tag(arg); focus_view(v); } @@ -214,8 +217,8 @@ Bool clientofview(View *v, Client *c) { unsigned int i; - for(i = 0; i < v->narea; i++) - if(clientofarea(v->area[i], c)) + for(i = 0; i < v->area.size; i++) + if(clientofarea(v->area.data[i], c)) return True; return False; } @@ -225,9 +228,9 @@ detach_fromview(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); + for(i = 0; i < v->area.size; i++) { + if(clientofarea(v->area.data[i], c)) { + detach_fromarea(v->area.data[i], c); XMoveWindow(dpy, c->framewin, 2 * rect.width, 0); } } @@ -241,14 +244,14 @@ attach_toview(View *v, Client *c) Area *a; if(c->trans || c->floating) - a = v->area[0]; + a = v->area.data[0]; else - a = v->area[v->sel]; + a = v->area.data[v->sel]; attach_toarea(a, c); map_client(c); XMapWindow(dpy, c->framewin); - if(v == view[sel]) + if(v == view.data[sel]) focus_client(c); } @@ -256,8 +259,8 @@ Client * sel_client_of_view(View *v) { if(v) { - Area *a = v->narea ? v->area[v->sel] : nil; - return (a && a->nframe) ? a->frame[a->sel]->client : nil; + Area *a = v->area.size ? v->area.data[v->sel] : nil; + return (a && a->frame.size) ? a->frame.data[a->sel]->client : nil; } return nil; } @@ -269,20 +272,20 @@ restack_view(View *v) static Window *wins = nil; static unsigned int winssz = 0; - if(nclient > winssz) { - winssz = 2 * nclient; + if(client.size > winssz) { + winssz = 2 * client.size; 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++) { + for(i = 0; i < v->area.size; i++) { + Area *a = v->area.data[i]; + if(a->frame.size) { + wins[n++] = a->frame.data[a->sel]->client->framewin; + for(j = 0; j < a->frame.size; j++) { if(j == a->sel) continue; - wins[n++] = a->frame[j]->client->framewin; + wins[n++] = a->frame.data[j]->client->framewin; } } } @@ -297,12 +300,12 @@ arrange_view(View *v, Bool updategeometry) unsigned int i; unsigned int width; - if(v->narea == 1) + if(v->area.size == 1) return; - width = rect.width / (v->narea - 1); - for(i = 1; i < v->narea; i++) { - Area *a = v->area[i]; + width = rect.width / (v->area.size - 1); + for(i = 1; i < v->area.size; i++) { + Area *a = v->area.data[i]; if(updategeometry) { a->rect.height = rect.height - brect.height; a->rect.x = (i - 1) * width; diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c index 1650c627..1e6ed594 100644 --- a/cmd/wm/wm.c +++ b/cmd/wm/wm.c @@ -33,9 +33,9 @@ win2client(Window w) { unsigned int i; - for(i = 0; (i < clientsz) && client[i]; i++) - if(client[i]->win == w) - return client[i]; + for(i = 0; (i < client.size) && client.data[i]; i++) + if(client.data[i]->win == w) + return client.data[i]; return nil; } @@ -201,10 +201,10 @@ static void cleanup() { unsigned int i; - Client *c; - for(i = 0; client && client[i]; i++) { - c = client[i]; - reparent_client(c, root, c->frame[c->sel]->rect.x, c->frame[c->sel]->rect.y); + for(i = 0; iframe.data[c->sel]; + reparent_client(c, root, cf->rect.x, cf->rect.y); } XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); XSync(dpy, False); @@ -293,15 +293,15 @@ main(int argc, char *argv[]) ixp_server_open_conn(&srv, ConnectionNumber(dpy), check_x_event, nil); init_x_event_handler(); - ntag = tagsz = nview = nclient = viewsz = clientsz = sel = 0; - view = nil; - tag = nil; - client = nil; + tag.size = view.size = client.size = sel = 0; + view.data = nil; + tag.data = nil; + client.data = nil; - key = nil; - keysz = nkey = 0; - label = nil; - nlabel = labelsz = 0; + key.data = nil; + key.size = 0; + label.data = nil; + label.size = 0; def.rules = nil; def.rulessz = 0; def.keys = nil; diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h index 7d866759..ac77ddb4 100644 --- a/cmd/wm/wm.h +++ b/cmd/wm/wm.h @@ -73,24 +73,24 @@ typedef struct Area Area; typedef struct Frame Frame; typedef struct Client Client; +EVECTOR(area_vec_t, Area*); + struct View { char tag[MAX_TAGS][MAX_TAGLEN]; unsigned int ntag; unsigned short id; - Area **area; - unsigned int areasz; - unsigned int narea; + area_vec_t area; unsigned int sel; unsigned int revert; }; +EVECTOR(frame_vec_t, Frame*); + struct Area { unsigned short id; - Frame **frame; + frame_vec_t frame; View *view; - unsigned int framesz; unsigned int sel; - unsigned int nframe; int mode; XRectangle rect; }; @@ -117,10 +117,8 @@ struct Client { XSizeHints size; Window framewin; GC gc; - Frame **frame; - unsigned int framesz; + frame_vec_t frame; unsigned int sel; - unsigned int nframe; Area *revert; }; @@ -160,22 +158,24 @@ typedef struct { } Default; /* global variables */ -View **view; -unsigned int nview; -unsigned int viewsz; +EVECTOR(view_vec_t, View*); +view_vec_t view; unsigned int sel; -Client **client; -unsigned int nclient; -unsigned int clientsz; -Key **key; -unsigned int keysz; -unsigned int nkey; -Label **label; -unsigned int nlabel; -unsigned int labelsz; -char **tag; -unsigned int ntag; -unsigned int tagsz; + +EVECTOR(client_vec_t, Client*); +client_vec_t client; + +EVECTOR(key_vec_t, Key*); +key_vec_t key; + +EVECTOR(label_vec_t, Label*); +label_vec_t label; + +EVECTOR(tag_vec_t, char *); +tag_vec_t tag; +//char **tag; +//unsigned int ntag; +//unsigned int tagsz; Display *dpy; IXPServer *ixps; @@ -284,6 +284,7 @@ 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 *t); +void ensure_tag(char *t); void update_tags(); /* view.c */ diff --git a/config.mk b/config.mk index 476f4f8d..a22e18c1 100644 --- a/config.mk +++ b/config.mk @@ -1,7 +1,7 @@ # Customize to fit your system # paths -PREFIX = /usr/local +PREFIX = /tmp/wmiibin CONFPREFIX = ${PREFIX}/etc MANPREFIX = ${PREFIX}/share/man @@ -14,9 +14,9 @@ VERSION = 3-current LIBS = -L${PREFIX}/lib -L/usr/lib -lc -lm -L${X11LIB} -lX11 # Linux/BSD -CFLAGS = -g -Wall -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \ +CFLAGS = -ggdb -Wall -O -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \ -DVERSION=\"${VERSION}\" -LDFLAGS = -g ${LIBS} +LDFLAGS = -ggdb ${LIBS} # Solaris #CFLAGS = -fast -xtarget=ultra ${INCLUDES} -DVERSION=\"${VERSION}\" diff --git a/libcext/Makefile b/libcext/Makefile index dec8192f..96e99e7c 100644 --- a/libcext/Makefile +++ b/libcext/Makefile @@ -3,7 +3,7 @@ include ../config.mk -SRC = array.c emallocz.c estrdup.c strlcat.c strlcpy.c strtonum.c tokenize.c +SRC = array.c emallocz.c estrdup.c evector.c strlcat.c strlcpy.c strtonum.c tokenize.c OBJ = ${SRC:.c=.o} @@ -16,6 +16,8 @@ all: libcext.a @echo CC $< @${CC} -c ${CFLAGS} $< +$(OBJ): cext.h + libcext.a: ${OBJ} @echo AR $@ @${AR} $@ ${OBJ} diff --git a/libcext/cext.h b/libcext/cext.h index c9588f64..5a6652e1 100644 --- a/libcext/cext.h +++ b/libcext/cext.h @@ -16,6 +16,18 @@ void cext_array_detach(void **array, void *p, unsigned int *size); /* emallocz.c */ void *cext_emallocz(unsigned int size); +/* evector.c */ +#define EVECTOR(name, type) \ +typedef struct { \ + unsigned int size; \ + type * data; \ +} name + +EVECTOR(evector_t, void*); + +void cext_evector_attach(evector_t *vector, void *data_to_be_added); +void cext_evector_detach(evector_t *vector, void *data_to_be_removed); + /* estrdup.c */ char *cext_estrdup(const char *s);