From ea390adc72dc10795b3e09cc9e569dd3b572528d Mon Sep 17 00:00:00 2001 From: ianmdlvl Date: Wed, 8 Dec 2004 03:01:42 +0000 Subject: [PATCH] @@ -2,6 +2,7 @@ machinery or docs (could do with --help too). + * xacpi-simple work in progress. --- cprogs/.cvsignore | 1 + cprogs/Makefile | 5 +- cprogs/xacpi-simple.c | 118 ++++++++++++++++++++++++++++++++++++++++++ debian/changelog | 1 + 4 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 cprogs/xacpi-simple.c diff --git a/cprogs/.cvsignore b/cprogs/.cvsignore index 720cd81..545d6c7 100644 --- a/cprogs/.cvsignore +++ b/cprogs/.cvsignore @@ -3,3 +3,4 @@ writebuffer trivsoundd really with-lock-ex +xacpi-simple diff --git a/cprogs/Makefile b/cprogs/Makefile index f584470..1f557ce 100644 --- a/cprogs/Makefile +++ b/cprogs/Makefile @@ -25,7 +25,7 @@ include ../settings.make RWBUFFER_SIZE_MB=16 -PROGRAMS= readbuffer writebuffer with-lock-ex +PROGRAMS= readbuffer writebuffer with-lock-ex xacpi-simple SUIDSBINPROGRAMS= really DAEMONS= trivsoundd MAN1PAGES= readbuffer.1 writebuffer.1 with-lock-ex.1 @@ -43,6 +43,9 @@ really: really.o myopt.o really.o myopt.o: myopt.h readbuffer.o writebuffer.o rwbuffer.o wrbufcore.o trivsoundd.o: rwbuffer.h +xacpi-simple: xacpi-simple.o + $(CC) -o $@ $< -L/usr/X11R6/lib -lX11 -lm + install: all $(INSTALL_DIRECTORY) $(bindir) $(sbindir) $(INSTALL_PROGRAM) $(PROGRAMS) $(bindir) diff --git a/cprogs/xacpi-simple.c b/cprogs/xacpi-simple.c new file mode 100644 index 0000000..96ba105 --- /dev/null +++ b/cprogs/xacpi-simple.c @@ -0,0 +1,118 @@ +/* + */ + +#include +#include +#include +#include + +#include + +static void fail(const char *m) { + fprintf(stderr,"error: %s\n", m); + sleep(5); + exit(-1); +} +static void badusage(void) { fail("bad usage"); } + +static Display *d; +static Window w; +static int width, height; +static GC gc_green, gc_red, gc_yellow, gc_blue; +static Colormap cmap; +static int screen; + +#define TOP 60 +#define BOTTOM 3600 + +static void refresh(void); + +static void geometry(void) { + int dummy; + Window dummyw; + + XGetGeometry(d,w, &dummyw,&dummy,&dummy, &width,&height, &dummy,&dummy); + refresh(); +} + +static void show(double fill_norm, double ratepersec_norm, int ac) { + double elap, then; + int i, leftmost_lit; + + for (i=0; i= 1.0 ? width : + width * then; + +fprintf(stderr," width=%d height=%d i=%d elap=%f then=%f leftmost_lit=%d\n", + (unsigned long)w, + width,height,i,then,leftmost_lit); + if (leftmost_lit >= 0) + XDrawLine(d, w, ac ? gc_blue : gc_green, 0,i, leftmost_lit,i); + if (leftmost_lit < width) + XDrawLine(d, w, then >= 0 ? gc_red : gc_yellow, + leftmost_lit+1,i, width,i); + } +} + +static void refresh(void) { + show(0.3, 0.5/3600, 1); +} + +static void colour(GC *gc_r, const char *name) { + XColor xc; + Status st; + XGCValues gcv; + + st= XAllocNamedColor(d,cmap,name,&xc,&xc); + if (!st) fail("couldn't allocate colour"); + + gcv.function= GXcopy; + gcv.line_width= 1; + gcv.foreground= xc.pixel; + *gc_r= XCreateGC(d,w, GCFunction|GCForeground|GCLineWidth, &gcv); +} + +int main(int argc, const char *const *argv) { + const char *windowid_string; + char *ep; + XEvent ev; + + d= XOpenDisplay(0); if (!d) fail("could not open display"); + + if (!argv[0] || argv[1]) + badusage(); + + /* if (!(windowid_string= getenv("WINDOWID"))) + badusage(); w= strtoul(windowid_string,&ep,0); + if (*ep) badusage(); + +*/ + + screen= DefaultScreen(d); + + w= XCreateSimpleWindow(d,DefaultRootWindow(d),0,0,50,50,0,0,0); + + cmap= DefaultColormap(d,screen); + + colour(&gc_green, "green"); + colour(&gc_red, "darkred"); + colour(&gc_yellow, "yellow"); + colour(&gc_blue, "blue"); + + XSelectInput(d,w, ExposureMask|VisibilityChangeMask); + XMapWindow(d,w); + + geometry(); + + for (;;) { + XNextEvent(d,&ev); + geometry(); + } +} diff --git a/debian/changelog b/debian/changelog index ee8ca8b..cd3220f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,7 @@ chiark-utils (4.0.99.0.8) unstable; urgency=low * New `random-word' script found lying about; checked in but no build machinery or docs (could do with --help too). + * xacpi-simple work in progress. -- -- 2.30.2