From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 15863 invoked from network); 5 Dec 2020 15:15:51 -0000 Received: from ewsd.inri.net (107.191.116.128) by inbox.vuxu.org with ESMTPUTF8; 5 Dec 2020 15:15:51 -0000 Received: from oat.nine.sirjofri.de ([5.45.105.127]) by ewsd; Sat Dec 5 10:13:40 -0500 2020 Message-ID: <48FC1DE9CD68A9B79FFC032531CB979C@sirjofri.de> To: 9front@9front.org Date: Sat, 05 Dec 2020 16:13:38 +0100 From: sirjofri+ml-9front@sirjofri.de In-Reply-To: <25016D827DDA2E082CC7E8046529D473@sirjofri.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-qvrxvwjwvztsknykdmckadbaxz" List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: CSS plugin Subject: Re: [9front] patch: tweak plumb support Reply-To: 9front@9front.org Precedence: bulk This is a multi-part message in MIME format. --upas-qvrxvwjwvztsknykdmckadbaxz Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hello, this version adds experimental plumb support for direct file data (action=showdata). It just creates temporary files in /tmp/tweaktmp.XXX, and does currently not clean the files after closing (this could also be considered a feature). The patch also includes adjustments to the man page. If you want to test it, you need to "create" the imageedit channel: echo plumb to imageedit >> /mnt/plumb/rules sirjofri . --upas-qvrxvwjwvztsknykdmckadbaxz Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit diff -r bdf5af28b857 sys/man/1/tweak --- a/sys/man/1/tweak Fri Dec 04 09:33:55 2020 +0100 +++ b/sys/man/1/tweak Sat Dec 05 16:04:47 2020 +0100 @@ -155,6 +155,18 @@ Quit .IR tweak . The program will complain once about modified but unwritten files. +.PP +.I Tweak +listens to the +.I plumber +channel +.B imageedit +for filenames as well as image data. Plumbed image data is stored as files in +.B /tmp +and is +.I not +cleaned after exiting +.IR tweak . .SH SOURCE .B /sys/src/cmd/tweak.c .SH "SEE ALSO" diff -r bdf5af28b857 sys/src/cmd/tweak.c --- a/sys/src/cmd/tweak.c Fri Dec 04 09:33:55 2020 +0100 +++ b/sys/src/cmd/tweak.c Sat Dec 05 16:04:47 2020 +0100 @@ -3,8 +3,11 @@ #include #include #include +#include #include +#define Eplumb 128 + typedef struct Thing Thing; struct Thing @@ -157,6 +160,7 @@ int but1val = 0; int but2val = 255; int invert = 0; +int blockinput = 0; Image *values[256]; Image *greyvalues[256]; uchar data[8192]; @@ -172,12 +176,24 @@ void tclose1(Thing*); void +flushevents(ulong keys) +{ + Event e; + if(keys == 0) + return; + while(ecanread(keys)) + eread(keys, &e); +} + +void main(int argc, char *argv[]) { - int i; + int i, n; Event e; Thing *t; + Plumbmsg *pm; + srand(time(0)); mag = Mag; if(initdraw(error, 0, "tweak") < 0){ fprint(2, "tweak: initdraw failed: %r\n"); @@ -190,6 +206,7 @@ drawerror(display, "can't allocate image"); } einit(Emouse|Ekeyboard); + eplumb(Eplumb, "imageedit"); eresized(0); i = 1; setjmp(err); @@ -214,6 +231,62 @@ } if(mouse.buttons & 4) menu(); + break; + case Eplumb: + pm = e.v; + if(pm->ndata == 0) + break; + if(strcmp(plumblookup(pm->attr, "action"), "showdata") == 0){ + n = 0; + Tmpretry: + file = smprint("/tmp/tweaktmp.%d", rand()); + if(file == 0){ + mesg("malloc failed: %r"); + goto Plumbout; + } + i = create(file, OWRITE|OEXCL, 0600); + if(i == 0){ + free(file); + if(n++ < 10) + goto Tmpretry; + else{ + mesg("cannot create tmpfiles: too many attempts"); + goto Plumberrout; + } + } + if(write(i, pm->data, pm->ndata) != pm->ndata){ + mesg("error writing tmpfile: %r"); + close(i); + free(file); + goto Plumberrout; + } + close(i); + goto Plumbout; + } + file = malloc(pm->ndata+1); + if(file == 0){ + mesg("malloc failed: %r"); + goto Plumberrout; + } + strncpy(file, pm->data, pm->ndata); + file[pm->ndata] = 0; + free(pm->data); + pm->data = file; + switch(pm->data[0]){ + case '/': + file = pm->data; + break; + default: + file = smprint("%s/%s", pm->wdir, pm->data); + } + Plumbout: + t = tget(file); + if(t) + drawthing(t, 1); + flushimage(display, 1); + file = 0; + Plumberrout: + plumbfree(pm); } } @@ -531,6 +604,12 @@ nt->tr.max.y = nt->tr.min.y + nl; nt->er.max.y = nt->tr.max.y + Border; text(nt); + + mesg(""); + if(blockinput){ + flushevents(Emouse|Ekeyboard); + blockinput = 0; + } } int @@ -557,6 +636,9 @@ uchar buf[256]; char *data; + mesg("reading %s", file); + blockinput = 1; + buf[0] = '\0'; errstr((char*)buf, sizeof buf); /* flush pending error message */ memmove(oerr, err, sizeof err); --upas-qvrxvwjwvztsknykdmckadbaxz--