9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Jacob Moody <moody@mail.posixcafe.org>
To: 9front@9front.org
Subject: [9front] [PATCH] programmable menus for rio
Date: Tue, 23 Aug 2022 19:40:54 -0600	[thread overview]
Message-ID: <6b1146ca-e2de-88eb-d331-e1c978baf266@posixcafe.org> (raw)

Something I've been playing with is a way of exposing part of the rio
menu to the programs running within it. This is a bit of a simple
approach, but I would like to gauge interest that people have in
something along these lines before continuing.

This adds a /dev/menu file that can be written to
to add new entries to the button3menu. The file
can be read to get the text string of an added
menu entry when hit by the user.

Thanks,
moody


diff 8dcf65f21e079f471eef6d3b3d0360c7beac4cd6 uncommitted
--- a/sys/src/cmd/rio/dat.h
+++ b/sys/src/cmd/rio/dat.h
@@ -19,6 +19,7 @@
 	Qwsys,		/* directory of window directories */
 	Qwsysdir,		/* window directory, child of wsys */
 	Qtap,
+	Qmenu,

 	QMAX,
 };
@@ -326,6 +327,8 @@
 Channel *totap;		/* our keyboard input to tap program */
 Channel *wintap;	/* tell the tapthread which Window to send to */
 Window	*input;
+Channel *usermenu;
+Channel *userhit;
 QLock	all;			/* BUG */
 Filsys	*filsys;
 Window	*hidden[100];
--- a/sys/src/cmd/rio/fsys.c
+++ b/sys/src/cmd/rio/fsys.c
@@ -38,6 +38,7 @@
 	{ "window",	QTFILE,	Qwindow,		0400 },
 	{ "wsys",		QTDIR,	Qwsys,		0500|DMDIR },
 	{ "kbdtap",	QTFILE,	Qtap,	0660 },
+	{ "menu",	QTFILE,	Qmenu, 0660 },
 	{ nil, }
 };

--- a/sys/src/cmd/rio/rio.c
+++ b/sys/src/cmd/rio/rio.c
@@ -53,6 +53,7 @@
 	Delete,
 	Hide,
 	Exit,
+	Hidden,
 };

 enum
@@ -82,8 +83,6 @@
 	menu2str
 };

-int	Hidden = Exit+1;
-
 char		*menu3str[100] = {
  [New]		"New",
  [Reshape]	"Resize",
@@ -94,6 +93,9 @@
 			nil
 };

+char *userentry[64] = { nil };
+int nusermenu = 0;
+
 Menu menu3 =
 {
 	menu3str
@@ -193,6 +195,8 @@
 	if(mousectl == nil)
 		error("can't find mouse");
 	mouse = mousectl;
+	usermenu = chancreate(sizeof(char*), 0);
+	userhit = chancreate(sizeof(char*), 0);
 	kbdchan = initkbd();
 	if(kbdchan == nil)
 		error("can't find keyboard");
@@ -528,7 +532,9 @@
 mousethread(void*)
 {
 	int sending, inside, scrolling, moving;
+	int j;
 	Window *w, *winput;
+	char *s;
 	Image *i;
 	Point xy;
 	Mouse tmp;
@@ -535,6 +541,7 @@
 	enum {
 		MReshape,
 		MMouse,
+		MUser,
 		NALT
 	};
 	static Alt alts[NALT+1];
@@ -549,10 +556,24 @@
 	alts[MMouse].c = mousectl->c;
 	alts[MMouse].v = &mousectl->Mouse;
 	alts[MMouse].op = CHANRCV;
+	alts[MUser].c = usermenu;
+	alts[MUser].v = &s;
+	alts[MUser].op = CHANRCV;
 	alts[NALT].op = CHANEND;

 	for(;;)
 	    switch(alt(alts)){
+		case MUser:
+			if(strncmp("add ", s, 4) == 0){
+				if(s+4 != '\0')
+					userentry[nusermenu++] = strdup(s+4);
+			}else if(strncmp("reset", s, 5) == 0){
+				for(j=0; j < nusermenu; j++)
+					free(userentry[j]);
+				nusermenu=0;
+			}
+			free(s);
+			break;
 		case MReshape:
 			resized();
 			break;
@@ -771,7 +792,8 @@
 void
 button3menu(void)
 {
-	int i, j, n;
+	int i, j, n, u;
+	char *s;

 	n = nhidden;
 	for(i=0; i<nwindow; i++){
@@ -785,11 +807,15 @@
 					break;
 			}
 	}
-	if(n >= nelem(menu3str)-Hidden)
+	for(u=0; u < nusermenu; u++){
+		free(menu3str[u+Hidden]);
+		menu3str[u+Hidden] = strdup(userentry[u]);
+	}
+	if(n >= nelem(menu3str)-(Hidden+u))
 		n = nelem(menu3str)-Hidden-1;
-	for(i=0; i<n; i++){
+	for(i=u; i<n+u; i++){
 		free(menu3str[i+Hidden]);
-		menu3str[i+Hidden] = shortlabel(hidden[i]->label);
+		menu3str[i+Hidden] = shortlabel(hidden[i-u]->label);
 	}
 	for(i+=Hidden; menu3str[i]; i++){
 		free(menu3str[i]);
@@ -818,7 +844,13 @@
 		confirmexit();
 		break;
 	default:
-		unhide(i);
+		i -= Hidden;
+		if(i < u){
+			s = strdup(menu3str[i+Hidden]);
+			if(nbsendp(userhit, s) != 1)
+				free(s);
+		} else
+			unhide(i-u);
 		break;
 	}
 	sweeping = FALSE;
@@ -1202,9 +1234,6 @@
 {
 	Window *w;

-	if(j < Hidden)
-		return;
-	j -= Hidden;
 	w = hidden[j];
 	if(w == nil)
 		return;
--- a/sys/src/cmd/rio/xfid.c
+++ b/sys/src/cmd/rio/xfid.c
@@ -585,6 +585,15 @@
 		}
 		break;

+	case Qmenu:
+		if(x->data[cnt-1] == '\n'){
+			if(cnt == 1)
+				break;
+			x->data[cnt-1] = '\0';
+		}
+		chanprint(usermenu, "%.*s", cnt, x->data);
+		break;
+
 	default:
 		fprint(2, "unknown qid %d in write\n", qid);
 		filsysrespond(x->fs, x, &fc, "unknown qid in write");
@@ -864,6 +873,34 @@
 		}
 		free(t);
 		return;
+
+	case Qmenu:
+		alts[Adata].c = userhit;
+		alts[Adata].v = &t;
+		alts[Adata].op = CHANRCV;
+		alts[Agone].c = w->gone;
+		alts[Agone].v = nil;
+		alts[Agone].op = CHANRCV;
+		alts[Aflush].c = x->flushc;
+		alts[Aflush].v = nil;
+		alts[Aflush].op = CHANRCV;
+		alts[Aend].op = CHANEND;
+
+		switch(alt(alts)){
+		case Adata:
+			break;
+		case Agone:
+			filsysrespond(x->fs, x, &fc, Edeleted);
+			return;
+		case Aflush:
+			filsyscancel(x);
+			return;
+		}
+		fc.data = t;
+		fc.count = strlen(t);
+		filsysrespond(x->fs, x, &fc, nil);
+		free(t);
+		break;

 	default:
 		fprint(2, "unknown qid %d in read\n", qid);

             reply	other threads:[~2022-08-24  1:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-24  1:40 Jacob Moody [this message]
2022-08-24  2:46 ` ori
2022-08-24  5:02   ` Jacob Moody
2022-08-24  7:05     ` qwx
2022-08-24 13:38       ` Jacob Moody
2022-08-24 17:26         ` Michael Misch
2022-08-24 17:30           ` Stanley Lieber
2022-08-24 17:37           ` ori
2022-08-24 18:56             ` Lyndon Nerenberg (VE7TFX/VE6BBM)
2022-08-24 19:31               ` Stuart Morrow
2022-08-24 20:10                 ` Jacob Moody
2022-08-25  6:40                   ` Jacob Moody
2022-08-27  3:40                 ` ori
2022-08-27 13:30                   ` hiro
2022-08-27 14:23                     ` Mark van Atten
2022-08-27 17:22                       ` hiro
2022-08-24 20:04               ` ori
2022-08-24 20:17                 ` Stanley Lieber

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=6b1146ca-e2de-88eb-d331-e1c978baf266@posixcafe.org \
    --to=moody@mail.posixcafe.org \
    --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).