| @@ -109,8 +109,9 @@ static Space spaces[] = { · 108 unmodified lines |
| 109 | 109 | }, |
| 110 | 110 | }; |
| 111 | 111 | |
| 112 | | −static char *menu2i[nelem(spaces)+2] = { |
| 112 | +static char *menu2i[nelem(spaces)+3] = { |
| 113 | 113 | "snarf", |
| 114 | + "snarf all", |
| 114 | 115 | }; |
| 115 | 116 | static Menu menu2 = { .item = menu2i }; |
| 116 | 117 | |
| @@ -184,6 +185,12 @@ slider(int si, int w) · 67 unmodified lines |
| 184 | 185 | return s; |
| 185 | 186 | } |
| 186 | 187 | |
| 188 | +static int |
| 189 | +color2str(Color *c, char *s) |
| 190 | +{ |
| 191 | + return nchan > 3 ? sprint(s, "%08lux", c->u) : sprint(s, "%06lux", c->u>>8); |
| 192 | +} |
| 193 | + |
| 187 | 194 | static void |
| 188 | 195 | redraw(void) |
| 189 | 196 | { |
| @@ -242,10 +249,7 @@ redraw(void) · 52 unmodified lines |
| 242 | 249 | draw(screen, r, colors[curcolor].i, nil, ZP); |
| 243 | 250 | |
| 244 | 251 | /* current color in hex */ |
| 245 | | − if (nchan > 3) |
| 246 | | − sprint(hex, "%08lux", colors[curcolor].u); |
| 247 | | − else |
| 248 | | − sprint(hex, "%06lux", colors[curcolor].u>>8); |
| 252 | + color2str(&colors[curcolor], hex); |
| 249 | 253 | r.min.x += Dx(r)/2 - stringwidth(font, hex)/2; |
| 250 | 254 | r.min.y += Dy(r)/2 - font->height/2; |
| 251 | 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 | 355 | Color *c; |
| 352 | 356 | int i, once; |
| 353 | 357 | ulong u; |
| 358 | + char buf[16]; |
| 354 | 359 | |
| 355 | 360 | space = &spaces[0]; |
| 356 | 361 | nchan = 3; |
| @@ -391,7 +396,7 @@ threadmain(int argc, char **argv) · 34 unmodified lines |
| 391 | 396 | } |
| 392 | 397 | |
| 393 | 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 | 401 | if (initdraw(nil, nil, "picker") < 0) |
| 397 | 402 | sysfatal("initdraw: %r"); |
| @@ -461,26 +466,33 @@ changed: · 63 unmodified lines |
| 461 | 466 | goto next; |
| 462 | 467 | } |
| 463 | 468 | } |
| 464 | | − } else if (m.buttons == 2) { |
| 465 | | − if ((i = menuhit(2, mctl, &menu2, nil)) >= 0) { |
| 469 | + } else if (m.buttons == 2 && (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 | 480 | if (i == 0) { |
| 467 | | − int f; |
| 468 | | − if ((f = open("/dev/snarf", OWRITE)) >= 0) { |
| 469 | | − write(f, hex, strlen(hex)); |
| 470 | | − close(f); |
| 471 | | − } |
| 481 | + write(f, hex, strlen(hex)); |
| 472 | 482 | } else { |
| 473 | | − space = &spaces[i]; |
| 474 | | − space->fromrgb(c->rgba, c->v); |
| 475 | | − for (i = 0; i < 3; i++) |
| 476 | | − c->v[i] = MAX(0.0, MIN(space->max[i], c->v[i])); |
| 477 | | − goto changed; |
| 483 | + for (i = 0; i < ncolors; i++) { |
| 484 | + write(f, buf, color2str(&colors[i], buf)); |
| 485 | + if (i != ncolors-1) |
| 486 | + write(f, " ", 1); |
| 487 | + } |
| 478 | 488 | } |
| 489 | + close(f); |
| 479 | 490 | } |
| 480 | 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 | 494 | u = c->u; |
| 483 | | − if (str2color(hex+1, c) == 0 && c->u != u) { |
| 495 | + if (str2color(buf, c) == 0 && c->u != u) { |
| 484 | 496 | c->u = ~c->u; /* just for the update to kick in */ |
| 485 | 497 | goto changed; |
| 486 | 498 | } |