chiark / gitweb /
@@ -2,6 +2,7 @@
authorianmdlvl <ianmdlvl>
Wed, 8 Dec 2004 03:01:42 +0000 (03:01 +0000)
committerianmdlvl <ianmdlvl>
Wed, 8 Dec 2004 03:01:42 +0000 (03:01 +0000)
     machinery or docs (could do with --help too).
+  * xacpi-simple work in progress.

cprogs/.cvsignore
cprogs/Makefile
cprogs/xacpi-simple.c [new file with mode: 0644]
debian/changelog

index 720cd81c216398d729b0a29e129cb1e97c11e38f..545d6c7fed46f41835396f8ca221cf95a42009bf 100644 (file)
@@ -3,3 +3,4 @@ writebuffer
 trivsoundd
 really
 with-lock-ex
+xacpi-simple
index f584470e55da284b99b70cb0f339a70a4cbadd39..1f557ce9222142af4e86e9bf00b70768d178feed 100644 (file)
@@ -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 (file)
index 0000000..96ba105
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ */
+
+#include <stdio.h>
+#include <math.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <X11/Xlib.h>
+
+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<height; i++) {
+    elap= !i ? 0 :
+      height==2 ? BOTTOM :
+      TOP * exp( (double)i / (height-2) * log( (double)BOTTOM/TOP ) );
+    
+    then= fill_norm + ratepersec_norm * elap;
+
+    leftmost_lit= then <= 0 ? -1 :
+      then >= 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();
+  }
+}
index ee8ca8bad52e3dd655e602abd718f71f8e3e102a..cd3220f02fd60b491ea46dec701fb9b1ea46c246 100644 (file)
@@ -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.
 
  --