X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=sys%2Fsrc%2Fcmd%2Fwinwatch.c;h=988a7cb55d49bf9763ec0551e25c373a38bce3bf;hb=2728e065895e7af2493ed7af3b8897caa416adf6;hp=0f5a9c4e83485e89739e65c41d9777a5cf494897;hpb=e5888a1ffdae813d7575f5fb02275c6bb07e5199;p=plan9front.git diff --git a/sys/src/cmd/winwatch.c b/sys/src/cmd/winwatch.c old mode 100755 new mode 100644 index 0f5a9c4e8..988a7cb55 --- a/sys/src/cmd/winwatch.c +++ b/sys/src/cmd/winwatch.c @@ -1,27 +1,33 @@ #include #include #include +#include #include #include +#include + +enum { + VISIBLE = 1, + CURRENT = 2, +}; typedef struct Win Win; struct Win { int n; int dirty; + int state; char *label; Rectangle r; }; - - Reprog *exclude = nil; Win *win; int nwin; int mwin; int onwin; int rows, cols; -Font *font; Image *lightblue; +Image *statecol[4]; enum { PAD = 3, @@ -64,14 +70,43 @@ estrdup(char *s) return t; } +int +readfile(char *buf, int nbuf, char *file, ...) +{ + va_list arg; + int n, fd; + + va_start(arg, file); + vsnprint(buf, nbuf, file, arg); + va_end(arg); + + if((fd = open(buf, OREAD)) < 0){ + buf[0] = 0; + return -1; + } + n = read(fd, buf, nbuf-1); + close(fd); + if(n < 0){ + buf[0] = 0; + return -1; + } + buf[n] = 0; + return n; +} void refreshwin(void) { - char label[128]; - int i, fd, lfd, n, nr, nw, m; + char label[128], wctl[128], *tok[8]; + int i, fd, n, nr, nw, state; + static int mywinid = -1; Dir *pd; + if(mywinid < 0){ + if(readfile(wctl, sizeof(wctl), "/dev/winid") > 0) + mywinid = atoi(wctl); + } + if((fd = open("/dev/wsys", OREAD)) < 0) return; @@ -80,18 +115,23 @@ refreshwin(void) while((nr=dirread(fd, &pd)) > 0){ for(i=0; iblack, ZP, font, win[i].label, nil, strlen(win[i].label), win[i].r, nil, ZP, SoverD); @@ -149,6 +190,8 @@ geometry(void) z = 0; rows = (Dy(screen->r)-2*MARGIN+PAD)/(font->height+PAD); + if(rows <= 0) + rows = 1; if(rows*cols < nwin || rows*cols >= nwin*2){ ncols = nwin <= 0 ? 1 : (nwin+rows-1)/rows; if(ncols != cols){ @@ -192,45 +235,73 @@ eresized(int new) redraw(screen, 1); } -void -click(Mouse m) +int +label(Win w, Mouse m) +{ + char buf[512], fname[128]; + int n, fd; + + snprint(buf, sizeof(buf), "%s", w.label); + n = eenter(nil, buf, sizeof(buf), &m); + if(n <= 0) + return 0; + sprint(fname, "/dev/wsys/%d/label", w.n); + if((fd = open(fname, OWRITE)) < 0) + return 0; + write(fd, buf, n); + close(fd); + refreshwin(); + redraw(screen, 1); + return 1; +} + +int +unhide(Win w) { - int fd, i, j; char buf[128]; + int fd; - if(m.buttons == 0 || (m.buttons & ~4)) - return; + sprint(buf, "/dev/wsys/%d/wctl", w.n); + if((fd = open(buf, OWRITE)) < 0) + return 0; + if(w.state == (CURRENT|VISIBLE)) + write(fd, "hide\n", 5); + else { + write(fd, "unhide\n", 7); + write(fd, "top\n", 4); + write(fd, "current\n", 8); + } + close(fd); + return 1; +} +int +click(Mouse m) +{ + int i, b; + + b = m.buttons & 7; + if(b != 2 && b != 4) + return 0; for(i=0; ichan, 1, 0xCCCCCCFF); + statecol[1] = lightblue; + statecol[2] = lightblue; + statecol[3] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPalegreygreen); + + for(i=0; i