diff --git a/README.md b/README.md index ed0f2dc..7505309 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ This is a fork of the `acme` text editor from the `plan9port` distribution. It combines the customizability of [lumar](https://github.com/lumar)/[sminez](https://github.com/sminez/plan9port)'s forks and [acme2k](https://github.com/karahobny/acme2k) with upstream fixes from [9fans](https://github.com/9fans/plan9port) and some custom work. +Namely, when click-to-focus is enabled, the active window body or tag renders the tick (aka the text cursor) with the hilight color (`COLOR__HI`); otherwise the tick is rendered with the text color (`COLOR__TX`). This is all done with a fork of `libframe` which is included in the distribution and compiled into the program. + See the `config.def.h` for out of the box customizations that can be done. [![screenshot](./scrot.png)](./scrot.png) @@ -44,13 +46,14 @@ After building, run `./install.sh`; If run as a regular user, it will install to ## TODO -* [ ] add an indicator of the active window when click to focus (`bartflag`) is enabled +- [ ] allow active tick to be rendered for row/column tags, not just window body and tags +- [ ] compile helpers ## thanks -* [rob pike](https://github.com/robpike) author of the original acme for plan9 -* [russ cox](https://research.swtch.com) and the rest of the [9fans](https://github.com/9fans) for plan9port -* [lumar](https://github.com/lumar) - looks like they deleted their github repos but I originally pulled my keybinds from there -* [sminez](https://github.com/sminez) - possibly the original source of lumar's keybindings -* [karahobny](https://github.com/karahobny) - creator of acme2k, a big inspiration for this project -* [aksr](https://github.com/aksr) - source of the missing tag border pixel fix +- [rob pike](https://github.com/robpike) author of the original acme for plan9 +- [russ cox](https://research.swtch.com) and the rest of the [9fans](https://github.com/9fans) for plan9port +- [lumar](https://github.com/lumar) - looks like they deleted their github repos but I originally pulled my keybinds from there +- [sminez](https://github.com/sminez) - possibly the original source of lumar's keybindings +- [karahobny](https://github.com/karahobny) - creator of acme2k, a big inspiration for this project +- [aksr](https://github.com/aksr) - source of the missing tag border pixel fix diff --git a/acme.c b/acme.c index 5b50af6..7c1e142 100644 --- a/acme.c +++ b/acme.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include @@ -43,7 +43,7 @@ Rune snarfrune[NSnarf + 1]; char* fontnames[2] = {PRIMARY_FONT, SECONDARY_FONT}; -char version[] = "acme9k v9001-a01"; +char version[] = "acme9k v9001-a02"; Command* command; @@ -510,7 +510,10 @@ void mousethread(void* v) { char* act; enum { MResize, MMouse, MPlumb, MWarnings, NMALT }; static Alt alts[NMALT + 1]; + + /* make sure we don't recklessly refresh the ticks */ int click; + Text* oldbarttext; USED(v); threadsetname("mousethread"); @@ -598,6 +601,7 @@ void mousethread(void* v) { but = 2; else if (m.buttons == 4) but = 3; + oldbarttext = barttext; barttext = t; if (t->what == Body && ptinrect(m.xy, t->scrollr)) { if (but) { @@ -668,15 +672,16 @@ void mousethread(void* v) { if (textselect3(t, &q0, &q1)) look3(t, q0, q1, FALSE); } + if (w) winunlock(w); goto Continue; } Continue: - /*if (click && w) { - /* draw hilighted border around active window - windrawideco(w, w->col->row->col, w->col->row->ncol); - }*/ + /* won't refresh ticks if scrolling didn't change the active frame! */ + if (oldbarttext != barttext && (m.buttons & (8 | 16) || click) && t) { + textsettick(t, t->row); + } qunlock(&row.lk); break; } diff --git a/addr.c b/addr.c index feeb82b..736fc19 100644 --- a/addr.c +++ b/addr.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/buff.c b/buff.c index a02c0a6..1d6c6eb 100644 --- a/buff.c +++ b/buff.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/cols.c b/cols.c index f05ac1c..1cf9dd9 100644 --- a/cols.c +++ b/cols.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include @@ -160,6 +160,7 @@ Window* coladd(Column* c, Window* w, Window* clone, int y) { /* near the button, but in the body */ moveto(mousectl, addpt(w->tag.scrollr.max, Pt(3, 3))); barttext = &w->body; + textsettick(&w->body, c->row); return w; } @@ -494,6 +495,7 @@ Pack: free(ny); c->safe = TRUE; winmousebut(w); + textsettick(&w->body, c->row); } void coldragwin(Column* c, Window* w, int but) { @@ -581,6 +583,7 @@ Found: winresize(w, r, c->safe, TRUE); c->safe = TRUE; winmousebut(w); + textsettick(&w->body, c->row); } Text* colwhich(Column* c, Point p) { diff --git a/config.def.h b/config.def.h index c316082..64b9269 100644 --- a/config.def.h +++ b/config.def.h @@ -1,5 +1,5 @@ /****************** - * acme9k1 config * + * acme9k config * ******************/ /********** diff --git a/dat.h b/dat.h index e2cb494..9c74ca8 100644 --- a/dat.h +++ b/dat.h @@ -228,7 +228,7 @@ void textsetorigin(Text*, uint, int); void textsetselect(Text*, uint, uint); void textshow(Text*, uint, uint, int); void texttype(Text*, Rune); - +void textsettick(Text*, Row*); enum { @@ -304,7 +304,6 @@ void winmousebut(Window*); void winaddincl(Window*, Rune*, int); void wincleartag(Window*); char *winctlprint(Window*, char*, int); -void windrawideco(Window*, Column**, int); struct Column { diff --git a/disk.c b/disk.c index 05e4c80..a9a6223 100644 --- a/disk.c +++ b/disk.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/ecmd.c b/ecmd.c index 2ae8403..37b5f50 100644 --- a/ecmd.c +++ b/ecmd.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/edit.c b/edit.c index e4ba23d..9dbf385 100644 --- a/edit.c +++ b/edit.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/elog.c b/elog.c index 6410378..5f73e81 100644 --- a/elog.c +++ b/elog.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/exec.c b/exec.c index 073e7b1..955219d 100644 --- a/exec.c +++ b/exec.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/file.c b/file.c index e4af18d..f634f6d 100644 --- a/file.c +++ b/file.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/fsys.c b/fsys.c index 827e5a6..000237a 100644 --- a/fsys.c +++ b/fsys.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/libframe/frame.h b/libframe/frame.h new file mode 100644 index 0000000..c81a69e --- /dev/null +++ b/libframe/frame.h @@ -0,0 +1,101 @@ +#ifndef _FRAME_H_ +#define _FRAME_H_ 1 +#if defined(__cplusplus) +extern "C" { +#endif + +AUTOLIB(frame) + +typedef struct Frbox Frbox; +typedef struct Frame Frame; + +enum{ + BACK, + HIGH, + BORD, + TEXT, + HTEXT, + NCOL +}; + +#define FRTICKW 3 +struct Frbox +{ + long wid; /* in pixels */ + long nrune; /* <0 ==> negate and treat as break char */ + uchar *ptr; + short bc; /* break char */ + short minwid; +}; + +struct Frame +{ + Font *font; /* of chars in the frame */ + Display *display; /* on which frame appears */ + Image *b; /* on which frame appears */ + Image *cols[NCOL]; /* text and background colors */ + Rectangle r; /* in which text appears */ + Rectangle entire; /* of full frame */ + void (*scroll)(Frame*, int); /* scroll function provided by application */ + Frbox *box; + ulong p0, p1; /* selection */ + ushort nbox, nalloc; + ushort maxtab; /* max size of tab, in pixels */ + ushort nchars; /* # runes in frame */ + ushort nlines; /* # lines with text */ + ushort maxlines; /* total # lines in frame */ + ushort lastlinefull; /* last line fills frame */ + ushort modified; /* changed since frselect() */ + Image *tick; /* typing tick when frame is inactive */ + Image* activetick; /* typing tick when frame has keyboard focus */ + Image* currenttick; /* points to the appropriate one of tick or activetick */ + Image *tickback; /* saved image under tick */ + int ticked; /* flag: is tick onscreen? */ + int noredraw; /* don't draw on the screen */ + int tickscale; /* tick scaling factor */ +}; + +ulong frcharofpt(Frame*, Point); +Point frptofchar(Frame*, ulong); +int frdelete(Frame*, ulong, ulong); +void frinsert(Frame*, Rune*, Rune*, ulong); +void frselect(Frame*, Mousectl*); +void frselectpaint(Frame*, Point, Point, Image*); +void frdrawsel(Frame*, Point, ulong, ulong, int); +Point frdrawsel0(Frame*, Point, ulong, ulong, Image*, Image*); +void frinit(Frame*, Rectangle, Font*, Image*, Image**); +void frsetrects(Frame*, Rectangle, Image*); +void frclear(Frame*, int); +void frredraw(Frame*); + +uchar *_frallocstr(Frame*, unsigned); +void _frinsure(Frame*, int, unsigned); +Point _frdraw(Frame*, Point); +void _frgrowbox(Frame*, int); +void _frfreebox(Frame*, int, int); +void _frmergebox(Frame*, int); +void _frdelbox(Frame*, int, int); +void _frsplitbox(Frame*, int, int); +int _frfindbox(Frame*, int, ulong, ulong); +void _frclosebox(Frame*, int, int); +int _frcanfit(Frame*, Point, Frbox*); +void _frcklinewrap(Frame*, Point*, Frbox*); +void _frcklinewrap0(Frame*, Point*, Frbox*); +void _fradvance(Frame*, Point*, Frbox*); +int _frnewwid(Frame*, Point, Frbox*); +int _frnewwid0(Frame*, Point, Frbox*); +void _frclean(Frame*, Point, int, int); +void _frdrawtext(Frame*, Point, Image*, Image*); +void _fraddbox(Frame*, int, int); +Point _frptofcharptb(Frame*, ulong, Point, int); +Point _frptofcharnb(Frame*, ulong, int); +int _frstrlen(Frame*, int); +void frtick(Frame*, Point, int); +void frinittick(Frame*); + +#define NRUNE(b) ((b)->nrune<0? 1 : (b)->nrune) +#define NBYTE(b) strlen((char*)(b)->ptr) +#if defined(__cplusplus) +} +#endif +#endif diff --git a/libframe/frbox.c b/libframe/frbox.c index f27baaa..6ff3877 100644 --- a/libframe/frbox.c +++ b/libframe/frbox.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include "frame.h" #define SLOP 25 diff --git a/libframe/frdelete.c b/libframe/frdelete.c index c386a5f..358f75f 100644 --- a/libframe/frdelete.c +++ b/libframe/frdelete.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include "frame.h" int frdelete(Frame* f, ulong p0, ulong p1) { Point pt0, pt1, ppt0; diff --git a/libframe/frdraw.c b/libframe/frdraw.c index bd541c9..4ee115f 100644 --- a/libframe/frdraw.c +++ b/libframe/frdraw.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include "frame.h" void _frdrawtext(Frame* f, Point pt, Image* text, Image* back) { Frbox* b; @@ -136,7 +136,7 @@ void frredraw(Frame* f) { static void _frtick(Frame* f, Point pt, int ticked) { Rectangle r; - if (f->ticked == ticked || f->tick == 0 || !ptinrect(pt, f->r)) + if (f->ticked == ticked || f->currenttick == 0 || !ptinrect(pt, f->r)) return; pt.x -= f->tickscale; /* looks best just left of where requested */ r = Rect(pt.x, pt.y, pt.x + FRTICKW * f->tickscale, pt.y + f->font->height); @@ -145,7 +145,7 @@ static void _frtick(Frame* f, Point pt, int ticked) { r.max.x = f->r.max.x; if (ticked) { draw(f->tickback, f->tickback->r, f->b, nil, pt); - draw(f->b, r, f->tick, nil, ZP); + draw(f->b, r, f->currenttick, nil, ZP); } else draw(f->b, r, f->tickback, nil, ZP); f->ticked = ticked; diff --git a/libframe/frinit.c b/libframe/frinit.c index da63bc1..79000d1 100644 --- a/libframe/frinit.c +++ b/libframe/frinit.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include "frame.h" void frinit(Frame* f, Rectangle r, Font* ft, Image* b, Image* cols[NCOL]) { f->font = ft; @@ -42,6 +42,16 @@ void frinittick(Frame* f) { DWhite); if (f->tick == nil) return; + if (f->activetick) + freeimage(f->activetick); + f->activetick = allocimage( + f->display, + Rect(0, 0, f->tickscale * FRTICKW, ft->height), + b->chan, + 0, + DWhite); + if (f->activetick == nil) + return; if (f->tickback) freeimage(f->tickback); f->tickback = allocimage(f->display, f->tick->r, b->chan, 0, DWhite); @@ -50,9 +60,9 @@ void frinittick(Frame* f) { f->tick = 0; return; } - /* background color */ + /* inactive background color */ draw(f->tick, f->tick->r, f->cols[BACK], nil, ZP); - /* vertical line */ + /* inactive vertical line */ draw( f->tick, Rect( @@ -63,7 +73,7 @@ void frinittick(Frame* f) { f->cols[TEXT], nil, ZP); - /* box on each end */ + /* inactive box on each end */ draw( f->tick, Rect(0, 0, f->tickscale * FRTICKW, f->tickscale * FRTICKW), @@ -80,6 +90,39 @@ void frinittick(Frame* f) { f->cols[TEXT], nil, ZP); + + /* active background color */ + draw(f->activetick, f->activetick->r, f->cols[BACK], nil, ZP); + /* active vertical line */ + draw( + f->activetick, + Rect( + f->tickscale * (FRTICKW / 2), + 0, + f->tickscale * (FRTICKW / 2 + 1), + ft->height), + f->cols[HIGH], + nil, + ZP); + /* active box on each end */ + draw( + f->activetick, + Rect(0, 0, f->tickscale * FRTICKW, f->tickscale * FRTICKW), + f->cols[HIGH], + nil, + ZP); + draw( + f->activetick, + Rect( + 0, + ft->height - f->tickscale * FRTICKW, + f->tickscale * FRTICKW, + ft->height), + f->cols[HIGH], + nil, + ZP); + + f->currenttick = f->tick; } void frsetrects(Frame* f, Rectangle r, Image* b) { @@ -96,8 +139,10 @@ void frclear(Frame* f, int freeall) { if (f->box) free(f->box); if (freeall) { + freeimage(f->activetick); freeimage(f->tick); freeimage(f->tickback); + f->currenttick = nil; f->tick = 0; f->tickback = 0; } diff --git a/libframe/frinsert.c b/libframe/frinsert.c index b6accef..9aec5bf 100644 --- a/libframe/frinsert.c +++ b/libframe/frinsert.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include "frame.h" #define DELTA 25 #define TMPSIZE 256 diff --git a/libframe/frptofchar.c b/libframe/frptofchar.c index 9c92cd2..de33f5a 100644 --- a/libframe/frptofchar.c +++ b/libframe/frptofchar.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include "frame.h" Point _frptofcharptb(Frame* f, ulong p, Point pt, int bn) { uchar* s; diff --git a/libframe/frselect.c b/libframe/frselect.c index 4f48f8c..24c7be3 100644 --- a/libframe/frselect.c +++ b/libframe/frselect.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include "frame.h" static int region(int a, int b) { if (a < b) diff --git a/libframe/frstr.c b/libframe/frstr.c index 4d98e5f..c524924 100644 --- a/libframe/frstr.c +++ b/libframe/frstr.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include "frame.h" #define CHUNK 16 #define ROUNDUP(n) ((n + CHUNK) & ~(CHUNK - 1)) diff --git a/libframe/frutil.c b/libframe/frutil.c index 8435861..81d3caa 100644 --- a/libframe/frutil.c +++ b/libframe/frutil.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include "frame.h" int _frcanfit(Frame* f, Point pt, Frbox* b) { int left, w, nr; diff --git a/libframe/libframe.a b/libframe/libframe.a index 452179d..9d59fed 100644 Binary files a/libframe/libframe.a and b/libframe/libframe.a differ diff --git a/logf.c b/logf.c index 50726bd..d9a3840 100644 --- a/logf.c +++ b/logf.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/look.c b/look.c index aeb2d42..b7b9930 100644 --- a/look.c +++ b/look.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include <9pclient.h> diff --git a/mkfile b/mkfile index a7499a2..a74eb73 100644 --- a/mkfile +++ b/mkfile @@ -4,7 +4,15 @@ TARG=acme DIRS=mail libframe OFILES=\ + libframe/frbox.$O\ + libframe/frdelete.$O\ + libframe/frdraw.$O\ libframe/frinit.$O\ + libframe/frinsert.$O\ + libframe/frptofchar.$O\ + libframe/frselect.$O\ + libframe/frstr.$O\ + libframe/frutil.$O\ acme.$O\ addr.$O\ buff.$O\ @@ -27,7 +35,8 @@ OFILES=\ wind.$O\ xfid.$O\ -HFILES=dat.h\ +HFILES=libframe/frame.h\ + dat.h\ edit.h\ fns.h\ @@ -36,7 +45,7 @@ HFILES=dat.h\ edit.$O ecmd.$O elog.$O: edit.h -LDFLAGS=-L./libframe -lframe $LDFLAGS +# LDFLAGS=-L./libframe -lframe $LDFLAGS likeplan9:V: mkdir -p likeplan9 diff --git a/regx.c b/regx.c index b26b5e4..3579283 100644 --- a/regx.c +++ b/regx.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/rows.c b/rows.c index ead56fd..55d45db 100644 --- a/rows.c +++ b/rows.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/scrl.c b/scrl.c index f641d64..ee6ffb3 100644 --- a/scrl.c +++ b/scrl.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/scrot.png b/scrot.png index 0e079c7..cd00efd 100644 Binary files a/scrot.png and b/scrot.png differ diff --git a/text.c b/text.c index 4ca959a..f266e26 100644 --- a/text.c +++ b/text.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include @@ -36,17 +36,39 @@ void textinit(Text* t, File* f, Rectangle r, Reffont* rf, Image* cols[NCOL]) { textredraw(t, r, rf->f, screen, -1, 0); } -void textdrawactive(Text* t, int active) { - Image* b; - Rectangle br; +void _textsettick(Text* current, Text* self) { + self->fr.currenttick = + (self == current) ? self->fr.activetick : self->fr.tick; +} - b = t->fr.cols[BACK]; - if (active) - b = t->fr.cols[HIGH]; - br.min = t->scrollr.max; - br.max.x = br.min.x + 1; - br.max.y = br.min.y + Dy(t->all); - draw(screen, br, b, nil, b->r.min); +void textsettick(Text* t, Row* r) { + Column** allcolumns; + Column* cptr; + Window* wptr; + int ncols, ccnt, wcnt; + + if (!bartflag) + return; + + allcolumns = r->col; + ncols = r->ncol; + + _textsettick(t, &r->tag); + for (ccnt = 0; ccnt < ncols; ccnt++) { + cptr = allcolumns[ccnt]; + _textsettick(t, &cptr->tag); + for (wcnt = 0; wcnt < cptr->nw; wcnt++) { + wptr = cptr->w[wcnt]; + winlock(wptr, 'M'); + _textsettick(t, &wptr->tag); + _textsettick(t, &wptr->body); + winunlock(wptr); + } + } + /* force redraw to refresh all ticks; + * kind of expensive, but we only do it when the active frame changes + */ + rowresize(r, r->r); } void textredraw(Text* t, Rectangle r, Font* f, Image* b, int odx, int active) { @@ -77,7 +99,6 @@ void textredraw(Text* t, Rectangle r, Font* f, Image* b, int odx, int active) { textfill(t); textsetselect(t, t->q0, t->q1); } - /*textdrawactive(t, active);*/ } int textresize(Text* t, Rectangle r, int keepextra) { diff --git a/time.c b/time.c index e1ea495..ffd0910 100644 --- a/time.c +++ b/time.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/util.c b/util.c index 80322f1..9a52692 100644 --- a/util.c +++ b/util.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include diff --git a/wind.c b/wind.c index 9f7208a..69286da 100644 --- a/wind.c +++ b/wind.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include @@ -89,35 +89,6 @@ void wininit(Window* w, Window* clone, Rectangle r) { } } -void windrawideco(Window* active, Column** allcols, int ncol) { - Window* wptr; - Column* cptr; - int wcnt, ccnt; - - for (ccnt = 0; ccnt < ncol; ccnt++) { - cptr = allcols[ccnt]; - for (wcnt = 0; wcnt < cptr->nw; wcnt++) { - wptr = cptr->w[wcnt]; - winlock(wptr, 'M'); - textredraw( - &wptr->tag, - wptr->tag.scrollr, - wptr->tag.fr.font, - screen, - -1, - wptr->id == active->id); - textredraw( - &wptr->body, - wptr->body.scrollr, - wptr->body.fr.font, - screen, - -1, - wptr->id == active->id); - winunlock(wptr); - } - } -} - /* * Draw the appropriate button. */ diff --git a/xfid.c b/xfid.c index f9ebd0e..95c52de 100644 --- a/xfid.c +++ b/xfid.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "libframe/frame.h" #include #include #include