| @@ -10,6 +10,7 @@ · 9 unmodified lines |
| 10 | 10 | #include <plumb.h> |
| 11 | 11 | #include <cursor.h> |
| 12 | 12 | #include <tos.h> |
| 13 | +#include "theme.h" |
| 13 | 14 | |
| 14 | 15 | #define MIN(x,y) ((x)<=(y)?(x):(y)) |
| 15 | 16 | #define MAX(x,y) ((x)>=(y)?(x):(y)) |
| @@ -45,17 +46,6 @@ enum { · 29 unmodified lines |
| 45 | 46 | Menu3exit, |
| 46 | 47 | Nummenu3, |
| 47 | 48 | |
| 48 | | − Dback = 0, |
| 49 | | − Dfhigh, |
| 50 | | − Dfmed, |
| 51 | | − Dflow, |
| 52 | | − Dfinv, |
| 53 | | − Dbhigh, |
| 54 | | − Dbmed, |
| 55 | | − Dblow, |
| 56 | | − Dbinv, |
| 57 | | − Numcolors, |
| 58 | | − |
| 59 | 49 | /* this might become a bad idea in the future */ |
| 60 | 50 | Mark_flag_group_highlight = 1<<6, |
| 61 | 51 | Mark_flag_selected = 1<<7, |
| @@ -143,23 +133,6 @@ static struct { · 81 unmodified lines |
| 143 | 133 | }, |
| 144 | 134 | }; |
| 145 | 135 | |
| 146 | | −static struct { |
| 147 | | − char *id; |
| 148 | | − u32int color; |
| 149 | | −}theme[Numcolors] = { |
| 150 | | − [Dback] = {"background", 0x000000}, |
| 151 | | − [Dfhigh] = {"f_high", 0xffffff}, |
| 152 | | − [Dfmed] = {"f_med", 0x777777}, |
| 153 | | − [Dflow] = {"f_low", 0x444444}, |
| 154 | | − [Dfinv] = {"f_inv", 0x000000}, |
| 155 | | − [Dbhigh] = {"b_high", 0xdddddd}, |
| 156 | | − [Dbmed] = {"b_med", 0x72dec2}, |
| 157 | | − [Dblow] = {"b_low", 0x222222}, |
| 158 | | − [Dbinv] = {"b_inv", 0xffb545}, |
| 159 | | −}; |
| 160 | | − |
| 161 | | −static Image *color[Numcolors]; |
| 162 | | − |
| 163 | 136 | static char *modes[Nummodes] = { |
| 164 | 137 | [Minsert] = "insert", |
| 165 | 138 | [Mappend] = "append", |
| @@ -596,10 +569,10 @@ redraw(int complete) · 430 unmodified lines |
| 596 | 569 | if (complete) { |
| 597 | 570 | r = screen->r; |
| 598 | 571 | r.max.y = r.min.y + txtoff.y; |
| 599 | | − draw(screen, r, color[Dback], nil, ZP); |
| 572 | + draw(screen, r, colors[Dback].im, nil, ZP); |
| 600 | 573 | r = screen->r; |
| 601 | 574 | r.max.x = r.min.x + txtoff.x; |
| 602 | | − draw(screen, r, color[Dback], nil, ZP); |
| 575 | + draw(screen, r, colors[Dback].im, nil, ZP); |
| 603 | 576 | } |
| 604 | 577 | |
| 605 | 578 | off = field.width*cur.y + cur.x; |
| @@ -636,7 +609,7 @@ redraw(int complete) · 30 unmodified lines |
| 636 | 609 | |
| 637 | 610 | if (!grouphl && !complete && c == fscr.buffer[off] && attr == mscr.buffer[off]) { |
| 638 | 611 | if (i > 0) { |
| 639 | | − p = runestringnbg(screen, p, color[oldfg], ZP, font, linebuf, i, color[oldbg], ZP); |
| 612 | + p = runestringnbg(screen, p, colors[oldfg].im, ZP, font, linebuf, i, colors[oldbg].im, ZP); |
| 640 | 613 | i = 0; |
| 641 | 614 | } |
| 642 | 615 | p.x += glyphsz.x; |
| @@ -687,43 +660,43 @@ redraw(int complete) · 44 unmodified lines |
| 687 | 660 | } |
| 688 | 661 | |
| 689 | 662 | if (bg != oldbg || fg != oldfg) { |
| 690 | | − p = runestringnbg(screen, p, color[oldfg], ZP, font, linebuf, i, color[oldbg], ZP); |
| 663 | + p = runestringnbg(screen, p, colors[oldfg].im, ZP, font, linebuf, i, colors[oldbg].im, ZP); |
| 691 | 664 | i = 0; |
| 692 | 665 | } |
| 693 | 666 | linebuf[i++] = c; |
| 694 | 667 | } |
| 695 | | − runestringnbg(screen, p, color[fg], ZP, font, linebuf, i, color[bg], ZP); |
| 668 | + runestringnbg(screen, p, colors[fg].im, ZP, font, linebuf, i, colors[bg].im, ZP); |
| 696 | 669 | p.y += glyphsz.y; |
| 697 | 670 | } |
| 698 | 671 | |
| 699 | 672 | r = screen->r; |
| 700 | 673 | r.min.x += txtoff.x + max.x*glyphsz.x; |
| 701 | | − draw(screen, r, color[Dback], nil, ZP); |
| 674 | + draw(screen, r, colors[Dback].im, nil, ZP); |
| 702 | 675 | |
| 703 | 676 | r = screen->r; |
| 704 | 677 | r.min.y += txtoff.y + max.y*glyphsz.y; |
| 705 | | − draw(screen, r, color[Dback], nil, ZP); |
| 678 | + draw(screen, r, colors[Dback].im, nil, ZP); |
| 706 | 679 | |
| 707 | 680 | p = top; |
| 708 | 681 | p.y += glyphsz.y*(max.y-1)/2; |
| 709 | 682 | if (scroll.x > 0) { |
| 710 | 683 | p.x = top.x - txtoff.x; |
| 711 | | − string(screen, p, color[Dfmed], ZP, font, "←"); |
| 684 | + string(screen, p, colors[Dfmed].im, ZP, font, "←"); |
| 712 | 685 | } |
| 713 | 686 | if (max.x+scroll.x < field.width) { |
| 714 | 687 | p.x = top.x + max.x*glyphsz.x + txtoff.x - glyphsz.x; |
| 715 | | − string(screen, p, color[Dfmed], ZP, font, "→"); |
| 688 | + string(screen, p, colors[Dfmed].im, ZP, font, "→"); |
| 716 | 689 | } |
| 717 | 690 | |
| 718 | 691 | p = top; |
| 719 | 692 | p.x += glyphsz.x*(max.x-1)/2; |
| 720 | 693 | if (scroll.y > 0) { |
| 721 | 694 | p.y = screen->r.min.y; |
| 722 | | − string(screen, p, color[Dfmed], ZP, font, "↑"); |
| 695 | + string(screen, p, colors[Dfmed].im, ZP, font, "↑"); |
| 723 | 696 | } |
| 724 | 697 | if (max.y+scroll.y < field.height) { |
| 725 | 698 | p.y = top.y + max.y*glyphsz.y; |
| 726 | | − string(screen, p, color[Dfmed], ZP, font, "↓"); |
| 699 | + string(screen, p, colors[Dfmed].im, ZP, font, "↓"); |
| 727 | 700 | } |
| 728 | 701 | |
| 729 | 702 | i = 0; |
| @@ -741,7 +714,7 @@ redraw(int complete) · 11 unmodified lines |
| 741 | 714 | i += runesprint(linebuf+i, "%-9s", s); |
| 742 | 715 | sprint(s, "%ldms", labs(framedev)); |
| 743 | 716 | i += runesprint(linebuf+i, "%-8s", s); |
| 744 | | − runestringn(screen, bot, color[Dfhigh], ZP, font, linebuf, i); |
| 717 | + runestringn(screen, bot, colors[Dfhigh].im, ZP, font, linebuf, i); |
| 745 | 718 | bot.y += glyphsz.y; |
| 746 | 719 | |
| 747 | 720 | i = 0; |
| @@ -752,12 +725,18 @@ redraw(int complete) · 4 unmodified lines |
| 752 | 725 | i += runesprint(linebuf+i, "%-9s", s); |
| 753 | 726 | i += runesprint(linebuf+i, "%-9s", modes[altdown ? Mslide : mode]); |
| 754 | 727 | i += runesprint(linebuf+i, "%s", filename[0] ? filename : "unnamed"); |
| 755 | | − runestringn(screen, bot, color[Dfhigh], ZP, font, linebuf, i); |
| 728 | + runestringn(screen, bot, colors[Dfhigh].im, ZP, font, linebuf, i); |
| 756 | 729 | |
| 757 | 730 | flushimage(display, 1); |
| 758 | 731 | unlockdisplay(display); |
| 759 | 732 | } |
| 760 | 733 | |
| 734 | +void |
| 735 | +themechanged(void) |
| 736 | +{ |
| 737 | + redraw(1); |
| 738 | +} |
| 739 | + |
| 761 | 740 | static void |
| 762 | 741 | command(char *s, void (*snapshot)(void)) |
| 763 | 742 | { |
| @@ -815,7 +794,7 @@ command(char *s, void (*snapshot)(void)) · 51 unmodified lines |
| 815 | 794 | } else if (s[0] == 'c' && s[1] == 'o') { /* color ffffff 111111 232323 ... */ |
| 816 | 795 | if (argc < 2) { |
| 817 | 796 | for (i = 0; i < Numcolors; i++) |
| 818 | | − print("%06x ", theme[i].color); |
| 797 | + print("%06x ", colors[i].rgb); |
| 819 | 798 | print("\n"); |
| 820 | 799 | fflush(stdout); |
| 821 | 800 | } else { |
| @@ -825,9 +804,9 @@ command(char *s, void (*snapshot)(void)) · 3 unmodified lines |
| 825 | 804 | continue; |
| 826 | 805 | if ((im = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, c<<8 | 0xff)) == nil) |
| 827 | 806 | continue; |
| 828 | | − freeimage(color[i-1]); |
| 829 | | − theme[i-1].color = c; |
| 830 | | − color[i-1] = im; |
| 807 | + freeimage(colors[i-1].im); |
| 808 | + colors[i-1].rgb = c; |
| 809 | + colors[i-1].im = im; |
| 831 | 810 | } |
| 832 | 811 | unlockdisplay(display); |
| 833 | 812 | redraw(1); |
| @@ -1168,88 +1147,6 @@ plumbproc(void *) · 334 unmodified lines |
| 1168 | 1147 | threadexits(nil); |
| 1169 | 1148 | } |
| 1170 | 1149 | |
| 1171 | | −static void |
| 1172 | | −runpicker(void *x) |
| 1173 | | −{ |
| 1174 | | − int *p, wfd; |
| 1175 | | − char *wsys; |
| 1176 | | − char tmp[64]; |
| 1177 | | − |
| 1178 | | − if ((wsys = getenv("wsys")) == nil) { |
| 1179 | | − fprint(2, "wsys not set\n"); |
| 1180 | | − goto err; |
| 1181 | | − } |
| 1182 | | − if ((wfd = open(wsys, ORDWR)) < 0) { |
| 1183 | | − fprint(2, "can't open wsys: %r\n"); |
| 1184 | | − goto err; |
| 1185 | | − } |
| 1186 | | − |
| 1187 | | − snprint(tmp, sizeof(tmp), "new -pid %d -dx %d -dy %d", getpid(), 384, 320); |
| 1188 | | − |
| 1189 | | − if (mount(wfd, -1, "/mnt/wsys", MREPL, tmp) < 0) { |
| 1190 | | − fprint(2, "couldn't mount wsys: %r\n"); |
| 1191 | | − goto err; |
| 1192 | | − } |
| 1193 | | − if (bind("/mnt/wsys", "/dev", MBEFORE) < 0) { |
| 1194 | | − fprint(2, "couldn't bind wsys: %r\n"); |
| 1195 | | − goto err; |
| 1196 | | − } |
| 1197 | | − |
| 1198 | | − p = x; |
| 1199 | | − dup(p[0], 0); close(p[0]); close(p[1]); |
| 1200 | | − dup(p[3], 1); close(p[3]); close(p[2]); |
| 1201 | | − dup(open("/dev/null", OWRITE), 2); |
| 1202 | | − procexecl(nil, "/bin/picker", "picker", nil); |
| 1203 | | − |
| 1204 | | −err: |
| 1205 | | − threadexits("exec: %r"); |
| 1206 | | −} |
| 1207 | | − |
| 1208 | | −static void |
| 1209 | | −colorsproc(void *) |
| 1210 | | −{ |
| 1211 | | − Biobuf *in, *out; |
| 1212 | | − char *s, *v[3]; |
| 1213 | | − int p[4], n, i; |
| 1214 | | − |
| 1215 | | − threadsetname("colorsproc"); |
| 1216 | | − pipe(p); |
| 1217 | | − pipe(p+2); |
| 1218 | | − procrfork(runpicker, p, 4096, RFFDG|RFNAMEG); |
| 1219 | | − close(p[0]); |
| 1220 | | − close(p[3]); |
| 1221 | | − out = Bfdopen(p[1], OWRITE); |
| 1222 | | − in = Bfdopen(p[2], OREAD); |
| 1223 | | − |
| 1224 | | − for (i = 0; i < nelem(theme); i++) |
| 1225 | | − Bprint(out, "%s\t%06ux\n", theme[i].id, theme[i].color); |
| 1226 | | − Bterm(out); |
| 1227 | | − |
| 1228 | | − for (;;) { |
| 1229 | | − if ((s = Brdstr(in, '\n', 1)) == nil) |
| 1230 | | − break; |
| 1231 | | − if ((n = tokenize(s, v, nelem(v))) == 2) { |
| 1232 | | − for (i = 0; i < nelem(theme); i++) { |
| 1233 | | − if (strcmp(theme[i].id, v[0]) == 0) { |
| 1234 | | − lockdisplay(display); |
| 1235 | | − freeimage(color[i]); |
| 1236 | | − theme[i].color = strtoul(v[1], nil, 16); |
| 1237 | | − color[i] = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[i].color<<8 | 0xff); |
| 1238 | | − unlockdisplay(display); |
| 1239 | | − redraw(1); |
| 1240 | | − break; |
| 1241 | | − } |
| 1242 | | − } |
| 1243 | | − } |
| 1244 | | − free(s); |
| 1245 | | − if (n != 2) |
| 1246 | | − break; |
| 1247 | | − } |
| 1248 | | − Bterm(in); |
| 1249 | | − |
| 1250 | | − threadexits(nil); |
| 1251 | | −} |
| 1252 | | − |
| 1253 | 1150 | static void |
| 1254 | 1151 | kbdproc(void *cchan) |
| 1255 | 1152 | { |
| @@ -1357,7 +1254,7 @@ threadmain(int argc, char **argv) · 101 unmodified lines |
| 1357 | 1254 | Point p; |
| 1358 | 1255 | char tmp[256]; |
| 1359 | 1256 | char cmd[256]; |
| 1360 | | − int oldw, oldh, w, h, n, oldbuttons; |
| 1257 | + int oldw, oldh, w, h, n, oldbuttons, themetid; |
| 1361 | 1258 | long seed; |
| 1362 | 1259 | bool complete; |
| 1363 | 1260 | Alt a[Numchan+1] = { |
| @@ -1464,8 +1361,8 @@ threadmain(int argc, char **argv) · 100 unmodified lines |
| 1464 | 1361 | |
| 1465 | 1362 | proccreate(stdinproc, nil, mainstacksize); |
| 1466 | 1363 | |
| 1467 | | − for (n = 0; n < Numcolors; n++) |
| 1468 | | − color[n] = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, theme[n].color<<8 | 0xff); |
| 1364 | + themeinit(); |
| 1365 | + |
| 1469 | 1366 | glyphsz.x = stringwidth(font, "@"); |
| 1470 | 1367 | glyphsz.y = font->height; |
| 1471 | 1368 | |
| @@ -1496,6 +1393,7 @@ threadmain(int argc, char **argv) · 24 unmodified lines |
| 1496 | 1393 | move.y = 1; |
| 1497 | 1394 | oldbuttons = 0; |
| 1498 | 1395 | cmd[0] = 0; |
| 1396 | + themetid = -1; |
| 1499 | 1397 | |
| 1500 | 1398 | netdial(nil, nil); |
| 1501 | 1399 | midiopen(nil); |
| @@ -1570,7 +1468,7 @@ noredraw: · 68 unmodified lines |
| 1570 | 1468 | } else if (n == Menu3rulerstyle) { |
| 1571 | 1469 | rulerstyle = ++rulerstyle % Numstyles; |
| 1572 | 1470 | } else if (n == Menu3colors) { |
| 1573 | | − proccreate(colorsproc, nil, mainstacksize); |
| 1471 | + themetid = proccreate(themeproc, nil, 4096); |
| 1574 | 1472 | } else if (n == Menu3exit) { |
| 1575 | 1473 | setcursor(mctl, &yousure); |
| 1576 | 1474 | for (;;) { |
| @@ -1840,6 +1738,7 @@ noredraw: · 263 unmodified lines |
| 1840 | 1738 | } |
| 1841 | 1739 | |
| 1842 | 1740 | end: |
| 1741 | + threadint(themetid); |
| 1843 | 1742 | chanclose(a[Ckey].c); |
| 1844 | 1743 | chanclose(a[Credraw].c); |
| 1845 | 1744 | mbuf_reusable_deinit(&mscr); |