From 2ae943225f5851db8ca723370ab79bb6fb78e7b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 31 Jan 2021 14:15:52 +0000 Subject: Add patch/winwatch-custom-rate --- patch/winwatch-custom-rate/email | 1 + patch/winwatch-custom-rate/files | 1 + patch/winwatch-custom-rate/notes | 0 patch/winwatch-custom-rate/readme | 1 + patch/winwatch-custom-rate/winwatch.c | 376 +++++++++++++++++++++++++++++ patch/winwatch-custom-rate/winwatch.c.orig | 372 ++++++++++++++++++++++++++++ 6 files changed, 751 insertions(+) create mode 100644 patch/winwatch-custom-rate/email create mode 100644 patch/winwatch-custom-rate/files create mode 100644 patch/winwatch-custom-rate/notes create mode 100644 patch/winwatch-custom-rate/readme create mode 100644 patch/winwatch-custom-rate/winwatch.c create mode 100644 patch/winwatch-custom-rate/winwatch.c.orig (limited to 'patch/winwatch-custom-rate') diff --git a/patch/winwatch-custom-rate/email b/patch/winwatch-custom-rate/email new file mode 100644 index 0000000..191feb6 --- /dev/null +++ b/patch/winwatch-custom-rate/email @@ -0,0 +1 @@ +john@ankarstrom.se diff --git a/patch/winwatch-custom-rate/files b/patch/winwatch-custom-rate/files new file mode 100644 index 0000000..f8d2281 --- /dev/null +++ b/patch/winwatch-custom-rate/files @@ -0,0 +1 @@ +/sys/src/cmd/winwatch.c winwatch.c diff --git a/patch/winwatch-custom-rate/notes b/patch/winwatch-custom-rate/notes new file mode 100644 index 0000000..e69de29 diff --git a/patch/winwatch-custom-rate/readme b/patch/winwatch-custom-rate/readme new file mode 100644 index 0000000..2c0fe29 --- /dev/null +++ b/patch/winwatch-custom-rate/readme @@ -0,0 +1 @@ +Add -r rate argument (default 2500 ms) diff --git a/patch/winwatch-custom-rate/winwatch.c b/patch/winwatch-custom-rate/winwatch.c new file mode 100644 index 0000000..4296b0e --- /dev/null +++ b/patch/winwatch-custom-rate/winwatch.c @@ -0,0 +1,376 @@ +#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; +Image *lightblue; +Image *statecol[4]; + +enum { + PAD = 3, + MARGIN = 5 +}; + +void* +erealloc(void *v, ulong n) +{ + v = realloc(v, n); + if(v == nil) + sysfatal("out of memory reallocating %lud", n); + return v; +} + +void* +emalloc(ulong n) +{ + void *v; + + v = malloc(n); + if(v == nil) + sysfatal("out of memory allocating %lud", n); + memset(v, 0, n); + return v; +} + +char* +estrdup(char *s) +{ + int l; + char *t; + + if (s == nil) + return nil; + l = strlen(s)+1; + t = emalloc(l); + memcpy(t, s, l); + + 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], 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; + + nw = 0; +/* i'd rather read one at a time but rio won't let me */ + while((nr=dirread(fd, &pd)) > 0){ + for(i=0; i= mwin){ + mwin += 8; + win = erealloc(win, mwin*sizeof(win[0])); + } + win[nw].n = n; + win[nw].label = estrdup(label); + win[nw].state = state; + win[nw].dirty = 1; + win[nw].r = Rect(0,0,0,0); + nw++; + } + free(pd); + } + while(nwin > nw) + free(win[--nwin].label); + nwin = nw; + close(fd); +} + +void +drawnowin(int i) +{ + Rectangle r; + + r = Rect(0,0,(Dx(screen->r)-2*MARGIN+PAD)/cols-PAD, font->height); + r = rectaddpt(rectaddpt(r, Pt(MARGIN+(PAD+Dx(r))*(i/rows), + MARGIN+(PAD+Dy(r))*(i%rows))), screen->r.min); + draw(screen, insetrect(r, -1), lightblue, nil, ZP); +} + +void +drawwin(int i) +{ + draw(screen, win[i].r, statecol[win[i].state], nil, ZP); + _string(screen, addpt(win[i].r.min, Pt(2,0)), display->black, ZP, + font, win[i].label, nil, strlen(win[i].label), + win[i].r, nil, ZP, SoverD); + border(screen, win[i].r, 1, display->black, ZP); + win[i].dirty = 0; +} + +int +geometry(void) +{ + int i, ncols, z; + Rectangle r; + + 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){ + cols = ncols; + z = 1; + } + } + + r = Rect(0,0,(Dx(screen->r)-2*MARGIN+PAD)/cols-PAD, font->height); + for(i=0; ir.min); + + return z; +} + +void +redraw(Image *screen, int all) +{ + int i; + + all |= geometry(); + if(all) + draw(screen, screen->r, lightblue, nil, ZP); + 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 +#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; +Image *lightblue; +Image *statecol[4]; + +enum { + PAD = 3, + MARGIN = 5 +}; + +void* +erealloc(void *v, ulong n) +{ + v = realloc(v, n); + if(v == nil) + sysfatal("out of memory reallocating %lud", n); + return v; +} + +void* +emalloc(ulong n) +{ + void *v; + + v = malloc(n); + if(v == nil) + sysfatal("out of memory allocating %lud", n); + memset(v, 0, n); + return v; +} + +char* +estrdup(char *s) +{ + int l; + char *t; + + if (s == nil) + return nil; + l = strlen(s)+1; + t = emalloc(l); + memcpy(t, s, l); + + 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], 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; + + nw = 0; +/* i'd rather read one at a time but rio won't let me */ + while((nr=dirread(fd, &pd)) > 0){ + for(i=0; i= mwin){ + mwin += 8; + win = erealloc(win, mwin*sizeof(win[0])); + } + win[nw].n = n; + win[nw].label = estrdup(label); + win[nw].state = state; + win[nw].dirty = 1; + win[nw].r = Rect(0,0,0,0); + nw++; + } + free(pd); + } + while(nwin > nw) + free(win[--nwin].label); + nwin = nw; + close(fd); +} + +void +drawnowin(int i) +{ + Rectangle r; + + r = Rect(0,0,(Dx(screen->r)-2*MARGIN+PAD)/cols-PAD, font->height); + r = rectaddpt(rectaddpt(r, Pt(MARGIN+(PAD+Dx(r))*(i/rows), + MARGIN+(PAD+Dy(r))*(i%rows))), screen->r.min); + draw(screen, insetrect(r, -1), lightblue, nil, ZP); +} + +void +drawwin(int i) +{ + draw(screen, win[i].r, statecol[win[i].state], nil, ZP); + _string(screen, addpt(win[i].r.min, Pt(2,0)), display->black, ZP, + font, win[i].label, nil, strlen(win[i].label), + win[i].r, nil, ZP, SoverD); + border(screen, win[i].r, 1, display->black, ZP); + win[i].dirty = 0; +} + +int +geometry(void) +{ + int i, ncols, z; + Rectangle r; + + 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){ + cols = ncols; + z = 1; + } + } + + r = Rect(0,0,(Dx(screen->r)-2*MARGIN+PAD)/cols-PAD, font->height); + for(i=0; ir.min); + + return z; +} + +void +redraw(Image *screen, int all) +{ + int i; + + all |= geometry(); + if(all) + draw(screen, screen->r, lightblue, nil, ZP); + 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