shithub: orca

Download patch

ref: e32c016f59ac58b204c1345359ad5c7743f1f73b
parent: 95aa7eb86bc157c28e419968bddc397a3d5117c2
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Feb 17 06:41:04 EST 2020

plan9: don't use mctl on enter()

--- a/plan9.c
+++ b/plan9.c
@@ -809,7 +809,6 @@
 	Keyboardctl kctl;
 	Mouse m;
 	char tmp[256];
-	Channel *kchan;
 	int oldw, oldh, w, h, n;
 	int movex, movey;
 	bool shiftdown, complete, ctldown;
@@ -824,10 +823,6 @@
 
 	USED(argc, argv);
 
-	kchan = chancreate(sizeof(Key), 20);
-	cchan = chancreate(sizeof(Rune), 20);
-	proccreate(kbdproc, kchan, mainstacksize);
-
 	srand(time(0));
 	threadsetname("orca/draw");
 
@@ -835,16 +830,17 @@
 		sysfatal("initdraw: %r");
 	if ((mctl = initmouse(nil, screen)) == nil)
 		sysfatal("initmouse: %r");
-	kctl.c = cchan;
-	kctl.file = "/dev/null";
-	kctl.consfd = kctl.pid = kctl.ctlfd = -1;
 
+	cchan = chancreate(sizeof(Rune), 20);
 	a[Cchar].c = cchan;
-	a[Ckey].c = kchan;
+	a[Ckey].c = chancreate(sizeof(Key), 20);
 	a[Cmouse].c = mctl->c;
 	a[Cresize].c = mctl->resizec;
 	a[Credraw].c = chancreate(sizeof(ulong), 0);
 
+	proccreate(kbdproc, a[Ckey].c, mainstacksize);
+	kctl.c = cchan;
+
 	for (n = 0; n < Numcolors; n++)
 		color[n] = allocimage(display, Rect(0, 0, 1, 1), RGBA32, 1, setalpha(theme[n] & ~0xff, theme[n] & 0xff));
 	charw = stringwidth(font, "X");
@@ -880,6 +876,9 @@
 
 noredraw:
 		switch (alt(a)) {
+		case -1:
+			goto end;
+
 		case Cmouse:
 			if (m.buttons == 4) {
 				menu3i[Menu3dotstyle] = tmp;
@@ -888,7 +887,7 @@
 				n = menuhit(3, mctl, &menu3, nil);
 				if (n == Menu3load || n == Menu3save) {
 					strncpy(tmp, filename, sizeof(tmp));
-					if (enter(n == Menu3load ? "load from:" : "save to:", tmp, sizeof(tmp), mctl, &kctl, nil) > 0) {
+					if (enter(n == Menu3load ? "load from:" : "save to:", tmp, sizeof(tmp), nil, &kctl, nil) > 0) {
 						if (n == Menu3load && fieldload(tmp) == 0) {
 							w = field.width;
 							h = field.height;
@@ -1024,7 +1023,7 @@
 				tmp[0] = 0;
 				if (filename[0])
 					fieldsave(filename);
-				else if (enter("file path:", tmp, sizeof(tmp), mctl, &kctl, nil) > 0 && fieldsave(tmp) == 0)
+				else if (enter("file path:", tmp, sizeof(tmp), nil, &kctl, nil) > 0 && fieldsave(tmp) == 0)
 					strncpy(filename, tmp, sizeof(filename));
 				break;
 			case 0x18: /* C-x */
@@ -1077,7 +1076,7 @@
 				break;
 			case Kstx:
 				tmp[0] = 0;
-				if (enter("command:", tmp, sizeof(tmp), mctl, &kctl, nil) > 0)
+				if (enter("command:", tmp, sizeof(tmp), nil, &kctl, nil) > 0)
 					command(tmp);
 				break;
 			case Kesc:
@@ -1145,6 +1144,8 @@
 	}
 
 end:
+	chanclose(a[Ckey].c);
+	chanclose(a[Credraw].c);
 	mbuf_reusable_deinit(&mscr);
 	field_deinit(&copyfield);
 	field_deinit(&selfield);