History

a few fixes and a "snarf all" menu option

Sigrid Haflínudóttir committed 6 years ago

Commit 29e9efb1 parent 35d64482 files · +47 −22Browse files

Unified · Split

2 files
  1. README.md +15 −2
  2. picker.c +32 −20
README.md+15−2
@@ -1,4 +1,17 @@
1# picker1# picker
2 2
3HSLuv color picker for Plan 9.3Color picker for Plan 9. It has HSLuv, HPLuv, and RGB color space
4It's WIP so the code look horrible and doesn't make any sense right now.4modes and is intended to be used mainly by external programs that need
5a way to change their color palette.
6
7## Installing
8
9```
10cd /tmp && \
11hget https://github.com/ftrvxmtrx/picker/archive/master.tar.gz | tar xz && \
12cd picker-master && mk install
13```
14
15## Documentation
16
17See the man page.
picker.c+32−20
@@ -109,8 +109,9 @@ static Space spaces[] = { · 108 unmodified lines
109 },109 },
110};110};
111 111
112static char *menu2i[nelem(spaces)+2] = {112static char *menu2i[nelem(spaces)+3] = {
113 "snarf",113 "snarf",
114 "snarf all",
114};115};
115static Menu menu2 = { .item = menu2i };116static Menu menu2 = { .item = menu2i };
116 117
@@ -184,6 +185,12 @@ slider(int si, int w) · 67 unmodified lines
184 return s;185 return s;
185}186}
186 187
188static int
189color2str(Color *c, char *s)
190{
191 return nchan > 3 ? sprint(s, "%08lux", c->u) : sprint(s, "%06lux", c->u>>8);
192}
193
187static void194static void
188redraw(void)195redraw(void)
189{196{
@@ -242,10 +249,7 @@ redraw(void) · 52 unmodified lines
242 draw(screen, r, colors[curcolor].i, nil, ZP);249 draw(screen, r, colors[curcolor].i, nil, ZP);
243 250
244 /* current color in hex */251 /* current color in hex */
245 if (nchan > 3)252 color2str(&colors[curcolor], hex);
246 sprint(hex, "%08lux", colors[curcolor].u);
247 else
248 sprint(hex, "%06lux", colors[curcolor].u>>8);
249 r.min.x += Dx(r)/2 - stringwidth(font, hex)/2;253 r.min.x += Dx(r)/2 - stringwidth(font, hex)/2;
250 r.min.y += Dy(r)/2 - font->height/2;254 r.min.y += Dy(r)/2 - font->height/2;
251 stringbg(screen, r.min, display->white, ZP, font, hex, display->black, ZP);255 stringbg(screen, r.min, display->white, ZP, font, hex, display->black, ZP);
@@ -351,6 +355,7 @@ threadmain(int argc, char **argv) · 99 unmodified lines
351 Color *c;355 Color *c;
352 int i, once;356 int i, once;
353 ulong u;357 ulong u;
358 char buf[16];
354 359
355 space = &spaces[0];360 space = &spaces[0];
356 nchan = 3;361 nchan = 3;
@@ -391,7 +396,7 @@ threadmain(int argc, char **argv) · 34 unmodified lines
391 }396 }
392 397
393 for (i = 0; i < nelem(spaces); i++)398 for (i = 0; i < nelem(spaces); i++)
394 menu2i[i+1] = spaces[i].name;399 menu2i[i+2] = spaces[i].name;
395 400
396 if (initdraw(nil, nil, "picker") < 0)401 if (initdraw(nil, nil, "picker") < 0)
397 sysfatal("initdraw: %r");402 sysfatal("initdraw: %r");
@@ -461,26 +466,33 @@ changed: · 63 unmodified lines
461 goto next;466 goto next;
462 }467 }
463 }468 }
464 } else if (m.buttons == 2) {469 } else if (m.buttons == 2 && (i = menuhit(2, mctl, &menu2, nil)) >= 0) {
465 if ((i = menuhit(2, mctl, &menu2, nil)) >= 0) {470 if (i >= 2) {
471 space = &spaces[i-2];
472 space->fromrgb(c->rgba, c->v);
473 for (i = 0; i < 3; i++)
474 c->v[i] = MAX(0.0, MIN(space->max[i], c->v[i]));
475 goto changed;
476 }
477
478 int f;
479 if ((f = open("/dev/snarf", OWRITE)) >= 0) {
466 if (i == 0) {480 if (i == 0) {
467 int f;481 write(f, hex, strlen(hex));
468 if ((f = open("/dev/snarf", OWRITE)) >= 0) {
469 write(f, hex, strlen(hex));
470 close(f);
471 }
472 } else {482 } else {
473 space = &spaces[i];483 for (i = 0; i < ncolors; i++) {
474 space->fromrgb(c->rgba, c->v);484 write(f, buf, color2str(&colors[i], buf));
475 for (i = 0; i < 3; i++)485 if (i != ncolors-1)
476 c->v[i] = MAX(0.0, MIN(space->max[i], c->v[i]));486 write(f, " ", 1);
477 goto changed;487 }
478 }488 }
489 close(f);
479 }490 }
480 } else if (m.buttons == 4) {491 } else if (m.buttons == 4) {
481 if (enter(nchan < 4 ? "rgb:" : "rgba:", hex+1, sizeof(hex)-1, mctl, kctl, nil) > 0) {492 strcpy(buf, hex);
493 if (enter(nchan < 4 ? "rgb:" : "rgba:", buf, sizeof(buf), mctl, kctl, nil) > 0) {
482 u = c->u;494 u = c->u;
483 if (str2color(hex+1, c) == 0 && c->u != u) {495 if (str2color(buf, c) == 0 && c->u != u) {
484 c->u = ~c->u; /* just for the update to kick in */496 c->u = ~c->u; /* just for the update to kick in */
485 goto changed;497 goto changed;
486 }498 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t