From: ianmdlvl Date: Sun, 12 Dec 2004 00:39:04 +0000 (+0000) Subject: internal connection numbers thing which does not work - but much other works X-Git-Tag: debian_version_4_0_99_0_12~11 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=commitdiff_plain;h=19e7df93e79d45a3082e4cf1347351540f615894 internal connection numbers thing which does not work - but much other works --- diff --git a/cprogs/xacpi-simple.c b/cprogs/xacpi-simple.c index 1b80df7..37a2e31 100644 --- a/cprogs/xacpi-simple.c +++ b/cprogs/xacpi-simple.c @@ -24,11 +24,14 @@ #include #include +#include #include #include #include +#define TIMEOUT 5000 /* milliseconds */ + /*---------- general utility stuff and declarations ----------*/ static void fail(const char *m) { @@ -300,8 +303,10 @@ static void initacquire(void) { C(green) \ C(cyan) \ C(grey) \ - C(darkmagenta) \ + C(darkmagenta) \ + C(white) \ GC(remain) \ + GC(white) \ GC(empty) static Display *disp; @@ -354,7 +359,7 @@ static void setforeground(Gcstate *g, unsigned long px) { static void show(void) { double elap, then; - int i, leftmost_lit, leftmost_nondeg; + int i, leftmost_lit, leftmost_nondeg, beyond, first_beyond; if (!charging_state_mask) { setbackground(pix_darkmagenta); @@ -373,23 +378,33 @@ static void show(void) { setforeground(&gc_empty, alarm_level ? pix_red : pix_black); - for (i=0; i=nondegraded_norm)); + if (then <= 0.0) then= 0.0; else if (then >= nondegraded_norm) then= nondegraded_norm; leftmost_lit= width * then; leftmost_nondeg= width * nondegraded_norm; - if (leftmost_lit < leftmost_nondeg) - XDrawLine(disp, win, gc_empty.gc, - leftmost_lit,i, leftmost_nondeg,i); - if (leftmost_lit >= 0) - XDrawLine(disp, win, gc_remain.gc, 0,i, leftmost_lit,i); + if (beyond && first_beyond) { + XDrawLine(disp, win, gc_white.gc, 0,i, leftmost_nondeg,i); + first_beyond= 0; + } else { + if (leftmost_lit < leftmost_nondeg) + XDrawLine(disp, win, gc_empty.gc, + leftmost_lit,i, leftmost_nondeg,i); + if (leftmost_lit >= 0) + XDrawLine(disp, win, gc_remain.gc, 0,i, leftmost_lit,i); + } } } @@ -399,7 +414,7 @@ static void initgc(Gcstate *gc_r) { memset(&gcv,0,sizeof(gcv)); gcv.function= GXcopy; gcv.line_width= 1; - gc_r->lastfg= gcv.foreground= pix_dimgrey; + gc_r->lastfg= gcv.foreground= pix_white; gc_r->gc= XCreateGC(disp,win, GCFunction|GCLineWidth|GCForeground, &gcv); } @@ -446,17 +461,51 @@ static void newgeometry(void) { Window dummyw; XGetGeometry(disp,win, &dummyw,&dummy,&dummy, &width,&height, &dummy,&dummy); - refresh(); } static void eventloop(void) { XEvent ev; + int *fds, nfds, npfds, *fdp, i, r; + struct pollfd *pfds, *pfd; newgeometry(); - + + npfds= 0; + pfds= 0; for (;;) { - XNextEvent(disp,&ev); - newgeometry(); + r= XInternalConnectionNumbers(disp, &fds, &nfds); + if (!r) fail("XInternalConnectionNumbers"); + + if (npfds != nfds) { + pfds= realloc(pfds, sizeof(*pfds) * nfds); + if (!pfds) failr("realloc for pollfds",errno); + npfds= nfds; + } + for (i=0, pfd=pfds, fdp=fds; + ifd= *fdp; + pfd->events= POLLIN|POLLERR; + } + XFree(fds); + + r= poll(pfds,npfds,TIMEOUT); + if (r==-1) failr("poll",errno); + + for (i=0, pfd=pfds; + irevents) + XProcessInternalConnection(disp,pfd->fd); + } + + while (XPending(disp)) { + XNextEvent(disp,&ev); + if (ev.type == ConfigureNotify) + newgeometry(); + } + + refresh(); } }