#include "i.h" // globals Channel* evchan; int Mfmt(Fmt *f); void eventinit(void) { evchan = chancreate(sizeof(EV), 0); fmtinstall('M', Mfmt); } int Mfmt(Fmt *f) { EV* ev; char* s; char cbuf[4]; int i; int n; Point p; char buf[BIGBUFSIZE]; ev = va_arg(f->args, EV*); n = sizeof(buf) - 1; switch(ev->tag) { case EVkeytag: switch(ev->u.keychar) { case ' ': s = ""; break; case '\t': s = ""; break; case '\n': s = ""; break; case '\r': s = ""; break; case '\b': s = ""; break; case 127: s = ""; break; case Kup: s = ""; break; case Kdown: s = ""; break; case Khome: s = ""; break; case Kleft: s = ""; break; case Kright: s = ""; break; default: sprint(cbuf, "%C", ev->u.keychar); s = cbuf; break; } i = snprint(buf, n, "key %d = %s", ev->u.keychar, s); break; case EVmousetag: switch(ev->u.mouse.mtype) { case Mmove: s = "move"; break; case Mlbuttondown: s = "lbuttondown"; break; case Mlbuttonup: s = "lbuttonup"; break; case Mldrag: s = "ldrag"; break; case Mmbuttondown: s = "mbuttondown"; break; case Mmbuttonup: s = "mbuttonup"; break; case Mmdrag: s = "mdrag"; break; case Mrbuttondown: s = "rbuttondown"; break; case Mrbuttonup: s = "rbuttonup"; break; case Mrdrag: s = "rdrag"; break; default: s = "?"; } p = ev->u.mouse.p; i = snprint(buf, n, "mouse (%d,%d) %s", p.x, p.y, s); break; case EVmovetag: p = ev->u.movept; i = snprint(buf, n, "move (%d,%d)", p.x, p.y); break; case EVresizetag: i = snprint(buf, n, "resize (%d,%d) (%d,%d)", ev->u.resizer.min.x, ev->u.resizer.min.y, ev->u.resizer.max.x, ev->u.resizer.max.y); break; case EVexposetag: i = snprint(buf, n, "expose"); break; case EVhidetag: i = snprint(buf, n, "hide"); break; case EVquittag: i = snprint(buf, n, "quit"); break; case EVstoptag: i = snprint(buf, n, "stop"); break; case EValerttag: i = snprint(buf, n, "alert(%S)", ev->u.alert.msg); break; case EVformtag: switch(ev->u.form.ftype) { case EFsubmit: s = "form submit"; break; case EFreset: s = "form reset"; break; default: s = "form unknown"; } i = snprint(buf, n, "%s", s); break; case EVgotag: if(ev->u.go.gtype == EGnormal) i = snprint(buf, n, "go(%U)", ev->u.go.url); else { switch(ev->u.go.gtype) { case EGreload: s = "RELOAD"; break; case EGforward: s = "FORWARD"; break; case EGback: s = "BACK"; break; case EGhome: s = "HOME"; break; case EGbookmarks: s = "BOOKMARKS"; break; default: s = "?"; } i = snprint(buf, sizeof(buf), "go(%s)", s); } break; case EVanimtag: i = snprint(buf, sizeof(buf), "anim(%U)", ev->u.anim.ai->cim->src); break; case EVprogresstag: switch(ev->u.progress.state) { case 0: s = ""; break; case Pstart: s = "start"; break; case Pconnected: s = "connected"; break; case Phavehdr: s = "havehdr"; break; case Pdone: s = "done"; break; case Perr: s = "err"; break; case Paborted: s = "aborted"; break; default: s = "?"; } i = snprint(buf, sizeof(buf), "progress(%d, %s, %d, %S)", ev->u.progress.bsid, s, ev->u.progress.pcnt, ev->u.progress.s ? ev->u.progress.s : L""); break; case EVdelaytag: i = snprint(buf, sizeof(buf), "delay(%d) %M", ev->u.delay.millisecs, ev->u.delay.ev); break; default: i = snprint(buf, sizeof(buf), "unknown event"); } buf[i] = 0; return fmtstrcpy(f, buf); } EV evgo(ParsedUrl* u, int targ, int gtype, int genframeid) { EV eg; eg.tag = EVgotag; eg.genframeid = genframeid; eg.u.go.url = u; eg.u.go.target = targ; eg.u.go.gtype = gtype; return eg; } EV evmouse(Point p, int mtype) { EV em; em.tag = EVmousetag; em.genframeid = -1; em.u.mouse.p = p; em.u.mouse.mtype = mtype; return em; } EV evkey(int keycode) { EV ek; ek.tag = EVkeytag; ek.genframeid = -1; ek.u.keychar = keycode; return ek; }