21 Keyboardctl *keyboardctl;
23 void keyboardthread(void*);
24 void mousethread(void*);
25 void resizethread(void*);
34 return (i<<16)+(i<<8)+i;
46 threadmain(int argc, char *argv[])
53 fmt = "index %3d r %3lud g %3lud b %3lud 0x%.8luX ";
58 fmt = "index %2luX r %3luX g %3luX b %3luX 0x%.8luX ";
67 fprint(2, "Usage: %s [-rx]\n", argv0);
68 threadexitsall("usage");
71 if(initdraw(0, nil, "colors") < 0)
72 sysfatal("initdraw failed: %r");
74 mousectl = initmouse(nil, display->image);
76 sysfatal("initmouse: %r");
78 keyboardctl = initkeyboard(nil);
79 if(keyboardctl == nil)
80 sysfatal("initkeyboard: %r");
84 if(screen->chan == CMAP8){
85 /* dither the fine grey */
87 dark = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (grey(j)<<8)+0xFF);
88 color[i] = allocimage(display, Rect(0,0,4,4), screen->chan, 1, (grey(j+17)<<8)+0xFF);
92 if(dither[j] > (i%17))
93 draw(color[i], Rect(k, l, k+1, l+1), dark, nil, ZP);
97 color[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (grey(i)<<8)+0xFF);
99 color[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (cmap2rgb(i)<<8)+0xFF);
101 sysfatal("can't allocate image: %r");
104 threadcreate(mousethread, nil, STACK);
105 threadcreate(keyboardthread, nil, STACK);
106 threadcreate(resizethread, nil, STACK);
110 keyboardthread(void *v)
116 while(recv(keyboardctl->c, &r) >= 0)
141 while(readmouse(mousectl) >= 0){
146 if(screen->depth > 8)
149 n = 1<<screen->depth;
151 if(i!=prev && ptinrect(m.xy, crect[i])){
162 p = addpt(screen->r.min, Pt(2,2));
163 draw(screen, Rpt(p, addpt(p, stringsize(font, buf))), display->white, nil, p);
164 string(screen, p, display->black, ZP, font, buf);
174 switch(menuhit(3, mousectl, &menu, nil)){
185 int x, y, i, n, nx, ny;
188 if(new && getwindow(display, Refnone) < 0){
189 fprint(2, "colors: can't reattach to window: %r\n");
190 threadexitsall("resized");
192 if(screen->depth > 8){
196 n = 1<<screen->depth;
197 nx = 1<<(screen->depth/2);
201 draw(screen, screen->r, display->white, nil, ZP);
202 r = insetrect(screen->r, 5);
205 for(i=n-1, y=0; y!=ny; y++){
207 b.max.y=r.min.y+(r.max.y-r.min.y)*(y+1)/ny;
209 for(x=0; x!=nx; x++, --i){
211 b.max.x=r.min.x+(r.max.x-r.min.x)*(x+1)/nx;
212 crect[i]=insetrect(b, 1);
213 draw(screen, crect[i], color[i], nil, ZP);
216 flushimage(display, 1);
220 resizethread(void *v)
227 while(recv(mousectl->resizec, &x) >= 0)