From 25493360e37474fb656eb8eea336e80bf3e99c66 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 29 Jan 2012 03:52:41 +0100 Subject: [PATCH] winwatch: highlight window state --- sys/src/cmd/winwatch.c | 124 +++++++++++++++++++++++++++-------------- 1 file changed, 82 insertions(+), 42 deletions(-) diff --git a/sys/src/cmd/winwatch.c b/sys/src/cmd/winwatch.c index 6819108ad..089dd1536 100644 --- a/sys/src/cmd/winwatch.c +++ b/sys/src/cmd/winwatch.c @@ -4,16 +4,20 @@ #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; @@ -21,6 +25,7 @@ int mwin; int onwin; int rows, cols; Image *lightblue; +Image *statecol[4]; enum { PAD = 3, @@ -63,14 +68,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; @@ -79,18 +113,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); @@ -191,45 +231,37 @@ eresized(int new) redraw(screen, 1); } -void +int click(Mouse m) { - int fd, i, j; char buf[128]; + int fd, i; - if(m.buttons == 0 || (m.buttons & ~4)) - return; - + if((m.buttons & 7) != 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