commit a9e9456f420380357642fe36d652666f435d3ffa
parent df70479dc8c2849fbd02cbb98a43ea8174ad94fa
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Sun, 21 May 2006 18:43:41 +0200
removed the insert_* insanity, added cext_vattachat instead
Diffstat:
4 files changed, 19 insertions(+), 49 deletions(-)
diff --git a/cmd/wm/column.c b/cmd/wm/column.c
@@ -389,9 +389,9 @@ drop_move(Frame *f, XRectangle *new, XPoint *pt)
cext_vdetach(vector_of_frames(&tgt->frame), f);
if(before)
- insert_before_idx(&tgt->frame, f, fidx);
+ cext_vattachat(vector_of_frames(&tgt->frame), f, fidx);
else
- insert_after_idx(&tgt->frame, f, fidx);
+ cext_vattachat(vector_of_frames(&tgt->frame), f, fidx + 1);
tgt->sel = idx_of_frame(f);
arrange_column(tgt, False);
@@ -403,9 +403,9 @@ drop_move(Frame *f, XRectangle *new, XPoint *pt)
fidx = idx_of_frame(ft);
if(pt->y < (ft->rect.y + ft->rect.height / 2))
- insert_before_idx(&tgt->frame, f, fidx);
+ cext_vattachat(vector_of_frames(&tgt->frame), f, fidx);
else
- insert_after_idx(&tgt->frame, f, fidx);
+ cext_vattachat(vector_of_frames(&tgt->frame), f, fidx + 1);
tgt->sel = idx_of_frame(f);
arrange_column(tgt, False);
diff --git a/cmd/wm/frame.c b/cmd/wm/frame.c
@@ -26,16 +26,9 @@ create_frame(Area *a, Client *c)
f->rect.width += 2 * def.border;
f->rect.height += def.border + height_of_bar();
cext_vattach(vector_of_frames(&c->frame), f);
+ a->sel = a->frame.size ? a->sel + 1 : 0;
+ cext_vattachat(vector_of_frames(&a->frame), f, a->sel);
c->sel = c->frame.size - 1;
- if(a->frame.size) {
- insert_after_idx(&a->frame, f, a->sel);
- a->sel++;
- }
- else {
- cext_vattach(vector_of_frames(&a->frame), f);
- a->sel = 0;
- }
-
return f;
}
@@ -84,37 +77,3 @@ frame_of_win(Window w)
return client.data[i];
return nil;
}
-
-static void
-xinsert(FrameVector *fv, Frame *f, unsigned int idx, Bool before)
-{
- FrameVector tmp = {0};
- unsigned int i;
-
- for(i = 0; i < fv->size; i++) {
- if(before && (i == idx))
- cext_vattach(vector_of_frames(&tmp), f);
- cext_vattach(vector_of_frames(&tmp), fv->data[i]);
- if(!before && (i == idx))
- cext_vattach(vector_of_frames(&tmp), f);
- }
-
- while(fv->size)
- cext_vdetach(vector_of_frames(fv), fv->data[0]);
- for(i = 0; i < tmp.size; i++)
- cext_vattach(vector_of_frames(fv), tmp.data[i]);
- while(tmp.size)
- cext_vdetach(vector_of_frames(&tmp), tmp.data[0]);
-}
-
-void
-insert_before_idx(FrameVector *fv, Frame *f, unsigned int idx)
-{
- xinsert(fv, f, idx, True);
-}
-
-void
-insert_after_idx(FrameVector *fv, Frame *f, unsigned int idx)
-{
- xinsert(fv, f, idx, False);
-}
diff --git a/libcext/cext.h b/libcext/cext.h
@@ -40,5 +40,5 @@ typedef struct { \
VECTOR(Vector, void *);
void cext_vattach(Vector *v, void *p);
+void cext_vattachat(Vector *v, void *p, unsigned int pos);
void cext_vdetach(Vector *v, void *p);
-
diff --git a/libcext/vector.c b/libcext/vector.c
@@ -11,13 +11,24 @@ cext_vattach(Vector *v, void *p)
{
++v->size;
if (!(v->data = realloc(v->data, v->size * sizeof(void *)))) {
- fprintf(stderr, "%s\n", "Out of memory in cext_evector_attach\n");
+ fprintf(stderr, "%s\n", "Out of memory in cext_vattach\n");
exit(1);
}
v->data[v->size - 1] = p;
}
void
+cext_vattachat(Vector *v, void *p, unsigned int pos)
+{
+ cext_vattach(v, p);
+ if(pos >= v->size)
+ return;
+ memmove(v->data + pos + 1, v->data + pos,
+ (v->size - pos - 1) * sizeof(void *));
+ v->data[pos] = p;
+}
+
+void
cext_vdetach(Vector *v, void *data)
{
unsigned int i;