ref: 4af9aa84c706c45398c4c7d1b9e96fa814a45dc0
parent: d9b4a120f0c7d48e2901361eb6faa9704ca2d608
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Jun 17 10:32:14 EDT 2020
simplify picker logic since picker is loading colors dynamically now
--- a/theme.c
+++ b/theme.c
@@ -26,15 +26,15 @@
runpicker(void *x)
{
int *p, f;
- char tmp[64];
+ char tmp[32];
- snprint(tmp, sizeof(tmp), "new -pid %d -dx %d -dy %d", getpid(), 384, 320);
+ snprint(tmp, sizeof(tmp), "-pid %d -dx %d -dy %d", getpid(), 384, 320);
newwindow(tmp);
p = x;
- dup(p[0], 0); close(p[0]); close(p[1]);
- dup(p[3], 1); close(p[3]); close(p[2]);
- f = open("/dev/null", OWRITE); dup(f, 2); close(f);
+ dup(*p, 0); dup(*p, 1); close(*p);
+ close(p[1]);
+ dup(f = open("/dev/null", OWRITE), 2); close(f);
procexecl(nil, "/bin/picker", "picker", nil);
threadexits("exec: %r");
@@ -43,27 +43,23 @@
static void
themeproc(void *)
{
- Biobuf *in, *out;
+ Biobuf *b;
char *s, *v[3];
- int p[4], n, i;
+ int p[2], n, i;
threadsetname("themeproc");
pipe(p);
- pipe(p+2);
procrfork(runpicker, p, 4096, RFFDG|RFNAMEG);
close(p[0]);
- close(p[3]);
- out = Bfdopen(p[1], OWRITE);
- in = Bfdopen(p[2], OREAD);
+ b = Bfdopen(p[1], OREAD);
for(i = 0; i < nelem(colors); i++)
- Bprint(out, "%s\t%06ux\n", colors[i].id, colors[i].rgb);
- Bterm(out);
+ fprint(p[1], "%s\t%06ux\n", colors[i].id, colors[i].rgb);
for(;;){
- if((s = Brdstr(in, '\n', 1)) == nil)
+ if((s = Brdstr(b, '\n', 1)) == nil)
break;
- if((n = tokenize(s, v, nelem(v))) == 2){
+ if((n = tokenize(s, v, nelem(v))) >= 2){
for(i = 0; i < nelem(colors); i++){
if(strcmp(colors[i].id, v[0]) == 0){
if(display->locking)
@@ -82,7 +78,7 @@
if(n != 2)
break;
}
- Bterm(in);
+ Bterm(b);
threadexits(nil);
}