9front - general discussion about 9front
 help / color / mirror / Atom feed
From: sirjofri+ml-9front@sirjofri.de
To: 9front@9front.org
Subject: [9front] patch: tweak plumb support
Date: Fri, 04 Dec 2020 11:30:51 +0100	[thread overview]
Message-ID: <137DF02E627D6015D5E98F0EC84C6847@sirjofri.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 563 bytes --]

Hello all,

this patch enables basic plumbing in tweak.

Tweak listens to plumb channel 'imageedit' and opens the files (currently only paths are supported, no action=showdata).

Furthermore, while reading data from files a message is printed in the footer and all input events are removed from the stack afterwards. This results in blocked input while loading. Without this adjustment, the image is loaded and every input event is queued until loading is done, resulting in multiple 'open' prompts, for example.

Feel free to test, submit, comment.

sirjofri

.

[-- Attachment #2: Type: text/plain, Size: 2243 bytes --]

diff -r 73caf2698436 sys/src/cmd/tweak.c
--- a/sys/src/cmd/tweak.c	Tue Dec 01 09:23:16 2020 +0100
+++ b/sys/src/cmd/tweak.c	Fri Dec 04 11:23:24 2020 +0100
@@ -3,8 +3,11 @@
 #include <draw.h>
 #include <cursor.h>
 #include <event.h>
+#include <plumb.h>
 #include <bio.h>
 
+#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,11 +176,22 @@
 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;
 	Event e;
 	Thing *t;
+	Plumbmsg *pm;
 
 	mag = Mag;
 	if(initdraw(error, 0, "tweak") < 0){
@@ -190,6 +205,7 @@
 			drawerror(display, "can't allocate image");
 	}
 	einit(Emouse|Ekeyboard);
+	eplumb(Eplumb, "imageedit");
 	eresized(0);
 	i = 1;
 	setjmp(err);
@@ -214,6 +230,42 @@
 			}
 			if(mouse.buttons & 4)
 				menu();
+			break;
+		case Eplumb:
+			pm = e.v;
+			if(pm->ndata == 0)
+				break;
+			file = malloc(pm->ndata+1);
+			if(file == 0){
+				mesg("malloc failed: %r");
+				goto Err;
+			}
+			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 = malloc(strlen(pm->wdir) + strlen(pm->data) + 2);
+				if(file == 0){
+					mesg("malloc failed: %r");
+					goto Err;
+				}
+	
+				strcpy(file, pm->wdir);
+				file[strlen(pm->wdir)] = '/';
+				strcpy(file+strlen(pm->wdir)+1, pm->data);
+			}
+			t = tget(file);
+			if(t)
+				drawthing(t, 1);
+			flushimage(display, 1);
+			file = 0;
+		   Err:
+			plumbfree(pm);
 		}
 }
 
@@ -531,6 +583,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 +615,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);

             reply	other threads:[~2020-12-04 10:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-04 10:30 sirjofri+ml-9front [this message]
2020-12-04 10:47 ` sirjofri+ml-9front
2020-12-05 15:13   ` sirjofri+ml-9front
2020-12-07  9:44     ` sirjofri+ml-9front
2020-12-07 15:43       ` ori
2020-12-07 20:26         ` sirjofri+ml-9front
2020-12-21 15:34           ` sirjofri+ml-9front
2021-01-12 10:12 sirjofri
2021-01-13 22:06 ` ori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=137DF02E627D6015D5E98F0EC84C6847@sirjofri.de \
    --to=sirjofri+ml-9front@sirjofri.de \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).