shithub: orca

Download patch

ref: 85497628f1036f7d26057fa38e63afb941119d38
parent: a93d7290f6d49317413fe60b7badb60cc7e97fe4
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun Mar 15 20:49:56 EDT 2020

plan9: change for new picker logic

--- a/plan9.c
+++ b/plan9.c
@@ -48,7 +48,9 @@
 	Dfmed,
 	Dflow,
 	Dfinv,
+	Dbhigh,
 	Dbmed,
+	Dblow,
 	Dbinv,
 	Numcolors,
 
@@ -124,14 +126,19 @@
 	},
 };
 
-static u32int theme[Numcolors] = {
-	[Dback] = 0x000000ff,
-	[Dfhigh] = 0xffffffff,
-	[Dfmed] = 0x777777ff,
-	[Dflow] = 0x272727ff,
-	[Dfinv] = 0x000000ff,
-	[Dbmed] = 0x72dec2ff,
-	[Dbinv] = 0xffb545ff,
+static struct {
+	char *id;
+	u32int color;
+}theme[Numcolors] = {
+	[Dback]  = {"background", 0x000000},
+	[Dfhigh] = {"f_high",     0xffffff},
+	[Dfmed]  = {"f_med",      0x777777},
+	[Dflow]  = {"f_low",      0x444444},
+	[Dfinv]  = {"f_inv",      0x000000},
+	[Dbhigh] = {"b_high",     0xdddddd},
+	[Dbmed]  = {"b_med",      0x72dec2},
+	[Dblow]  = {"b_low",      0x222222},
+	[Dbinv]  = {"b_inv",      0xffb545},
 };
 
 static Image *color[Numcolors];
@@ -811,7 +818,7 @@
 	} else if (s[0] == 'c' && s[1] == 'o') { /* color ffffff 111111 232323 ... */
 		if (argc < 2) {
 			for (i = 0; i < Numcolors; i++)
-				print("%06x ", theme[i]>>8);
+				print("%06x ", theme[i].color);
 			print("\n");
 			fflush(stdout);
 		} else {
@@ -819,11 +826,10 @@
 			for (i = 1; i < Numcolors+1 && i < argc; i++) {
 				if ((c = strtoul(argv[i], &s, 16)) == 0 && s == argv[i])
 					continue;
-				c = c<<8 | 0xff;
-				if ((im = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, c)) == nil)
+				if ((im = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, c<<8 | 0xff)) == nil)
 					continue;
 				freeimage(color[i-1]);
-				theme[i-1] = c;
+				theme[i-1].color = c;
 				color[i-1] = im;
 			}
 			unlockdisplay(display);
@@ -1166,9 +1172,8 @@
 static void
 runpicker(void *x)
 {
-	int *p, i, a, wfd;
-	char *args[1+Numcolors+1], *wsys;
-	char colors[Numcolors][8];
+	int *p, wfd;
+	char *wsys;
 	char tmp[64];
 
 	if ((wsys = getenv("wsys")) == nil) {
@@ -1191,19 +1196,11 @@
 		goto err;
 	}
 
-	a = 0;
-	args[a++] = "picker";
-	for (i = 0; i < Numcolors; i++) {
-		sprint(colors[i], "%06x", theme[i]>>8);
-		args[a++] = colors[i];
-	}
-	args[a] = nil;
-
 	p = x;
-	close(0);
-	dup(p[1], 1); close(p[1]); close(p[0]);
+	dup(p[0], 0); close(p[0]); close(p[1]);
+	dup(p[3], 1); close(p[3]); close(p[2]);
 	dup(open("/dev/null", OWRITE), 2);
-	procexec(nil, "/bin/picker", args);
+	procexecl(nil, "/bin/picker", "picker", nil);
 
 err:
 	threadexits("exec: %r");
@@ -1212,25 +1209,38 @@
 static void
 colorsproc(void *)
 {
-	Biobuf *in;
+	Biobuf *in, *out;
 	char *s, *v[3];
 	int p[4], n, i;
 
 	threadsetname("colorsproc");
 	pipe(p);
+	pipe(p+2);
 	procrfork(runpicker, p, 4096, RFFDG|RFNAMEG);
-	close(p[1]);
-	in = Bfdopen(p[0], OREAD);
+	close(p[0]);
+	close(p[3]);
+	out = Bfdopen(p[1], OWRITE);
+	in = Bfdopen(p[2], OREAD);
+
+	for (i = 0; i < nelem(theme); i++)
+		Bprint(out, "%s\t%06ux\n", theme[i].id, theme[i].color);
+	Bterm(out);
+
 	for (;;) {
 		if ((s = Brdstr(in, '\n', 1)) == nil)
 			break;
-		if ((n = tokenize(s, v, nelem(v))) == 2 && (i = atoi(v[0])) >= 0 && i < Numcolors) {
-			lockdisplay(display);
-			freeimage(color[i]);
-			theme[i] = strtoul(v[1], nil, 16);
-			color[i] = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[i]<<8 | 0xff);
-			unlockdisplay(display);
-			redraw(1);
+		if ((n = tokenize(s, v, nelem(v))) == 2) {
+			for (i = 0; i < nelem(theme); i++) {
+				if (strcmp(theme[i].id, v[0]) == 0) {
+					lockdisplay(display);
+					freeimage(color[i]);
+					theme[i].color = strtoul(v[1], nil, 16);
+					color[i] = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[i].color<<8 | 0xff);
+					unlockdisplay(display);
+					redraw(1);
+					break;
+				}
+			}
 		}
 		free(s);
 		if (n != 2)
@@ -1456,7 +1466,7 @@
 	proccreate(stdinproc, nil, mainstacksize);
 
 	for (n = 0; n < Numcolors; n++)
-		color[n] = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[n]);
+		color[n] = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[n].color<<8 | 0xff);
 	glyphsz.x = stringwidth(font, "@");
 	glyphsz.y = font->height;