11 static void fail(const char *m) {
12 fprintf(stderr,"error: %s\n", m);
16 static void badusage(void) { fail("bad usage"); }
20 static int width, height;
21 static GC gc_green, gc_red, gc_yellow, gc_blue;
28 static void refresh(void);
30 static void geometry(void) {
34 XGetGeometry(d,w, &dummyw,&dummy,&dummy, &width,&height, &dummy,&dummy);
38 static void show(double fill_norm, double ratepersec_norm, int ac) {
42 for (i=0; i<height; i++) {
45 TOP * exp( (double)i / (height-2) * log( (double)BOTTOM/TOP ) );
47 then= fill_norm + ratepersec_norm * elap;
49 leftmost_lit= then <= 0 ? -1 :
53 if (leftmost_lit >= 0)
54 XDrawLine(d, w, ac ? gc_blue : gc_green, 0,i, leftmost_lit,i);
55 if (leftmost_lit < width)
56 XDrawLine(d, w, then >= 0 ? gc_red : gc_yellow,
57 leftmost_lit+1,i, width,i);
61 static void refresh(void) {
62 show(0.3, 0.5/3600, 1);
65 static void colour(GC *gc_r, const char *name) {
70 st= XAllocNamedColor(d,cmap,name,&xc,&xc);
71 if (!st) fail("couldn't allocate colour");
75 gcv.foreground= xc.pixel;
76 *gc_r= XCreateGC(d,w, GCFunction|GCForeground|GCLineWidth, &gcv);
79 int main(int argc, const char *const *argv) {
82 d= XOpenDisplay(0); if (!d) fail("could not open display");
84 if (!argv[0] || argv[1])
87 screen= DefaultScreen(d);
89 w= XCreateSimpleWindow(d,DefaultRootWindow(d),0,0,100,20,0,0,0);
91 cmap= DefaultColormap(d,screen);
93 colour(&gc_green, "green");
94 colour(&gc_red, "red");
95 colour(&gc_yellow, "yellow");
96 colour(&gc_blue, "blue");
98 XSelectInput(d,w, ExposureMask|VisibilityChangeMask);