21 Keyboardctl *keyboardctl;
23 void keyboardthread(void*);
24 void mousethread(void*);
25 void resizethread(void*);
34 return (i<<16)+(i<<8)+i;
45 extern int chattydrawclient;
48 threadmain(int argc, char *argv[])
55 fmt = "index %3d r %3lud g %3lud b %3lud 0x%.8luX ";
63 fmt = "index %2luX r %3luX g %3luX b %3luX 0x%.8luX ";
72 fprint(2, "Usage: %s [-rx]\n", argv0);
73 threadexitsall("usage");
76 if(initdraw(0, nil, "colors") < 0)
77 sysfatal("initdraw failed: %r");
79 mousectl = initmouse(nil, display->image);
81 sysfatal("initmouse: %r");
83 keyboardctl = initkeyboard(nil);
84 if(keyboardctl == nil)
85 sysfatal("initkeyboard: %r");
89 if(screen->chan == CMAP8){
90 /* dither the fine grey */
92 dark = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (grey(j)<<8)+0xFF);
93 color[i] = allocimage(display, Rect(0,0,4,4), screen->chan, 1, (grey(j+17)<<8)+0xFF);
97 if(dither[j] > (i%17))
98 draw(color[i], Rect(k, l, k+1, l+1), dark, nil, ZP);
102 color[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (grey(i)<<8)+0xFF);
104 color[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (cmap2rgb(i)<<8)+0xFF);
106 sysfatal("can't allocate image: %r");
109 threadcreate(mousethread, nil, STACK);
110 threadcreate(keyboardthread, nil, STACK);
111 threadcreate(resizethread, nil, STACK);
115 keyboardthread(void *v)
121 while(recv(keyboardctl->c, &r) >= 0)
146 while(readmouse(mousectl) >= 0){
151 if(screen->depth > 8)
154 n = 1<<screen->depth;
156 if(i!=prev && ptinrect(m.xy, crect[i])){
167 p = addpt(screen->r.min, Pt(2,2));
168 draw(screen, Rpt(p, addpt(p, stringsize(font, buf))), display->white, nil, p);
169 string(screen, p, display->black, ZP, font, buf);
179 switch(menuhit(3, mousectl, &menu, nil)){
190 int x, y, i, n, nx, ny;
193 if(new && getwindow(display, Refnone) < 0){
194 fprint(2, "colors: can't reattach to window: %r\n");
195 threadexitsall("resized");
197 if(screen->depth > 8){
201 n = 1<<screen->depth;
202 nx = 1<<(screen->depth/2);
206 draw(screen, screen->r, display->white, nil, ZP);
207 r = insetrect(screen->r, 5);
210 for(i=n-1, y=0; y!=ny; y++){
212 b.max.y=r.min.y+(r.max.y-r.min.y)*(y+1)/ny;
214 for(x=0; x!=nx; x++, --i){
216 b.max.x=r.min.x+(r.max.x-r.min.x)*(x+1)/nx;
217 crect[i]=insetrect(b, 1);
218 draw(screen, crect[i], color[i], nil, ZP);
221 flushimage(display, 1);
225 resizethread(void *v)
232 while(recv(mousectl->resizec, &x) >= 0)