#include #include #include int wsys; void curwctl(char *s){ Dir *d; char buf[5 * 12]; int wctl, n; seek(wsys, 0, 0); n = dirreadall(wsys, &d); while(--n >= 0){ sprint(buf, "/dev/wsys/%s/wctl", d[n].name); wctl = open(buf, ORDWR); if(wctl < 0) continue; read(wctl, buf, 5 * 12); if(!strncmp(buf + 4 * 12, " current ", 12)) break; close(wctl); } free(d); if(n < 0){ fprint(2, "no current window\n"); return; } n = strlen(s); if(write(wctl, s, n) != n) fprint(2, "write: %r\n"); close(wctl); } char* tag(uint r){ Dir *d; char buf[5 * 12]; int fd, n; seek(wsys, 0, 0); n = dirreadall(wsys, &d); while(--n >= 0){ sprint(buf, "/dev/wsys/%s/wctl", d[n].name); fd = open(buf, OREAD); if(fd < 0) continue; read(fd, buf, 5 * 12); close(fd); if(!strncmp(buf + 4 * 12, " current ", 12)) break; } if(n < 0){ free(d); fprint(2, "no current window\n"); return nil; } sprint(buf, "/dev/wsys/%s/label", d[n].name); free(d); fd = open(buf, OREAD); if(fd >= 0){ n = read(fd, buf + 20, sizeof(buf) - 21); close(fd); if(n > 0) fprint(2, "F%ud = %.*s\n", r + 1, n, buf + 20); } strcpy(strchr(buf + 11, '/') + 1, "wctl"); return strdup(buf); } void raise(char **s){ int fd; fd = open(*s, OWRITE); if(fd < 0){ fprint(2, "%s disappeared\n", *s); free(*s); *s = nil; return; } write(fd, "current", 7); write(fd, "unhide", 6); close(fd); } void main(int, char**){ char *f[12], buf[128], *i, *o, *e, *mod = nil; Rune r; int wctl; for(r = 0; r < 12; r++) f[r] = nil; wctl = open("/dev/wctl", OWRITE); wsys = open("/dev/wsys", OREAD); if(wctl < 0 || wsys < 0) sysfatal("open: %r"); while(9){ i = o = buf; e = buf + read(0, buf, sizeof(buf)); if(e <= buf) break; while(i < e){ if(*i == 'k' || *i == 'K') mod = utfrune(i + 1, Kmod4); else if(*i == 'c'){ chartorune(&r, i + 1); if(r >= (KF | 1) && r <= (KF | 12)){ r -= KF | 1; if(mod == nil){ if(f[r] == nil) fprint(2, "nothing bound to F%ud\n", r + 1); else raise(f + r); }else{ free(f[r]); f[r] = tag(r); } while(*i++); continue; } if(mod != nil){ switch(r){ case Kdown: curwctl("hide"); break; case Kup: curwctl("resize -r 380 0 1600 900"); break; case Kleft: curwctl("resize -r 0 0 802 900"); break; case Kright: curwctl("resize -r 798 0 1600 900"); break; case '\n': case 'n': if(write(wctl, "new -r 380 0 1600 900", 21) != 21) fprint(2, "write: %r\n"); break; } while(*i++); continue; } } while(*o++ = *i++); } write(1, buf, o - buf); } exits(nil); }