aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2020-06-17 14:08:38 +0000
committerrodri <rgl@antares-labs.eu>2020-06-17 14:08:38 +0000
commit6644b94ee7945f8a55238196e702f0c82f4a93c8 (patch)
tree2ab1675caeb9e4d87f24c625b4bcda41195ad869
parent30c2848b3550083a07ad00c1a7dac9b71e573b56 (diff)
downloadpuppeteer-6644b94ee7945f8a55238196e702f0c82f4a93c8.tar.gz
puppeteer-6644b94ee7945f8a55238196e702f0c82f4a93c8.tar.bz2
puppeteer-6644b94ee7945f8a55238196e702f0c82f4a93c8.zip
integrate color selection with sigrid's color picker.
also revert previous change. it was an stupid idea.
-rw-r--r--main.c46
1 files changed, 39 insertions, 7 deletions
diff --git a/main.c b/main.c
index 8535738..b450841 100644
--- a/main.c
+++ b/main.c
@@ -103,6 +103,25 @@ redraw(void)
unlockdisplay(display);
}
+static void
+pickerproc(void *arg)
+{
+ int *pfd;
+ char mntdesc[64];
+
+ pfd = arg;
+ close(pfd[1]);
+ dup(pfd[0], 0);
+ dup(pfd[0], 1);
+ close(pfd[0]);
+
+ snprint(mntdesc, sizeof mntdesc, "-pid %d -dx %d -dy %d", getpid(), 384, 320);
+ newwindow(mntdesc);
+
+ procexecl(nil, "/bin/picker", "picker", "-e", nil);
+ threadexits("procexecl: %r");
+}
+
static char*
genrmbmenuitem(int idx)
{
@@ -149,7 +168,7 @@ rmb(Mousectl *mc, Keyboardctl *kc)
};
static Menu menu = { .gen = genrmbmenuitem };
char buf[256], chanstr[9+1], *s;
- int w, h, idx, fd;
+ int w, h, idx, fd, n, pfd[2];
ulong chan;
Point2 cpos;
Layer *l;
@@ -184,9 +203,20 @@ rmb(Mousectl *mc, Keyboardctl *kc)
addlayer(curcanvas, buf);
break;
case SETCOLOR:
- if(enter("hex value", buf, sizeof buf, mc, kc, nil) <= 0)
+ if(pipe(pfd) < 0)
+ sysfatal("pipe: %r");
+ procrfork(pickerproc, pfd, 4096, RFFDG|RFNAMEG);
+ close(pfd[0]);
+ fprint(pfd[1], "0 %08ux\n", 0x000000ff);
+ n = read(pfd[1], buf, sizeof(buf)-1);
+ close(pfd[1]);
+ if(n < 0)
return;
- brushcolor = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, strtoul(buf, nil, 16));
+ buf[n] = 0;
+ s = buf;
+ while(*s && *s++ != '\t')
+ ;
+ brushcolor = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, strtoul(s, nil, 16));
break;
case SAVE:
if(curcanvas == nil)
@@ -205,10 +235,12 @@ rmb(Mousectl *mc, Keyboardctl *kc)
}
idx -= NITEMS;
- l = curcanvas->layers.next;
- while(l != &curcanvas->layers && idx--)
- l = l->next;
- curcanvas->curlayer = l;
+ if(idx >= 0){
+ l = curcanvas->layers.next;
+ while(l != &curcanvas->layers && idx--)
+ l = l->next;
+ curcanvas->curlayer = l;
+ }
}
void