ref: 4672956489ed9c9aed2ba9f9772af56f5e88eeea
parent: 6ef0a92a0038d3853e20ece01e5529b5bfb1fc64
author: Sigrid Haflínudóttir <[email protected]>
date: Wed Jun 17 10:27:06 EDT 2020
don't wait until all colors are loaded before the program draws
--- a/picker.c
+++ b/picker.c
@@ -18,6 +18,7 @@
Ckey,
Cmouse,
Cresize,
+ Cloaded,
Numchan,
Offset = 6,
@@ -118,6 +119,7 @@
static Menu menu2 = { .item = menu2i };
static Color *colors, *color, *last;
+static Channel *loaded;
static int ncolors;
static Rectangle srects[3];
static Space *space;
@@ -375,12 +377,14 @@
}
static void
-readcolors(Biobuf *b)
+readcolors(void *x)
{
Color *c, *new;
+ Biobuf *b;
char *s;
int i, n;
+ b = x;
new = nil;
for (i = 1; (s = Brdstr(b, '\n', 1)) != nil; i++) {
if (new == nil)
@@ -394,6 +398,7 @@
continue;
}
+ lockdisplay(display);
for (c = colors; c != nil; c = c->next) {
if (strcmp(c->id, new->id) == 0) {
free(c->id);
@@ -404,19 +409,23 @@
}
}
- if (c != nil)
- continue;
+ if (c == nil) {
+ if (last != nil)
+ last->next = new;
+ new->prev = last;
+ last = new;
- if (last != nil)
- last->next = new;
- new->prev = last;
- last = new;
+ if (colors == nil)
+ colors = color = new;
+ new = nil;
+ ncolors++;
+ }
- if (colors == nil)
- colors = new;
- new = nil;
- ncolors++;
+ unlockdisplay(display);
+ sendul(loaded, 0);
}
+ Bterm(b);
+ threadexits(nil);
}
static void
@@ -433,12 +442,8 @@
{
Biobuf *b;
- if ((b = Bopen(filename, OREAD)) != nil) {
- lockdisplay(display);
- readcolors(b);
- unlockdisplay(display);
- Bterm(b);
- }
+ if ((b = Bopen(filename, OREAD)) != nil)
+ proccreate(readcolors, b, 4096);
}
static void
@@ -451,7 +456,6 @@
if ((f = plumbopen("picker", OREAD)) >= 0) {
while ((m = plumbrecv(f)) != nil) {
loadtheme(m->data);
- redraw();
dump(1);
plumbfree(m);
}
@@ -473,6 +477,7 @@
[Ckey] = { nil, &r, CHANRCV },
[Cmouse] = { nil, &m, CHANRCV },
[Cresize] = { nil, nil, CHANRCV },
+ [Cloaded] = { nil, nil, CHANRCV },
{ nil, nil, CHANEND },
};
int i, once, oldbuttons, slider;
@@ -508,11 +513,7 @@
b = argc == 1 ? Bopen(argv[0], OREAD) : Bfdopen(0, OREAD);
if (b == nil)
sysfatal("no colors: %r");
- readcolors(b);
- if (ncolors < 1)
- sysfatal("no colors");
- Bterm(b);
- color = colors;
+ loaded = chancreate(sizeof(ulong), 0);
for (i = 0; i < nelem(spaces); i++)
menu2i[i] = spaces[i].name;
@@ -529,13 +530,14 @@
sysfatal("initmouse: %r");
a[Cmouse].c = mctl->c;
a[Cresize].c = mctl->resizec;
+ a[Cloaded].c = loaded;
display->locking = 1;
unlockdisplay(display);
loadbg();
- redraw();
slider = -1;
- proccreate(plumbproc, nil, mainstacksize);
+ proccreate(readcolors, b, 4096);
+ proccreate(plumbproc, nil, 4096);
for (;;) {
next:
@@ -547,6 +549,8 @@
goto end;
case Ckey:
+ if (c == nil)
+ break;
switch (r) {
case Kleft:
if (c->prev != nil)
@@ -564,6 +568,8 @@
break;
case Cmouse:
+ if (c == nil)
+ break;
if (m.buttons == 1) {
m.xy.x = MAX(screen->r.min.x, MIN(screen->r.max.x, m.xy.x));
for (i = 0; i < c->nchan; i++) {
@@ -629,6 +635,11 @@
case Cresize:
getwindow(display, Refnone);
+ if (color != nil)
+ redraw();
+ break;
+
+ case Cloaded:
redraw();
break;
}