tBetter window size management. - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 20ae0b0fc25448245b75e0bd7b30b2fd29525165
 (DIR) parent 9881c00260e55f2994ca16229cf89a7929293e49
 (HTM) Author: rsc <devnull@localhost>
       Date:   Fri, 16 Dec 2005 15:12:38 +0000
       
       Better window size management.
       
       Diffstat:
         M src/cmd/acme/cols.c                 |      22 ++++++++++++++++++----
         M src/cmd/acme/fns.h                  |       2 +-
         M src/cmd/acme/look.c                 |      14 +++++++++-----
         M src/cmd/acme/wind.c                 |       7 ++++++-
       
       4 files changed, 34 insertions(+), 11 deletions(-)
       ---
 (DIR) diff --git a/src/cmd/acme/cols.c b/src/cmd/acme/cols.c
       t@@ -53,7 +53,7 @@ coladd(Column *c, Window *w, Window *clone, int y)
        {
                Rectangle r, r1;
                Window *v;
       -        int i, t;
       +        int i, j, minht, t;
        
                v = nil;
                r = c->r;
       t@@ -74,15 +74,27 @@ coladd(Column *c, Window *w, Window *clone, int y)
                        /*
                         * if v's too small, grow it first.
                         */
       -                if(!c->safe || v->body.fr.maxlines<=3){
       +                minht = v->tag.fr.font->height+Border+1;
       +                j = 0;
       +                while(!c->safe || v->body.fr.maxlines<=3 || Dy(v->body.all) <= minht){
       +                        if(++j > 10){
       +fprint(2, "oops: dy=%d\n", Dy(v->body.all));
       +                                break;
       +                        }
       +                        if(j > 1)
       +fprint(2, "regrow\n");
                                colgrow(c, v, 1);
       -                        y = v->body.fr.r.min.y+Dy(v->body.fr.r)/2;
                        }
       -                r = v->r;
                        if(i == c->nw)
                                t = c->r.max.y;
                        else
                                t = c->w[i]->r.min.y-Border;
       +                y = v->body.all.min.y+Dy(v->body.all)/2;
       +                if(t - y < minht)
       +                        y = t - minht;
       +                if(y < v->body.all.min.y)
       +                        y = v->body.all.min.y;
       +                r = v->r;
                        r.max.y = t;
                        draw(screen, r, textcols[BACK], nil, ZP);
                        r1 = r;
       t@@ -209,6 +221,8 @@ colresize(Column *c, Rectangle r)
                                r1.max.y = r.max.y;
                        else
                                r1.max.y = r1.min.y+(Dy(w->r)+Border)*Dy(r)/Dy(c->r);
       +                if(Dy(r1) < Border+font->height)
       +                        r1.max.y = r1.min.y + Border+font->height;
                        r2 = r1;
                        r2.max.y = r2.min.y+Border;
                        draw(screen, r2, display->black, nil, ZP);
 (DIR) diff --git a/src/cmd/acme/fns.h b/src/cmd/acme/fns.h
       t@@ -9,7 +9,7 @@ void        warningew(Window*, Mntdir*, char*, ...);
        #define        fbufalloc()        emalloc(BUFSIZE)
        #define        fbuffree(x)        free(x)
        
       -void        plumblook(Plumbmsg*m);
       +void        plumblook(Plumbmsg *m);
        void        plumbshow(Plumbmsg*m);
        void        acmeputsnarf(void);
        void        acmegetsnarf(void);
 (DIR) diff --git a/src/cmd/acme/look.c b/src/cmd/acme/look.c
       t@@ -16,7 +16,7 @@
        CFid *plumbsendfid;
        CFid *plumbeditfid;
        
       -Window*        openfile(Text*, Expand*);
       +Window*        openfile(Text*, Expand*, int);
        
        int        nuntitled;
        
       t@@ -167,7 +167,7 @@ look3(Text *t, uint q0, uint q1, int external)
                if(expanded == FALSE)
                        return;
                if(e.name || e.u.at)
       -                openfile(t, &e);
       +                openfile(t, &e, FALSE);
                else{
                        if(t->w == nil)
                                return;
       t@@ -207,6 +207,7 @@ plumblook(Plumbmsg *m)
        {
                Expand e;
                char *addr;
       +        int newwindow;
        
                if(m->ndata >= BUFSIZE){
                        warning(nil, "insanely long file name (%d bytes) in plumb message (%.32s...)\n", m->ndata, m->data);
       t@@ -227,7 +228,8 @@ plumblook(Plumbmsg *m)
                        e.u.ar = bytetorune(addr, &e.a1);
                        e.agetc = plumbgetc;
                }
       -        openfile(nil, &e);
       +        newwindow = plumblookup(m->attr, "newwindow") != nil;
       +        openfile(nil, &e, newwindow);
                free(e.name);
                free(e.u.at);
                drawtopwindow();
       t@@ -688,7 +690,7 @@ lookid(int id, int dump)
        
        
        Window*
       -openfile(Text *t, Expand *e)
       +openfile(Text *t, Expand *e, int newwindow)
        {
                Range r;
                Window *w, *ow;
       t@@ -705,6 +707,8 @@ openfile(Text *t, Expand *e)
                }else
                        w = lookfile(e->name, e->nname);
                if(w){
       +                if(newwindow==TRUE && !w->isdir)
       +                        w = coladd(w->col, nil, w, -1);
                        t = &w->body;
                        if(!t->col->safe && t->fr.maxlines==0) /* window is obscured by full-column window */
                                colgrow(t->col, t->col->w[0], 1);
       t@@ -785,7 +789,7 @@ new(Text *et, Text *t, Text *argt, int flag1, int flag2, Rune *arg, int narg)
                        e.nname = nf;
                        e.bname = runetobyte(f, nf);
                        e.jump = TRUE;
       -                openfile(et, &e);
       +                openfile(et, &e, FALSE);
                        free(f);
                        free(e.bname);
                        arg = skipbl(a, na, &narg);
 (DIR) diff --git a/src/cmd/acme/wind.c b/src/cmd/acme/wind.c
       t@@ -121,6 +121,7 @@ winresize(Window *w, Rectangle r, int safe, int keepextra)
                Image *b;
                Rectangle br, r1;
        
       +if(0) fprint(2, "winresize %d %R safe=%d keep=%d h=%d\n", w->id, r, safe, keepextra, font->height);
                w->tagtop = r;
                w->tagtop.max.y = r.min.y+font->height;
        
       t@@ -128,7 +129,9 @@ winresize(Window *w, Rectangle r, int safe, int keepextra)
                r1.max.y = min(r.max.y, r1.min.y + w->taglines*font->height);
                y = r1.max.y;
                if(1 || !safe || !eqrect(w->tag.all, r1)){
       +if(0) fprint(2, "resize tag %R => %R", w->tag.all, r1);
                        textresize(&w->tag, r1, TRUE);
       +if(0) fprint(2, "=> %R (%R)\n", w->tag.all, w->tag.fr.r);
                        y = w->tag.fr.r.max.y;
                        b = button;
                        if(w->body.file->mod && !w->isdir && !w->isscratch)
       t@@ -141,7 +144,7 @@ winresize(Window *w, Rectangle r, int safe, int keepextra)
                
                r1 = r;
                r1.min.y = y;
       -        if(!safe || !eqrect(w->body.all, r1)){
       +        if(1 || !safe || !eqrect(w->body.all, r1)){
                        if(y+1+w->body.fr.font->height <= r.max.y){        /* room for one line */
                                r1.min.y = y;
                                r1.max.y = y+1;
       t@@ -153,8 +156,10 @@ winresize(Window *w, Rectangle r, int safe, int keepextra)
                                r1.min.y = y;
                                r1.max.y = y;
                        }
       +if(0) fprint(2, "resize body %R => %R", w->body.all, r1);
                        w->r = r;
                        w->r.max.y = textresize(&w->body, r1, keepextra);
       +if(0) fprint(2, " => %R (%R; %R)\n", w->body.all, w->body.fr.r, w->r);
                        textscrdraw(&w->body);
                }
                w->maxlines = min(w->body.fr.nlines, max(w->maxlines, w->body.fr.maxlines));