Source obtained from http://sourceforge.net/projects/wmacpi/files/.

2003 November 23 1.99
        Finally claimed the wmacpi name as my own . . .

        Renamed wmacpi-ng and acpi-ng, renamed the header files, fixed up
        the makefile.

        For the Debian package, also made compilation of the command line
        tool optional, defaulting to not building it. This is because
        after the renaming, my acpi clashes with the acpi package that's
        already in Debian. The command line functionality is now
        accessible via the -w option to wmacpi.

        This is wmacpi 1.99, so that I can have a release packaged and in
        Debian before going to 2.0, so that any bugs that are left can be
        found by all the extra users.
---
 wmacpi/AUTHORS            |   3 +
 wmacpi/ChangeLog          |  16 +
 wmacpi/INSTALL            |  30 +-
 wmacpi/Makefile           |  33 +-
 wmacpi/README             |  94 +++--
 wmacpi/TODO               |   7 +
 wmacpi/acpi-ng.c          | 128 -------
 wmacpi/acpi.1             |   1 +
 wmacpi/acpi.c             | 128 +++++++
 wmacpi/debian/acpi-ng.1   |   1 -
 wmacpi/debian/control     |  17 +-
 wmacpi/debian/menu        |   4 +-
 wmacpi/debian/rules       |   8 +-
 wmacpi/debian/wmacpi-ng.1 | 140 --------
 wmacpi/libacpi.c          |  40 +--
 wmacpi/libacpi.h          |  39 ++-
 wmacpi/wmacpi-ng.c        | 805 -------------------------------------------
 wmacpi/wmacpi-ng.h        |   9 -
 wmacpi/wmacpi.1           | 144 ++++++++
 wmacpi/wmacpi.c           | 856 ++++++++++++++++++++++++++++++++++++++++++++++
 wmacpi/wmacpi.h           |   9 +
 21 files changed, 1306 insertions(+), 1206 deletions(-)
 delete mode 100644 wmacpi/acpi-ng.c
 create mode 100644 wmacpi/acpi.1
 create mode 100644 wmacpi/acpi.c
 delete mode 100644 wmacpi/debian/acpi-ng.1
 delete mode 100644 wmacpi/debian/wmacpi-ng.1
 delete mode 100644 wmacpi/wmacpi-ng.c
 delete mode 100644 wmacpi/wmacpi-ng.h
 create mode 100644 wmacpi/wmacpi.1
 create mode 100644 wmacpi/wmacpi.c
 create mode 100644 wmacpi/wmacpi.h

diff --git a/wmacpi/AUTHORS b/wmacpi/AUTHORS
index ed910da..6f804d2 100644
--- a/wmacpi/AUTHORS
+++ b/wmacpi/AUTHORS
@@ -1,3 +1,6 @@
+Simon Fowler <[email protected]>
+ Complete rewriting of the code from wmacpi-1.34. 
+
  timecop
  [email protected]
  all the code
diff --git a/wmacpi/ChangeLog b/wmacpi/ChangeLog
index 4bc42ed..179bd35 100644
--- a/wmacpi/ChangeLog
+++ b/wmacpi/ChangeLog
@@ -1,3 +1,19 @@
+2003 November 23 1.99
+       Finally claimed the wmacpi name as my own . . . 
+
+       Renamed wmacpi-ng and acpi-ng, renamed the header files, fixed up
+       the makefile.
+
+       For the Debian package, also made compilation of the command line
+       tool optional, defaulting to not building it. This is because
+       after the renaming, my acpi clashes with the acpi package that's
+       already in Debian. The command line functionality is now
+       accessible via the -w option to wmacpi.
+
+       This is wmacpi 1.99, so that I can have a release packaged and in
+       Debian before going to 2.0, so that any bugs that are left can be
+       found by all the extra users.
+       
 2003 September 26 0.99
        Fix the last of the old wmacpi code oddities (specifically, the
        APMInfo struct, which was a completely inappropriate name given we
diff --git a/wmacpi/INSTALL b/wmacpi/INSTALL
index 01b1e42..274d1f4 100644
--- a/wmacpi/INSTALL
+++ b/wmacpi/INSTALL
@@ -1,10 +1,20 @@
-to install:
-
-* vi Makefile
-* change what you want, according to instructions, save Makefile
-* make
-* copy wmacpi somewhere useful
-* dance
-* <somewhere useful>/wmacpi &
-* phear
-(if it doesn't work, skip the phear step)
+The basic install is very simple: make, make install.
+
+You can change the default install prefix (/usr/local) by specifying
+it in the make install command, eg: make install PREFIX=/usr
+
+To build the command line tool, either uncomment the BUILD_CLI=1 line
+in the Makefile, or specify BUILD_CLI=1 on the make command line. ie, 
+make BUILD_CLI=1
+make install BUILD_CLI=1
+
+No uninstall is supported, but isn't exactly difficult to delete all
+the files by hand . . .
+
+Files installed (paths relative to PREFIX):
+bin/wmacpi
+bin/acpi
+man/man1/wmacpi.1
+man/man1/acpi.1
+
+Simon Fowler <[email protected]>, 2003-11-23
\ No newline at end of file
diff --git a/wmacpi/Makefile b/wmacpi/Makefile
index 66e62f6..9b1f755 100644
--- a/wmacpi/Makefile
+++ b/wmacpi/Makefile
@@ -3,21 +3,28 @@
 
 OPT    := -O2 
 
+# uncomment this to build the command line acpi tool
+#BUILD_CLI = 1
+
 # uncomment this to make wmacpi use less system colors (looks uglier too)
 #OPT   += -DLOW_COLOR
 
 # debugging options (don't bother with these)
-#OPT   = -pg -g -DPRO -DACPI
+#OPT   = -pg -g
 
 CC     := gcc
 CFLAGS := $(OPT) -Wall -W -g -ansi -I/usr/X11R6/include
 LDFLAGS := $(OPT) -L/usr/X11R6/lib -lX11 -lXpm -lXext
 
-WMSRC  := wmacpi-ng.c libacpi.c
-CLSRC := acpi-ng.c libacpi.c
-HEADERS := libacpi.h wmacpi-ng.h
-targets := wmacpi-ng acpi-ng
-doc_targets := debian/wmacpi-ng.1 debian/acpi-ng.1
+WMSRC  := wmacpi.c libacpi.c
+HEADERS := libacpi.h wmacpi.h
+targets := wmacpi
+doc_targets := wmacpi.1
+
+ifdef BUILD_CLI
+targets += acpi
+doc_targets += acpi.1
+endif
 
 PREFIX := /usr/local
 
@@ -25,17 +32,23 @@ all: $(targets)
 
 # build the list of object files
 WMOBJ := $(patsubst %.c,%.o,$(filter %.c,$(WMSRC)))
-CLOBJ := $(patsubst %.c,%.o,$(filter %.c,$(CLSRC)))
 
 # include per-file dependencies
 include $(WMOBJ:.o=.d)
-include $(CLOBJ:.o=.d)
 
-wmacpi-ng:     $(WMOBJ)
+wmacpi:        $(WMOBJ)
        $(CC) $(LDFLAGS) -o $@ $^
 
-acpi-ng: $(CLOBJ)
+# for the Debian package, we want to make building the command line tools
+# optional. So, we hide all the necessary stuff here . . . 
+ifdef BUILD_CLI
+CLSRC := acpi.c libacpi.c
+CLOBJ := $(patsubst %.c,%.o,$(filter %.c,$(CLSRC)))
+include $(CLOBJ:.o=.d)
+
+acpi: $(CLOBJ)
        $(CC) $(LDFLAGS) -o $@ $^
+endif
 
 # build per-file dependencies - note that -MM may not be supported
 # in gcc versions older than 2.95.4, but most likely is.
diff --git a/wmacpi/README b/wmacpi/README
index faeea84..409f8b8 100644
--- a/wmacpi/README
+++ b/wmacpi/README
@@ -5,60 +5,50 @@ Usage:
 +-------------+
 |battery graph| <- visual percentage battery remaining
 |[:][=] [100%]| <- [:] - on AC (blink when charging) [=] - on battery
-|[00:00] [///]| <- [00:00] time remaining   [///] timer mode switch
+|[00:00]  [bX]| <- [00:00] time remaining   [bX] battery being monitored.
 |status   area| <- messages scroll here
 +-------------+
 
 see wmacpi -h for some command line switches
 
-Timer mode, available only when "on-battery", keeps track how long your laptop
-has been away from AC power.  Clicking the button toggles between timer and
-standard "time remaining" mode.
-
-******************************************************************************
-
-Implementation of "ACPI" mode:
-
-As far as I know, there aren't any tools available right now to process battery
-statistics provided in /proc/power by ACPI stuff in 2.4.x kernels.  This is my
-attempt to have a usable dockapp battery monitor for ACPI laptop systems.
-Since version 1.32 I've added some code to detect multiple batteries.  However
-it's not fully implemented yet, and while it will detect and enumerate
-batteries, the statistics reported are for the first found battery.
-  * Your battery is "Control Method" type
-  * Your ACPI BIOS is supported by current version of ACPI in kernel
-    2.4.17 + intel patches
-  * You applied acpi subsystem patch version 20020214 (from intel.com)
-
-If you are using kernels or ACPI version older than 2.4.17, keep using 
-wmacpi 1.32. This version is only for the latest ACPI code.
-To use ACPI support, just follow "INSTALL" instructions.  Makefile has been
-updated to include -DACPI. If you don't have ACPI, you don't need this version
-of wmacpi. Information below only applies to APM systems, without ACPI support.
-
-Implementation of "APM" mode
-
-This works on all machines that have a standard non-borked APM implementation.
-For people with broken APM implementations, I added some stuff, which was
-sent to me by Daniel Pittman <[email protected]>, to compensate for some
-of the stupidity.  If you see dumb behaviour from wmapm, consider editing
-wmapm.c and uncomment one, or both, of these lines (on lines 19 and 20):
-
-#define RETARDED_APM if your bios thinks the battery is charging all the time
-when it's on AC power.  What this will do is stop "charging" process as soon
-as the battery reaches 100%.
-
-#define STUPID_APM if your bios shows -1 minutes remaining when AC is plugged
-in, or when battery is charging.
-
-If your bios is even dumber than this, and you come up with another special
-case that needs to be handled, feel free to #ifdef it under <badword>_APM and
-send me a diff -u.  I will include it in the next version.  Any of these
-changes would have to go into acquire_apm_info.  Note, I changed format of
-apminfo structure to get rid of redundancy - now there is only one power state
-variable, which keeps track whether we are on AC, charging, battery, etc.
-
-Note, all the *_APM stuff is untested - my laptop has a working BIOS :)  If you
-test this and it doesn't work as advertised, go ahead and send me a fix.
-
- -timecop
+**********************************************************************
+
+wmacpi is a dockapp ACPI battery monitor for modern kernels (ie,
+2.4.17 or later, and 2.6 kernels). Basically, it opens various files
+under /proc/acpi, reads status information from them, and then
+displays summaries.
+
+Version 1.99 and later provides full support for multiple
+batteries. You can tell it to monitor a particular batter with the -m
+option, which will display the percentage remaining and current status
+message for that battery. The time remaining and AC/battery status are
+global - the time remaining is calculated based on all batteries found
+on the system. When charging, the time displayed is the time remaining
+until the battery is fully charged - this only works sensibly if your
+ACPI system is implemented properly (far, far too many laptops have
+buggered ACPI implementations).
+
+The displayed time is averaged over 50 samples, each taken every three
+seconds (by default). This greatly improves the accuracy of the
+numbers - on my laptop, the time remaining seems to be overstated by a
+good hour or so if you only sample once compared to fifty times.
+
+Some ACPI implementations are stupid enough to block interrupts while
+reading status information from the battery over a slow bus - this
+means that on such b0rken laptops, running an ACPI battery monitor
+could affect interactivity. To provide a workaround for this, current
+versions of wmacpi supports setting the sample rate from the command
+line. The default -s setting is 100, which translates to once every
+three seconds. -s 10 will sample every 30 seconds, -s 1 every 300
+seconds. -s 1000 will sample every 0.3 seconds - don't do that unless
+you're just having fun . . .
+
+Also provided is a command line tool to report the battery status. By
+default this will only sample once, but with the -a option you can
+specify a number. Be aware that it will try to take all those samples
+in the space of one second, so if your ACPI implementation is b0rken
+this could have adverse effects.
+
+Please report bugs to <[email protected]>.
+
+Simon Fowler, 2003-11-23.
\ No newline at end of file
diff --git a/wmacpi/TODO b/wmacpi/TODO
index 1aab3e8..3ddfbfa 100644
--- a/wmacpi/TODO
+++ b/wmacpi/TODO
@@ -1,3 +1,10 @@
+2003 November 23 1.99
+ * Expand libacpi to handle everything else under
+   /proc/acpi. Basically, make it into a full ACPI reporting library. 
+
+ * Make the command line tool a complete replacement for Grahame
+   Bowland's acpi tool, so that wmacpi won't conflict with it.
+
 2003 July 6 0.50
  * Fix the non-deb installation - as it stands, it doesn't even try.
 
diff --git a/wmacpi/acpi-ng.c b/wmacpi/acpi-ng.c
deleted file mode 100644
index ebc9184..0000000
--- a/wmacpi/acpi-ng.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * acpi-ng: command line acpi battery status tool.
- *
- * Written by Simon Fowler <[email protected]>, 2003-06-20.
- * Copyright 2003-06-20 Dreamcraft Pty Ltd.
- *
- * This file is distributed under the GNU General Public License, 
- * version 2. Please see the COPYING file for details.
- */
-
-/*
- * 2003-06-20.
- * I'm getting sick of not having a convenient way to query battery
- * status on the command line, so I'm hacking up this - a quick little
- * command line tool to display current battery status, using the same
- * libacpi code as wmacpi-ng.
- */
-
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <getopt.h>
-#include <unistd.h>
-
-#include "libacpi.h"
-
-#define ACPI_NG_VER "0.99"
-
-global_t *globals;
-
-void usage(char *name)
-{
-       printf("%s: query battery status on ACPI enabled systems.\n"
-              "Usage:\n"
-              "%s [-h] [-a samples]\n"
-              " h - display this help information\n"
-              " a - average remaining time over some number of samples\n"
-              "     much more accurate than using a single sample\n"
-              " v - increase verbosity\n",
-              name, name);
-}
-
-void print_version(void)
-{
-       printf("acpi-ng version %s\n", ACPI_NG_VER);
-       printf(" Using libacpi version %s\n", LIBACPI_VER);
-}
-
-int main(int argc, char *argv[])
-{
-       int i, j, ch;
-       int sleep_time = 0;
-       int samples = 1;
-       battery_t *binfo;
-       adapter_t *ap;
-
-       while((ch = getopt(argc, argv, "hvVa:")) != EOF) {
-               switch(ch) {
-               case 'h':
-                       usage(argv[0]);
-                       return 0;
-               case 'v':
-                       verbosity++;
-                       break;
-               case 'V':
-                       print_version();
-                       return 0;
-               case 'a':
-                       if(optarg != NULL) {
-                               samples = atoi(optarg);
-                               if(samples > 1000 || samples <= 0) {
-                                       printf("Please specify a reasonable 
number of samples\n");
-                                       exit(1);
-                       }
-                       }
-                       printf("samples: %d\n", samples);
-                       sleep_time = 1000000/samples;
-                       break;
-               default:
-                       usage(argv[0]);
-                       return 1;
-               }
-       }
-
-       globals = (global_t *) malloc(sizeof(global_t));
-
-       power_init();
-       /* we want to acquire samples over some period of time, so . . . */
-       for(i = 0; i < samples + 2; i++) {
-               for(j = 0; j < batt_count; j++)
-                       acquire_batt_info(j);
-               acquire_global_info();
-               usleep(sleep_time);
-       }
-       
-       ap = &globals->adapter;
-       if(ap->power == AC) {
-               printf("On AC Power");
-               for(i = 0; i < batt_count; i++) {
-                       binfo = &batteries[i];
-                       if(binfo->present && (binfo->charge_state == CHARGE)) {
-                               printf("; Battery %s charging", binfo->name);
-                               printf(", currently at %2d%%", 
binfo->percentage);
-                               if(binfo->charge_time >= 0) 
-                                       printf(", %2d:%02d remaining", 
-                                              binfo->charge_time/60,
-                                              binfo->charge_time%60);
-                       }
-               }
-               printf("\n");
-       } else if(ap->power == BATT) {
-               printf("On Battery");
-               for(i = 0; i < batt_count; i++) {
-                       binfo = &batteries[i];
-                       if(binfo->present && (binfo->percentage >= 0))
-                               printf(", Battery %s at %d%%", binfo->name,
-                                      binfo->percentage);
-               }
-               if(globals->rtime >= 0)
-                       printf("; %d:%02d remaining", globals->rtime/60, 
-                              globals->rtime%60);
-               printf("\n");
-       }
-       return 0;
-}
-
diff --git a/wmacpi/acpi.1 b/wmacpi/acpi.1
new file mode 100644
index 0000000..c286484
--- /dev/null
+++ b/wmacpi/acpi.1
@@ -0,0 +1 @@
+.so man1/wmacpi.1
diff --git a/wmacpi/acpi.c b/wmacpi/acpi.c
new file mode 100644
index 0000000..2bb0935
--- /dev/null
+++ b/wmacpi/acpi.c
@@ -0,0 +1,128 @@
+/*
+ * acpi-ng: command line acpi battery status tool.
+ *
+ * Written by Simon Fowler <[email protected]>, 2003-06-20.
+ * Copyright 2003-06-20 Dreamcraft Pty Ltd.
+ *
+ * This file is distributed under the GNU General Public License, 
+ * version 2. Please see the COPYING file for details.
+ */
+
+/*
+ * 2003-06-20.
+ * I'm getting sick of not having a convenient way to query battery
+ * status on the command line, so I'm hacking up this - a quick little
+ * command line tool to display current battery status, using the same
+ * libacpi code as wmacpi-ng.
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <unistd.h>
+
+#include "libacpi.h"
+
+#define ACPI_VER "1.99"
+
+global_t *globals;
+
+void usage(char *name)
+{
+       printf("%s: query battery status on ACPI enabled systems.\n"
+              "Usage:\n"
+              "%s [-h] [-a samples]\n"
+              " h - display this help information\n"
+              " a - average remaining time over some number of samples\n"
+              "     much more accurate than using a single sample\n"
+              " v - increase verbosity\n",
+              name, name);
+}
+
+void print_version(void)
+{
+       printf("acpi version %s\n", ACPI_VER);
+       printf(" Using libacpi version %s\n", LIBACPI_VER);
+}
+
+int main(int argc, char *argv[])
+{
+       int i, j, ch;
+       int sleep_time = 0;
+       int samples = 1;
+       battery_t *binfo;
+       adapter_t *ap;
+
+       while((ch = getopt(argc, argv, "hvVa:")) != EOF) {
+               switch(ch) {
+               case 'h':
+                       usage(argv[0]);
+                       return 0;
+               case 'v':
+                       verbosity++;
+                       break;
+               case 'V':
+                       print_version();
+                       return 0;
+               case 'a':
+                       if(optarg != NULL) {
+                               samples = atoi(optarg);
+                               if(samples > 1000 || samples <= 0) {
+                                       printf("Please specify a reasonable 
number of samples\n");
+                                       exit(1);
+                       }
+                       }
+                       printf("samples: %d\n", samples);
+                       sleep_time = 1000000/samples;
+                       break;
+               default:
+                       usage(argv[0]);
+                       return 1;
+               }
+       }
+
+       globals = (global_t *) malloc(sizeof(global_t));
+
+       power_init();
+       /* we want to acquire samples over some period of time, so . . . */
+       for(i = 0; i < samples + 2; i++) {
+               for(j = 0; j < batt_count; j++)
+                       acquire_batt_info(j);
+               acquire_global_info();
+               usleep(sleep_time);
+       }
+       
+       ap = &globals->adapter;
+       if(ap->power == AC) {
+               printf("On AC Power");
+               for(i = 0; i < batt_count; i++) {
+                       binfo = &batteries[i];
+                       if(binfo->present && (binfo->charge_state == CHARGE)) {
+                               printf("; Battery %s charging", binfo->name);
+                               printf(", currently at %2d%%", 
binfo->percentage);
+                               if(binfo->charge_time >= 0) 
+                                       printf(", %2d:%02d remaining", 
+                                              binfo->charge_time/60,
+                                              binfo->charge_time%60);
+                       }
+               }
+               printf("\n");
+       } else if(ap->power == BATT) {
+               printf("On Battery");
+               for(i = 0; i < batt_count; i++) {
+                       binfo = &batteries[i];
+                       if(binfo->present && (binfo->percentage >= 0))
+                               printf(", Battery %s at %d%%", binfo->name,
+                                      binfo->percentage);
+               }
+               if(globals->rtime >= 0)
+                       printf("; %d:%02d remaining", globals->rtime/60, 
+                              globals->rtime%60);
+               printf("\n");
+       }
+       return 0;
+}
+
diff --git a/wmacpi/debian/acpi-ng.1 b/wmacpi/debian/acpi-ng.1
deleted file mode 100644
index c12e2a4..0000000
--- a/wmacpi/debian/acpi-ng.1
+++ /dev/null
@@ -1 +0,0 @@
-.so man1/wmacpi-ng.1
diff --git a/wmacpi/debian/control b/wmacpi/debian/control
index d6d72a8..8b9e99f 100644
--- a/wmacpi/debian/control
+++ b/wmacpi/debian/control
@@ -1,21 +1,20 @@
-Source: wmacpi-ng
+Source: wmacpi
 Section: x11
 Priority: optional
 Maintainer: Simon Fowler <[email protected]>
 Build-Depends: debhelper (>= 4), xlibs-dev
 Standards-Version: 3.5.9
 
-Package: wmacpi-ng
+Package: wmacpi
 Architecture: i386
 Depends: ${shlibs:Depends}
 Recommends: wmaker
 Description: An ACPI battery monitor for WindowMaker
- This is a battery monitor that uses ACPI to query the battery status. As
- the interface to ACPI changes rather often, this program usually only works
- with a very specific kernel version.
+ This is a battery monitor that uses ACPI to query the battery status.
+ This version should work with all recent kernels, both 2.4 and 2.6.
  .
- This is a reworked version to handle kernel version 2.4.21-rc2, done
- by Simon Fowler <[email protected]>     
+ This is a reworked version to handle modern kernels, done by Simon
+ Fowler <[email protected]>        
  .
-  Author: Tim Copperfield <[email protected]>
-  Homepage: http://www.ne.jp/asahi/linux/timecop/
+  Author: Simon Fowler <[email protected]>
+  Homepage: http://himi.org/wmacpi-ng/
diff --git a/wmacpi/debian/menu b/wmacpi/debian/menu
index e76a272..10c6503 100644
--- a/wmacpi/debian/menu
+++ b/wmacpi/debian/menu
@@ -1,2 +1,2 @@
-?package(wmacpi-ng):needs=X11 section=Apps/System\
-  title="wmacpi-ng" command="/usr/bin/wmacpi-ng"
+?package(wmacpi):needs=X11 section=Apps/System\
+  title="wmacpi" command="/usr/bin/wmacpi"
diff --git a/wmacpi/debian/rules b/wmacpi/debian/rules
index 45c5893..5cc82ce 100755
--- a/wmacpi/debian/rules
+++ b/wmacpi/debian/rules
@@ -5,7 +5,7 @@
 # Uncomment this to turn on verbose mode.
 #export DH_VERBOSE=1
 
-INSTALLDIR=$(CURDIR)/debian/wmacpi-ng
+INSTALLDIR=$(CURDIR)/debian/wmacpi
 
 # These are used for cross-compiling and for saving the configure script
 # # from having to guess our platform (since we know it already)
@@ -50,8 +50,8 @@ install: build
        dh_installdirs
 
        # Add here commands to install the package into debian/wmacpi.
-       install -o root -g root -m 755 wmacpi-ng $(INSTALLDIR)/usr/bin/
-       install -o root -g root -m 755 acpi-ng $(INSTALLDIR)/usr/bin/
+       install -o root -g root -m 755 wmacpi $(INSTALLDIR)/usr/bin/
+#      install -o root -g root -m 755 acpi-ng $(INSTALLDIR)/usr/bin/
 
 
 # Build architecture-independent files here.
@@ -70,7 +70,7 @@ binary-arch: build install
 #      dh_installpam
 #      dh_installinit
 #      dh_installcron
-       dh_installman debian/wmacpi-ng.1 debian/acpi-ng.1
+       dh_installman wmacpi.1 # acpi.1
 #      dh_installinfo
 #      dh_undocumented
        dh_installchangelogs ChangeLog
diff --git a/wmacpi/debian/wmacpi-ng.1 b/wmacpi/debian/wmacpi-ng.1
deleted file mode 100644
index ae564b4..0000000
--- a/wmacpi/debian/wmacpi-ng.1
+++ /dev/null
@@ -1,140 +0,0 @@
-.TH WMACPI-NG 1 "July 11, 2003"
-.SH NAME
-wmacpi-ng \- Battery status monitor for systems supporting ACPI
-.SH NAME
-acpi-ng \- Query battery status for systems supporting ACPI
-.SH SYNOPSIS
-.B wmacpi-ng
-[
-.RI -b
-]
-[
-.RI -c
-value ]
-[
-.RI -d
-display ]
-[
-.RI -m
-battery no ]
-[
-.RI -s
-sample rate ]
-[
-.RI -v
-]
-]
-.RI -n
-]
-[
-.RI -V
-]
-[
-.RI -h
-]
-.PP
-.B acpi-ng
-[
-.RI -a
-samples ]
-[
-.RI -v 
-]
-[
-.RI -V
-]
-[
-.RI -h
-]
-.SH DESCRIPTION
-This manual page documents briefly the
-.B wmacpi-ng
-command.
-.PP
-.B wmacpi-ng
-is a program that displays the current battery status in a WindowMaker
-dock app, on systems that support Intel's Advanced Configuration and
-Power Interface specification (ACPI).
-.PP
-The program monitors a battery, displaying its current percentage
-charge via a bar and a numeric value. It also displays the current
-power status for the system, the time remaining (calculated based on
-the remaining battery capacity and the current rate of power usage),
-and a scrolling message with some hopefully useful information.
-.PP
-Clicking on the window cycles through the batteries that the ACPI
-system knows about.
-.PP
-.B acpi-ng
-queries the battery status from the command line. It prints the power
-status, the percentage remaining for each battery found, and the time
-remaining if the system is on battery, or the time remaining for each
-battery to reach full charge if the batteries are charging.
-.SH OPTIONS
-.B wmacpi-ng
-.TP
-.B \-b
-Make noise when battery is critical low (beep).
-.TP
-.B \-c percentage
-Set critical low alarm at <value>% (default: 10%).
-.TP
-.B \-d display
-Set the X display to open the window on.
-.TP
-.B \-m battery number
-Set the battery to monitor initially.
-.TP
-.B \-s sample rate
-Set the rate at which to sample the ACPI data (default is 100, which 
-translates to once every three seconds. 10 gives once every 30 seconds, 
-1 once every 300 seconds (five minutes), 1000 once every 0.3 seconds).
-.TP
-.B \-n
-Disable blinking power glyph when charging. Note that it still blinks when 
-the battery reports its capacity state as critical.
-.TP
-.B \-v
-Increase the verbosity of the program. Can be used more than once -
-each successive use increases the verbosity.
-.TP
-.B \-V
-Print the version information.
-.TP
-.B \-h
-Display help.
-.TP
-.B acpi-ng
-.TP
-.B \-a num
-Average the time remaining over num samples. This greatly improves the
-accuracy of the reported time remaining.
-.TP
-.B \-v
-Increase the verbosity of the program, as for
-.B wmacpi-ng
-.TP
-.B \-V
-Print the version information.
-.TP
-.B \-h
-Display help.
-.TP
-.SH SEE ALSO
-.BR wmapm (1)
-.br
-.SH AUTHOR
-.B wmacpi
-as written by Tim Copperfield <[email protected]>. 
-.B wmacpi-ng 
-is a reworking of 
-.B wmacpi 1.34
-to support recent kernel versions, performed by Simon Fowler
-<[email protected]>. 
-.PP
-This manual page was originally written by Simon Richter
-<[email protected]> for the Debian GNU/Linux system, and then updated for 
-.B wmacpi-ng
-by Simon Fowler.
-.br
-Last modification by Simon Fowler <[email protected]>, 2003-07-11.
diff --git a/wmacpi/libacpi.c b/wmacpi/libacpi.c
index e0b536d..bf82417 100644
--- a/wmacpi/libacpi.c
+++ b/wmacpi/libacpi.c
@@ -30,7 +30,7 @@ int init_batteries(void)
     batt_count = 0;
     battdir = opendir("/proc/acpi/battery");
     if (battdir == NULL) {
-       fprintf(stderr, "No batteries or ACPI not supported\n");
+       perr("No batteries or ACPI not supported\n");
        return 1;
     }
     while ((batt = readdir(battdir))) {
@@ -68,13 +68,13 @@ int init_batteries(void)
                 "/proc/acpi/battery/%s/info", names[i]);
        snprintf(batteries[i].state_file, MAX_NAME, 
                 "/proc/acpi/battery/%s/state", names[i]);
-       eprint(0, "battery detected at %s\n", batteries[i].info_file);
-       fprintf(stderr, "found battery %s\n", names[i]);
+       pdebug("battery detected at %s\n", batteries[i].info_file);
+       pinfo("found battery %s\n", names[i]);
     }
 
     /* tell user some info */
-    eprint(0, "%d batteries detected\n", batt_count);
-    fprintf(stderr, "libacpi: found %d batter%s\n", batt_count,
+    pdebug("%d batteries detected\n", batt_count);
+    pinfo("libacpi: found %d batter%s\n", batt_count,
            (batt_count == 1) ? "y" : "ies");
     
     return 0;
@@ -92,7 +92,7 @@ int init_ac_adapters(void)
 
     acdir = opendir("/proc/acpi/ac_adapter");
     if (acdir == NULL) {
-       fprintf(stderr, "Unable to open /proc/acpi/ac_adapter -"
+       pfatal("Unable to open /proc/acpi/ac_adapter -"
                " are you sure this system supports ACPI?\n");
        return 1;
     }
@@ -102,14 +102,14 @@ int init_ac_adapters(void)
 
        if (!strncmp(".", name, 1) || !strncmp("..", name, 2))
            continue;
-       fprintf(stderr, "found adapter %s\n", name);
+       pdebug("found adapter %s\n", name);
     }
     /* we /should/ only see one filename other than . and .. so
      * we'll just use the last value name acquires . . . */
     ap->name = strdup(name);
     snprintf(ap->state_file, MAX_NAME, "/proc/acpi/ac_adapter/%s/state",
             ap->name);
-    fprintf(stderr, "libacpi: found ac adapter %s\n", ap->name);
+    pinfo("libacpi: found ac adapter %s\n", ap->name);
     
     return 0;
 }
@@ -123,16 +123,16 @@ int power_init(void)
     int retval;
 
     if (!(acpi = fopen("/proc/acpi/info", "r"))) {
-       fprintf(stderr, "This system does not support ACPI\n");
+       pfatal("This system does not support ACPI\n");
        return 1;
     }
 
     /* okay, now see if we got the right version */
     fread(buf, 4096, 1, acpi);
     acpi_ver = strtol(buf + 25, NULL, 10);
-    eprint(0, "ACPI version detected: %d\n", acpi_ver);
+    pinfo("ACPI version detected: %d\n", acpi_ver);
     if (acpi_ver < 20020214) {
-       fprintf(stderr, "This version requires ACPI subsystem version 
20020214\n");
+       pfatal("This version requires ACPI subsystem version 20020214\n");
        fclose(acpi);
        return 1;
     }
@@ -194,7 +194,7 @@ int get_battery_info(int batt_no)
 
     if ((file = fopen(info->info_file, "r")) == NULL) {
        /* this is cheating, but string concatenation should work . . . */
-       fprintf(stderr, "Could not open %s:", info->info_file );
+       pfatal("Could not open %s:", info->info_file );
        perror(NULL);
        return 0;
     }
@@ -209,7 +209,7 @@ int get_battery_info(int batt_no)
     if ((strncmp(val, "yes", 3)) == 0) {
        info->present = 1;
     } else {
-       eprint(0, "Battery %s not present\n", info->name);
+       pinfo("Battery %s not present\n", info->name);
        info->present = 0;
        return 0;
     }
@@ -242,7 +242,7 @@ int get_battery_info(int batt_no)
 
     
     if ((file = fopen(info->state_file, "r")) == NULL) {
-       fprintf(stderr, "Could not open %s:", info->state_file );
+       perr("Could not open %s:", info->state_file );
        perror(NULL);
        return 0;
     }
@@ -258,7 +258,7 @@ int get_battery_info(int batt_no)
        info->present = 1;
     } else {
        info->present = 0;
-       eprint(1, "Battery %s no longer present\n", info->name);
+       perr("Battery %s no longer present\n", info->name);
        return 0;
     }
 
@@ -341,13 +341,13 @@ static int calc_remaining_percentage(int batt)
 
     /* we use -1 to indicate that the value is unknown . . . */
     if (rcap < 0) {
-       eprint(0, "unknown percentage value\n");
+       perr("unknown percentage value\n");
        retval = -1;
     } else {
        if (lfcap <= 0)
            lfcap = 1;
        retval = (int)((rcap/lfcap) * 100.0);
-       eprint(0, "percent: %d\n", retval);
+       pdebug("percent: %d\n", retval);
     }
     return retval;
 }
@@ -368,7 +368,7 @@ static int calc_charge_time(int batt)
 
     if (binfo->charge_state == CHARGE) {
        if (binfo->present_rate == -1) {
-           eprint(0, "unknown present rate\n");
+           perr("unknown present rate\n");
            charge_time = -1;
        } else {
            lfcap = (float)binfo->last_full_cap;
@@ -424,7 +424,7 @@ void acquire_batt_info(int batt)
         * check if we're at a critical battery level, and calculate
         * other interesting stuff . . . */
        if (binfo->capacity_state == CRITICAL) {
-           eprint(1, "Received critical battery status");
+           pinfo("Received critical battery status");
            ap->power = HARD_CRIT;
        }
     }
@@ -506,7 +506,7 @@ void acquire_global_info(void)
     if(rtime <= 0) 
        rtime = 0;
  out:
-    eprint(0, "time rem: %d\n", rtime);
+    pdebug("time rem: %d\n", rtime);
     globals->rtime = rtime;
 
     /* get the power status.
diff --git a/wmacpi/libacpi.h b/wmacpi/libacpi.h
index fac7f8d..4ed6f5a 100644
--- a/wmacpi/libacpi.h
+++ b/wmacpi/libacpi.h
@@ -92,28 +92,35 @@ typedef struct {
 
 /*
  * To provide a convenient debugging function . . . 
+ *
+ * It's a macro because I'm too lazy to deal with varargs.
  */
 
 static int verbosity = 0;
 
-#define eprint(level, fmt, arg...)                                     \
-    do {                                                               \
-       if (level > verbosity) {                                        \
-           switch (level) {                                            \
-           case 0:                                                     \
-               break;                                                  \
-           case 1:                                                     \
-               fprintf(stderr, fmt, ##arg);                            \
-                break;                                                 \
-           default:                                                    \
-               fprintf(stderr, "%s: " fmt, __FUNCTION__, ##arg);       \
-               fprintf(stderr, "\n");                                  \
-               break;                                                  \
-           }                                                           \
-       }                                                               \
+#define pdebug(fmt, arg...)                            \
+    do {                                               \
+       if (verbosity > 2)                              \
+           fprintf(stderr, fmt, ##arg);                \
+    } while (0)
+
+#define pinfo(fmt, arg...)                             \
+    do {                                               \
+       if (verbosity > 1)                              \
+           fprintf(stderr, fmt, ##arg);                \
     } while (0)
 
-/* since these /are/ needed here . . . */
+#define perr(fmt, arg...)                              \
+    do {                                               \
+       if (verbosity > 0)                              \
+           fprintf(stderr, fmt, ##arg);                \
+    } while (0)
+
+#define pfatal(fmt, arg...)                            \
+    fprintf(stderr, fmt, ##arg)                                \
+       
+
+/* Since these /are/ needed here . . . */
 battery_t batteries[MAXBATT];
 int batt_count;
 
diff --git a/wmacpi/wmacpi-ng.c b/wmacpi/wmacpi-ng.c
deleted file mode 100644
index 27a77cc..0000000
--- a/wmacpi/wmacpi-ng.c
+++ /dev/null
@@ -1,805 +0,0 @@
-/* apm/acpi dockapp - phear it 1.34
- * Copyright (C) 2000, 2001, 2002 [email protected]
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <getopt.h>
-#include <unistd.h>
-#include <time.h>
-
-#include <X11/X.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/extensions/shape.h>
-#include <X11/xpm.h>
-
-#include "libacpi.h"
-#include "wmacpi-ng.h"
-
-#define WMACPI_NG_VER "0.99"
-
-/* main pixmap */
-#ifdef LOW_COLOR
-#include "master_low.xpm"
-#else
-#include "master.xpm"
-#endif
-
-typedef struct {
-    Display *display;          /* X11 display struct */
-    int screen;                        /* current screen */
-    Window root;               /* root window */
-    Window win;                        /* one window */
-    Window iconwin;            /* another one */
-    Pixmap pixmap;             /* UI pixmap, window pixmap */
-    Pixmap mask;               /* mask pixmap for shape */
-    GC gc;                     /* main drawing GC */
-    Pixmap text;               /* pixmap for text scroller */
-    int tw;                    /* text width inside text pixmap */
-    int update;                        /* need to redraw? */
-    int blink;                 /* should we blink the LED? (critical battery) 
*/
-} Dockapp;
-
-/* for debug printing */
-#ifdef PRO
-char *state[] = { "AC", "Charging", "High", "Low", "Crit" };
-#endif
-
-/* globals */
-Dockapp *dockapp;
-global_t *globals;
-int count = 0;                 /* global timer variable */
-int noisy_critical = 0;                /* ring xbell annoyingly if critical? */
-
-/* Time for scroll updates */
-#define DEFAULT_UPDATE 150
-static int update_timeout = DEFAULT_UPDATE;
-
-/* proto for local stuff */
-static void new_window(char *name);
-static int open_display(char *display);
-static void redraw_window(void);
-static void render_text(char *string);
-static void scroll_text(int x, int y, int width, int tw, int reset);
-static void display_percentage(int percent);
-static void display_time(int minutes);
-
-#define copy_xpm_area(x, y, w, h, dx, dy)                              \
-{                                                                      \
-    XCopyArea(dockapp->display, dockapp->pixmap, dockapp->pixmap,      \
-           dockapp->gc, x, y, w, h, dx, dy);                           \
-    dockapp->update = 1;                                               \
-}
-
-/* display AC power symbol */
-static void display_power_glyph(void)
-{
-    copy_xpm_area(67, 38, 12, 7, 6, 17);
-}
-
-/* get rid of AC power symbol */
-static void kill_power_glyph(void)
-{
-    copy_xpm_area(67, 48, 12, 7, 6, 17);
-}
-
-/* display battery symbol */
-static void display_battery_glyph(void)
-{
-    copy_xpm_area(82, 38, 12, 7, 20, 17);
-}
-
-/* get rid of battery symbol */
-static void kill_battery_glyph(void)
-{
-    copy_xpm_area(82, 48, 12, 7, 20, 17);
-}
-
-/* clear the time display */
-static void clear_time_display(void)
-{
-    copy_xpm_area(114, 76, 31, 11, 7, 32);
-}
-
-/* set time display to -- -- */
-static void invalid_time_display(void)
-{
-    copy_xpm_area(122, 13, 31, 11, 7, 32);
-}
-
-static void redraw_window(void)
-{
-    if (dockapp->update) {
-       eprint(0, "redrawing window");
-       XCopyArea(dockapp->display, dockapp->pixmap, dockapp->iconwin,
-                 dockapp->gc, 0, 0, 64, 64, 0, 0);
-       XCopyArea(dockapp->display, dockapp->pixmap, dockapp->win,
-                 dockapp->gc, 0, 0, 64, 64, 0, 0);
-       dockapp->update = 0;
-    }
-}
-
-static void new_window(char *name)
-{
-    XpmAttributes attr;
-    Pixel fg, bg;
-    XGCValues gcval;
-    XSizeHints sizehints;
-    XClassHint classhint;
-    XWMHints wmhints;
-
-    dockapp->screen = DefaultScreen(dockapp->display);
-    dockapp->root = DefaultRootWindow(dockapp->display);
-
-    sizehints.flags = USSize;
-    sizehints.width = 64;
-    sizehints.height = 64;
-
-    fg = BlackPixel(dockapp->display, dockapp->screen);
-    bg = WhitePixel(dockapp->display, dockapp->screen);
-
-    dockapp->win = XCreateSimpleWindow(dockapp->display, dockapp->root,
-                                      0, 0, sizehints.width,
-                                      sizehints.height, 1, fg, bg);
-    dockapp->iconwin =
-       XCreateSimpleWindow(dockapp->display, dockapp->win, 0, 0,
-                           sizehints.width, sizehints.height, 1, fg, bg);
-
-    XSetWMNormalHints(dockapp->display, dockapp->win, &sizehints);
-    classhint.res_name = name;
-    classhint.res_class = name;
-    XSetClassHint(dockapp->display, dockapp->win, &classhint);
-
-    XSelectInput(dockapp->display, dockapp->win,
-                ExposureMask | ButtonPressMask | ButtonReleaseMask |
-                StructureNotifyMask);
-    XSelectInput(dockapp->display, dockapp->iconwin,
-                ExposureMask | ButtonPressMask | ButtonReleaseMask |
-                StructureNotifyMask);
-
-    XStoreName(dockapp->display, dockapp->win, name);
-    XSetIconName(dockapp->display, dockapp->win, name);
-
-    gcval.foreground = fg;
-    gcval.background = bg;
-    gcval.graphics_exposures = False;
-
-    dockapp->gc =
-       XCreateGC(dockapp->display, dockapp->win,
-                 GCForeground | GCBackground | GCGraphicsExposures,
-                 &gcval);
-
-    attr.exactColors = 0;
-    attr.alloc_close_colors = 1;
-    attr.closeness = 1L << 15;
-    attr.valuemask = XpmExactColors | XpmAllocCloseColors | XpmCloseness;
-    if (XpmCreatePixmapFromData(dockapp->display, dockapp->win,
-                               master_xpm, &dockapp->pixmap,
-                               &dockapp->mask, &attr) != XpmSuccess) {
-       fprintf(stderr, "FATAL: Not enough colors for main pixmap!\n");
-       exit(1);
-    }
-
-    /* text area is 318x7, or 53 characters long */
-    dockapp->text = XCreatePixmap(dockapp->display, dockapp->win, 318, 7,
-                                 DefaultDepth(dockapp->display,
-                                              dockapp->screen));
-    if (!dockapp->text) {
-       fprintf(stderr, "FATAL: Cannot create text scroll pixmap!\n");
-       exit(1);
-    }
-
-    XShapeCombineMask(dockapp->display, dockapp->win, ShapeBounding, 0, 0,
-                     dockapp->mask, ShapeSet);
-    XShapeCombineMask(dockapp->display, dockapp->iconwin, ShapeBounding, 0,
-                     0, dockapp->mask, ShapeSet);
-
-    wmhints.initial_state = WithdrawnState;
-    wmhints.flags = StateHint;
-    wmhints.icon_window = dockapp->iconwin;
-    wmhints.icon_x = sizehints.x;
-    wmhints.icon_y = sizehints.y;
-    wmhints.window_group = dockapp->win;
-    wmhints.flags =
-       StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;
-    XSetWMHints(dockapp->display, dockapp->win, &wmhints);
-
-    XMapWindow(dockapp->display, dockapp->win);
-}
-
-static void render_text(char *string)
-{
-    int i, c, k;
-
-    if (strlen(string) > 53)
-       return;
-
-    eprint(0, "rendering: %s", string);
-
-    /* prepare the text area by clearing it */
-    for (i = 0; i < 54; i++) {
-       XCopyArea(dockapp->display, dockapp->pixmap, dockapp->text,
-                 dockapp->gc, 133, 57, 6, 8, i * 6, 0);
-    }
-    k = 0;
-
-    for (i = 0; string[i]; i++) {
-       c = toupper(string[i]);
-       if (c >= 'A' && c <= 'Z') {     /* letter */
-           c = c - 'A';
-           XCopyArea(dockapp->display, dockapp->pixmap, dockapp->text,
-                     dockapp->gc, c * 6, 67, 6, 7, k, 0);
-       } else if (c >= '0' && c <= '9') {      /* number */
-           c = c - '0';
-           XCopyArea(dockapp->display, dockapp->pixmap, dockapp->text,
-                     dockapp->gc, c * 6 + 66, 58, 6, 7, k, 0);
-       } else if (c == '.') {
-           XCopyArea(dockapp->display, dockapp->pixmap, dockapp->text,
-                     dockapp->gc, 140, 58, 6, 7, k, 0);
-       } else if (c == '-') {
-           XCopyArea(dockapp->display, dockapp->pixmap, dockapp->text,
-                     dockapp->gc, 126, 58, 6, 7, k, 0);
-       }
-       k += 6;
-    }
-    dockapp->tw = k;           /* length of text segment */
-    /* re-scroll the message */
-    scroll_text(6, 50, 52, dockapp->tw, 1);
-    /* reset the scroll repeat counter */
-    count = 0;
-}
-
-static int open_display(char *display)
-{
-    dockapp->display = XOpenDisplay(display);
-    if (!dockapp->display) {
-       fprintf(stderr, "Unable to open display '%s'\n", display);
-       return 1;
-    }
-    return 0;
-}
-
-static void scroll_text(int x, int y, int width, int tw, int reset)
-{
-    static int pos, first, stop;
-
-    if (reset) {
-       pos = 0;
-       first = 0;
-       stop = 0;
-       XCopyArea(dockapp->display, dockapp->pixmap, dockapp->text,
-                 dockapp->gc, 0, 0, width, 7, x, y);
-    }
-
-    if (stop) {
-       return;
-    }
-
-    if ((first == 0) && pos == 0) {
-       pos = width;
-       first = 1;
-    }
-
-    if (pos == (0 - tw - 2)) {
-       first = 1;
-       pos = width;
-       stop = 1;
-       return;
-    }
-    pos -= 2;
-
-    if (pos > 0) {
-       copy_xpm_area(66, 9, pos, 7, x, y);     /* clear */
-       XCopyArea(dockapp->display, dockapp->text, dockapp->pixmap,
-                 dockapp->gc, 0, 0, width - pos, 7, x + pos, y);
-    } else {                   /* don't need to clear, already in text */
-       XCopyArea(dockapp->display, dockapp->text, dockapp->pixmap,
-                 dockapp->gc, abs(pos), 0, width, 7, x, y);
-    }
-    dockapp->update = 1;
-}
-
-static void display_percentage(int percent)
-{
-    static int op = -1;
-    static unsigned int obar;
-    unsigned int bar;
-
-    eprint(0, "received: %d\n", percent);
-
-    if (percent == -1)
-       percent = 0;
-
-    if (op == percent)
-       return;
-
-    if (percent < 0)
-       percent = 0;
-    if (percent > 100)
-       percent = 100;
-
-    if (percent < 100) {       /* 0 - 99 */
-       copy_xpm_area(95, 48, 8, 7, 37, 17);
-       if (percent >= 10)
-           copy_xpm_area((percent / 10) * 6 + 67, 28, 5, 7, 40, 17);
-       copy_xpm_area((percent % 10) * 6 + 67, 28, 5, 7, 46, 17);
-    } else
-       copy_xpm_area(95, 37, 21, 9, 37, 16);   /* 100% */
-    op = percent;
-
-    bar = percent / 1.8518;
-
-    if (bar == obar)
-       return;
-
-    copy_xpm_area(66, 0, bar, 8, 5, 5);
-    if (bar < 54)
-       copy_xpm_area(66 + bar, 18, 54 - bar, 8, bar + 5, 5);
-    obar = bar;
-}
-
-static void display_time(int minutes)
-{
-    static int ohour = -1, omin = -1;
-    int hour, min, tmp;
-
-    if (minutes <= 0) {        /* error - clear the display */
-       invalid_time_display();
-       ohour = omin = -1;
-       return;
-    }
-
-    /* render time on the display */
-    hour = minutes / 60;
-    /* our display area only fits %2d:%2d, so we need to make sure
-     * what we're displaying will fit in those constraints. I don't
-     * think we're likely to see any batteries that do more than 
-     * 100 hours any time soon, so it's fairly safe. */
-    if (hour >= 100) {
-       hour = 99;
-       min = 59;
-    } else
-       min = minutes % 60;
-
-    if (hour == ohour && min == omin)
-       return;
-
-    eprint(0, "redrawing time");
-    tmp = hour / 10;
-    copy_xpm_area(tmp * 7 + 1, 76, 6, 11, 7, 32);
-    tmp = hour % 10;
-    copy_xpm_area(tmp * 7 + 1, 76, 6, 11, 14, 32);
-    tmp = min / 10;
-    copy_xpm_area(tmp * 7 + 1, 76, 6, 11, 25, 32);
-    tmp = min % 10;
-    copy_xpm_area(tmp * 7 + 1, 76, 6, 11, 32, 32);
-    copy_xpm_area(71, 76, 3, 11, 21, 32);
-    ohour = hour;
-    omin = min;
-}
-
-/* 
- * The reworked state handling stuff.
- */
-
-/* set the current state of the power panel */
-enum panel_states {
-    PS_AC,
-    PS_BATT,
-    PS_NULL,
-};
-
-static void really_blink_power_glyph(void)
-{
-    static int counter = 0;
-
-    if (counter == 10) 
-       display_power_glyph();
-    else if (counter == 20) 
-       kill_power_glyph();
-    else if (counter > 30)
-       counter = 0;
-    counter++;
-}
-
-static void blink_power_glyph(void)
-{
-    if (dockapp->blink)
-       really_blink_power_glyph();
-}
-
-static void really_blink_battery_glyph(void)
-{
-    static int counter = 0;
-
-    if (counter == 10)
-       display_battery_glyph();
-    else if (counter == 20)
-       kill_battery_glyph();
-    else if (counter > 30)
-       counter = 0;
-    counter++;
-}    
-
-static void blink_battery_glyph(void)
-{
-    if (dockapp->blink)
-       really_blink_battery_glyph();
-}
-
-static void set_power_panel(void)
-{
-    enum panel_states power = PS_NULL;
-    battery_t *binfo = globals->binfo;
-    adapter_t *ap = &globals->adapter;
-
-    if (ap->power == AC) {
-       if (power != PS_AC) {
-           power = PS_AC;
-           kill_battery_glyph();
-           display_power_glyph();
-       }
-    } else if (ap->power == BATT) {
-       if (power != PS_BATT) {
-           power = PS_BATT;
-           kill_power_glyph();
-           display_battery_glyph();
-       }
-    }
-
-    if (binfo->charge_state == CHARGE)
-       blink_power_glyph();
-
-    if (binfo->state == CRIT)
-       blink_battery_glyph();
-
-    if (binfo->state == HARD_CRIT)
-       really_blink_battery_glyph();
-}
-
-/* 
- * The message that needs to be displayed needs to be decided
- * according to a heirarchy: a message like not present needs to take
- * precedence over a global thing like the current power status, and
- * something like a low battery warning should take precedence over
- * the "on battery" message. Likewise, a battery charging message
- * needs to take precedence over the on ac power message. The other
- * question is how much of a precedence local messages should take
- * over global ones . . . 
- *
- * So, there are three possible sets of messages: not present, on-line
- * and off-line messages. We need to decide which of those sets is
- * appropriate right now, and then decide within them. 
- */
-enum messages {
-    M_NP,      /* not present */
-    M_AC,      /* on ac power */
-    M_CH,      /* battery charging */
-    M_BATT,    /* on battery */
-    M_LB,      /* low battery */
-    M_CB,      /* critical low battery */
-    M_HCB,     /* battery reported critical capacity state */
-    M_NULL,    /* empty starting state */
-};
-
-static void set_message(void)
-{
-    static enum messages state = M_NULL;
-    battery_t *binfo = globals->binfo;
-    adapter_t *ap = &globals->adapter;
-    
-    /* battery not present case */
-    if (!binfo->present) {
-       if (state != M_NP) {
-           state = M_NP;
-           render_text("not present");
-       }
-    } else if (ap->power == AC) {
-       if (binfo->charge_state == CHARGE) {
-           if (state != M_CH) {
-               state = M_CH;
-               update_timeout = DEFAULT_UPDATE;
-               render_text("battery charging");
-           }
-       } else {
-           if (state != M_AC) {
-               state = M_AC;
-               update_timeout = DEFAULT_UPDATE;
-               render_text("on ac power");
-           }
-       }
-    } else {
-       if (binfo->state == CRIT) {
-           if (state != M_CB) {
-               state = M_CB;
-               update_timeout = 80;
-               render_text("critical low battery");
-           }
-       } else if (binfo->state == HARD_CRIT) {
-           if (state != M_HCB) {
-               state = M_HCB;
-               update_timeout = 60;
-               render_text("hard critical low battery");
-           }
-       } else if (binfo->state == LOW) {
-           if (state != M_LB) {
-               state = M_LB;
-               update_timeout = 100;
-               render_text("low battery");
-           }
-       } else {
-           if (state != M_BATT) {
-               state = M_BATT;
-               update_timeout = DEFAULT_UPDATE;
-               render_text("on battery");
-           }
-       }
-    }    
-}
-
-void set_time_display(void)
-{
-    battery_t *binfo = &batteries[battery_no];
-    
-    if (binfo->charge_state == CHARGE)
-       display_time(binfo->charge_time);
-    else if (binfo->charge_state == DISCHARGE)
-       display_time(globals->rtime);
-    else
-       invalid_time_display();
-}
-
-/*
- * This should really be fixed so that it can handle more than two batteries.
- */
-
-void set_id_1(void)
-{
-    copy_xpm_area(118, 38, 15, 15, 44, 30);
-}    
-
-void set_id_2(void)
-{
-    copy_xpm_area(136, 38, 15, 15, 44, 30);
-}
-
-void set_batt_id_area(int bno)
-{
-    switch(bno) {
-    case 0:
-       set_id_1();
-       break;
-    case 1:
-       set_id_2();
-       break;
-    }
-}
-
-void usage(char *name)
-{
-    printf("%s - help\t\t[[email protected]]\n\n"
-          "-d display\t\tdisplay on remote display <display>\n"
-          "-b\t\t\tmake noise when battery is critical low (beep)\n"
-          "-c value\t\tset critical low alarm at <value> percent\n"
-          "\t\t\t(default: 10 percent)\n"
-          "-m <battery number>\tbattery number to monitor\n"
-          "-v\t\t\tincrease verbosity.\n"
-          "-h\t\t\tdisplay this help\n",
-          name);
-}
-
-void print_version(void)
-{
-    printf("wmacpi-ng version %s\n", WMACPI_NG_VER);
-    printf(" Using libacpi version %s\n", LIBACPI_VER);
-}
-
-int main(int argc, char **argv)
-{
-    char *display = NULL;
-    char ch;
-    int update = 0;
-    int samplerate = 100;
-    battery_t *binfo;
-
-    dockapp = calloc(1, sizeof(Dockapp));
-    globals = calloc(1, sizeof(global_t));
-
-    dockapp->blink = 1;
-    globals->crit_level = 10;
-    battery_no = 1;
-
-    /* see if whatever we want to use is supported */
-    if (power_init())
-       /* power_init functions handle printing error messages */
-       exit(1);
-
-    /* parse command-line options */
-    while ((ch = getopt(argc, argv, "bd:c:m:s:hnvV")) != EOF) {
-       switch (ch) {
-       case 'b':
-           noisy_critical = 1;
-           break;
-       case 'c':
-           if (optarg) {
-               globals->crit_level = atoi(optarg);
-               if ((globals->crit_level < 0) || (globals->crit_level > 100)) {
-                   fprintf(stderr, "Please use values between 0 and 100%%\n");
-                   globals->crit_level = 10;
-                   fprintf(stderr, "Using default value of 10%%\n");
-               }
-           }
-           break;
-       case 'd':
-           if (optarg)
-               display = strdup(optarg);
-           break;
-       case 'm':
-           if (optarg) {
-               battery_no = atoi(optarg);
-               if (battery_no >= MAXBATT) {
-                   fprintf(stderr, "Please specify a battery number below 
%d\n",
-                           MAXBATT);
-                   return 1;
-               }
-               if (battery_no > batt_count) {
-                   fprintf(stderr, "Battery %d does not appear to be 
installed\n",
-                           battery_no);
-                   return 1;
-               }
-               fprintf(stderr, "Monitoring battery %d\n", battery_no);
-           } 
-           break;
-       case 's':
-           if (optarg) {
-               samplerate = atoi(optarg);
-               if (samplerate == 0) samplerate = 1;
-               if (samplerate > 3000) samplerate = 3000;
-           } else {
-               usage(argv[0]);
-               exit(1);
-           }
-           break;
-       case 'h':
-           usage(argv[0]);
-           return 0;
-       case 'v':
-           verbosity++;
-           break;
-       case 'V':
-           print_version();
-           return 0;
-       case 'n':
-           dockapp->blink = 0;
-           break;
-       default:
-           usage(argv[0]);
-           return 1;
-       }
-       
-    }
-    battery_no--;
-
-    /* open local or command-line specified display */
-    if (open_display(display))
-       exit(1);
-
-    /* make new dockapp window */
-    /* Don't even /think/ of asking me why, but if I set the window name to 
-     * "acpi", the app refuses to dock properly - it's just plain /weird/ */
-/*    new_window("acpi"); */
-    new_window("apm");
-
-    /* get initial statistics */
-    acquire_all_info();
-    binfo = &batteries[battery_no];
-    globals->binfo = binfo;
-    fprintf(stderr, "monitoring battery %s\n", binfo->name);
-    clear_time_display();
-    set_power_panel();
-    set_message();
-    set_batt_id_area(battery_no);
-
-    /* main loop */
-    while (1) {
-       XEvent event;
-       while (XPending(dockapp->display)) {
-           eprint(0, "X11 activity");
-           XNextEvent(dockapp->display, &event);
-           switch (event.type) {
-           case Expose:
-               /* update */
-               dockapp->update = 1;
-               while (XCheckTypedEvent(dockapp->display, Expose, &event));
-               redraw_window();
-               break;
-           case DestroyNotify:
-               XCloseDisplay(dockapp->display);
-               exit(0);
-               break;
-           case ButtonPress:
-               break;
-           case ButtonRelease:
-               /* cycle through the known batteries. */
-               battery_no++;
-               battery_no = battery_no % batt_count;
-               globals->binfo = &batteries[battery_no];
-               binfo = globals->binfo;
-               fprintf(stderr, "changing to monitor battery %d\n", battery_no 
+ 1);
-               set_batt_id_area(battery_no);
-               break;
-           }
-       }
-
-       /* XXX: some laptops have problems with sampling the battery
-        * regularly - apparently, the BIOS disables interrupts while
-        * reading from the battery, which is generally on a slow bus 
-        * and is a slow device, so you get significant periods without
-        * interrupts. This causes interactivity to suffer . . . 
-        * 
-        * My proposed workaround is to allow the user to set the sample
-        * rate - it defaults to ten, but can be set lower (or higher).
-        *
-        * The only problem with this is that we need to sample less 
-        * frequently, while still allowing the app to update normally. 
-        * That means calling redraw_window() and all the set_*() functions
-        * normally, but only calling acquire_all_info() every so often. 
-        * As it stands, we only call acquire_all_info() once every three
-        * seconds (once every thirty updates) . . . I'm not entirely sure
-        * /how/ this could cause interactivity problems, but hey . . . 
-        *
-        * So, given the base rate of once every three seconds, we want to
-        * change this test to . . . */
-       if (update++ == (3000/samplerate)) {
-           acquire_all_info();
-           update = 0;
-       }
-
-       if (count++ == update_timeout) {
-           scroll_text(6, 50, 52, dockapp->tw, 1);
-           count = 0;
-       }
-
-       /* the old code had some kind of weird crap with timers and the like. 
-        * As far as I can tell, it's meaningless - the time we want to display
-        * is the time calculated from the remaining capacity, as per the 
-        * ACPI spec. The only thing I'd change is the handling of a charging
-        * state: my best guess, based on the behaviour I'm seeing with my 
-        * Lifebook, is that the present rate value when charging is the rate
-        * at which the batteries are being charged, which would mean I'd just
-        * need to reverse the rtime calculation to be able to work out how 
-        * much time remained until the batteries were fully charged . . . 
-        * That would be rather useful, though given it would vary rather a lot
-        * it seems likely that it'd be little more than a rough guesstimate. */
-       set_time_display();
-       set_power_panel();
-       set_message();
-       display_percentage(binfo->percentage);
-       scroll_text(6, 50, 52, dockapp->tw, 0);
-
-       /* redraw_window, if anything changed - determined inside 
-        * redraw_window. */
-       redraw_window();
-       usleep(100000);
-    }
-    return 0;
-}
diff --git a/wmacpi/wmacpi-ng.h b/wmacpi/wmacpi-ng.h
deleted file mode 100644
index a49acdf..0000000
--- a/wmacpi/wmacpi-ng.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef _WMACPI_H_
-#define _WMACPI_H_
-
-#include "libacpi.h"
-
-/* we need to make these available generally. */
-int battery_no;
-
-#endif /* _WMACPI_H_ */
diff --git a/wmacpi/wmacpi.1 b/wmacpi/wmacpi.1
new file mode 100644
index 0000000..a9a6f6c
--- /dev/null
+++ b/wmacpi/wmacpi.1
@@ -0,0 +1,144 @@
+.TH WMACPI-NG 1 "July 11, 2003"
+.SH NAME
+wmacpi \- Battery status monitor for systems supporting ACPI
+.SH NAME
+acpi \- Query battery status for systems supporting ACPI
+.SH SYNOPSIS
+.B wmacpi
+[
+.RI -c
+value ]
+[
+.RI -d
+display ]
+[
+.RI -m
+battery no ]
+[
+.RI -s
+sample rate ]
+[
+.RI -v
+]
+]
+.RI -n
+]
+[
+.RI -w
+]
+[
+.RI -a
+samples ]
+[
+.RI -V
+]
+[
+.RI -h
+]
+.PP
+.B acpi
+[
+.RI -a
+samples ]
+[
+.RI -v 
+]
+[
+.RI -V
+]
+[
+.RI -h
+]
+.SH DESCRIPTION
+This manual page documents briefly the
+.B wmacpi
+command.
+.PP
+.B wmacpi
+is a program that displays the current battery status in a WindowMaker
+dock app, on systems that support Intel's Advanced Configuration and
+Power Interface specification (ACPI).
+.PP
+The program monitors a battery, displaying its current percentage
+charge via a bar and a numeric value. It also displays the current
+power status for the system, the time remaining (calculated based on
+the remaining battery capacity and the current rate of power usage),
+and a scrolling message with some hopefully useful information.
+.PP
+Clicking on the window cycles through the batteries that the ACPI
+system knows about.
+.PP
+.B acpi
+queries the battery status from the command line. It prints the power
+status, the percentage remaining for each battery found, and the time
+remaining if the system is on battery, or the time remaining for each
+battery to reach full charge if the batteries are charging.
+.SH OPTIONS
+.B wmacpi
+.TP
+.B \-c percentage
+Set critical low alarm at <value>% (default: 10%).
+.TP
+.B \-d display
+Set the X display to open the window on.
+.TP
+.B \-m battery number
+Set the battery to monitor initially.
+.TP
+.B \-s sample rate
+Set the rate at which to sample the ACPI data (default is 100, which 
+translates to once every three seconds. 10 gives once every 30 seconds, 
+1 once every 300 seconds (five minutes), 1000 once every 0.3 seconds).
+.TP
+.B \-n
+Disable blinking power glyph when charging. Note that it still blinks when 
+the battery reports its capacity state as critical.
+.TP
+.B \-w
+Run wmacpi in command line mode - this operates identically to 
+.B acpi
+..
+.TP
+.B \-a num
+Average the time remaining over num samples. This greatly improves the
+accuracy of the reported time remaining.
+.TP
+.B \-v
+Increase the verbosity of the program. Can be used more than once -
+each successive use increases the verbosity.
+.TP
+.B \-V
+Print the version information.
+.TP
+.B \-h
+Display help.
+.TP
+.B acpi
+.TP
+.B \-a num
+Average the time remaining over num samples. This greatly improves the
+accuracy of the reported time remaining.
+.TP
+.B \-v
+Increase the verbosity of the program, as for
+.B wmacpi
+.TP
+.B \-V
+Print the version information.
+.TP
+.B \-h
+Display help.
+.TP
+.SH SEE ALSO
+.BR wmapm (1)
+.br
+.SH AUTHOR
+.B wmacpi
+was originally written by Tim Copperfield <[email protected]>, then
+completely rewritten after 1.34 by Simon Fowler <[email protected]>.
+.PP
+This manual page was originally written by Simon Richter
+<[email protected]> for the Debian GNU/Linux system, and then updated by
+Simon Fowler. 
+.br
+Last modification by Simon Fowler <[email protected]>, 2003-11-23.
diff --git a/wmacpi/wmacpi.c b/wmacpi/wmacpi.c
new file mode 100644
index 0000000..158f514
--- /dev/null
+++ b/wmacpi/wmacpi.c
@@ -0,0 +1,856 @@
+/* apm/acpi dockapp - phear it 1.34
+ * Copyright (C) 2000, 2001, 2002 [email protected]
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <getopt.h>
+#include <unistd.h>
+#include <time.h>
+
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/shape.h>
+#include <X11/xpm.h>
+
+#include "libacpi.h"
+#include "wmacpi.h"
+
+#define WMACPI_VER "1.99"
+
+/* main pixmap */
+#ifdef LOW_COLOR
+#include "master_low.xpm"
+#else
+#include "master.xpm"
+#endif
+
+typedef struct {
+    Display *display;          /* X11 display struct */
+    int screen;                        /* current screen */
+    Window root;               /* root window */
+    Window win;                        /* one window */
+    Window iconwin;            /* another one */
+    Pixmap pixmap;             /* UI pixmap, window pixmap */
+    Pixmap mask;               /* mask pixmap for shape */
+    GC gc;                     /* main drawing GC */
+    Pixmap text;               /* pixmap for text scroller */
+    int tw;                    /* text width inside text pixmap */
+    int update;                        /* need to redraw? */
+    int blink;                 /* should we blink the LED? (critical battery) 
*/
+} Dockapp;
+
+/* globals */
+Dockapp *dockapp;
+global_t *globals;
+int count = 0;                 /* global timer variable */
+
+/* Time for scroll updates */
+#define DEFAULT_UPDATE 150
+static int update_timeout = DEFAULT_UPDATE;
+
+/* proto for local stuff */
+static void new_window(char *name);
+static int open_display(char *display);
+static void redraw_window(void);
+static void render_text(char *string);
+static void scroll_text(int x, int y, int width, int tw, int reset);
+static void display_percentage(int percent);
+static void display_time(int minutes);
+
+#define copy_xpm_area(x, y, w, h, dx, dy)                              \
+{                                                                      \
+    XCopyArea(dockapp->display, dockapp->pixmap, dockapp->pixmap,      \
+           dockapp->gc, x, y, w, h, dx, dy);                           \
+    dockapp->update = 1;                                               \
+}
+
+/* display AC power symbol */
+static void display_power_glyph(void)
+{
+    copy_xpm_area(67, 38, 12, 7, 6, 17);
+}
+
+/* get rid of AC power symbol */
+static void kill_power_glyph(void)
+{
+    copy_xpm_area(67, 48, 12, 7, 6, 17);
+}
+
+/* display battery symbol */
+static void display_battery_glyph(void)
+{
+    copy_xpm_area(82, 38, 12, 7, 20, 17);
+}
+
+/* get rid of battery symbol */
+static void kill_battery_glyph(void)
+{
+    copy_xpm_area(82, 48, 12, 7, 20, 17);
+}
+
+/* clear the time display */
+static void clear_time_display(void)
+{
+    copy_xpm_area(114, 76, 31, 11, 7, 32);
+}
+
+/* set time display to -- -- */
+static void invalid_time_display(void)
+{
+    copy_xpm_area(122, 13, 31, 11, 7, 32);
+}
+
+static void redraw_window(void)
+{
+    if (dockapp->update) {
+       XCopyArea(dockapp->display, dockapp->pixmap, dockapp->iconwin,
+                 dockapp->gc, 0, 0, 64, 64, 0, 0);
+       XCopyArea(dockapp->display, dockapp->pixmap, dockapp->win,
+                 dockapp->gc, 0, 0, 64, 64, 0, 0);
+       dockapp->update = 0;
+    }
+}
+
+static void new_window(char *name)
+{
+    XpmAttributes attr;
+    Pixel fg, bg;
+    XGCValues gcval;
+    XSizeHints sizehints;
+    XClassHint classhint;
+    XWMHints wmhints;
+
+    dockapp->screen = DefaultScreen(dockapp->display);
+    dockapp->root = DefaultRootWindow(dockapp->display);
+
+    sizehints.flags = USSize;
+    sizehints.width = 64;
+    sizehints.height = 64;
+
+    fg = BlackPixel(dockapp->display, dockapp->screen);
+    bg = WhitePixel(dockapp->display, dockapp->screen);
+
+    dockapp->win = XCreateSimpleWindow(dockapp->display, dockapp->root,
+                                      0, 0, sizehints.width,
+                                      sizehints.height, 1, fg, bg);
+    dockapp->iconwin =
+       XCreateSimpleWindow(dockapp->display, dockapp->win, 0, 0,
+                           sizehints.width, sizehints.height, 1, fg, bg);
+
+    XSetWMNormalHints(dockapp->display, dockapp->win, &sizehints);
+    classhint.res_name = name;
+    classhint.res_class = name;
+    XSetClassHint(dockapp->display, dockapp->win, &classhint);
+
+    XSelectInput(dockapp->display, dockapp->win,
+                ExposureMask | ButtonPressMask | ButtonReleaseMask |
+                StructureNotifyMask);
+    XSelectInput(dockapp->display, dockapp->iconwin,
+                ExposureMask | ButtonPressMask | ButtonReleaseMask |
+                StructureNotifyMask);
+
+    XStoreName(dockapp->display, dockapp->win, name);
+    XSetIconName(dockapp->display, dockapp->win, name);
+
+    gcval.foreground = fg;
+    gcval.background = bg;
+    gcval.graphics_exposures = False;
+
+    dockapp->gc =
+       XCreateGC(dockapp->display, dockapp->win,
+                 GCForeground | GCBackground | GCGraphicsExposures,
+                 &gcval);
+
+    attr.exactColors = 0;
+    attr.alloc_close_colors = 1;
+    attr.closeness = 1L << 15;
+    attr.valuemask = XpmExactColors | XpmAllocCloseColors | XpmCloseness;
+    if (XpmCreatePixmapFromData(dockapp->display, dockapp->win,
+                               master_xpm, &dockapp->pixmap,
+                               &dockapp->mask, &attr) != XpmSuccess) {
+       pfatal("FATAL: Not enough colors for main pixmap!\n");
+       exit(1);
+    }
+
+    /* text area is 318x7, or 53 characters long */
+    dockapp->text = XCreatePixmap(dockapp->display, dockapp->win, 318, 7,
+                                 DefaultDepth(dockapp->display,
+                                              dockapp->screen));
+    if (!dockapp->text) {
+       pfatal("FATAL: Cannot create text scroll pixmap!\n");
+       exit(1);
+    }
+
+    XShapeCombineMask(dockapp->display, dockapp->win, ShapeBounding, 0, 0,
+                     dockapp->mask, ShapeSet);
+    XShapeCombineMask(dockapp->display, dockapp->iconwin, ShapeBounding, 0,
+                     0, dockapp->mask, ShapeSet);
+
+    wmhints.initial_state = WithdrawnState;
+    wmhints.flags = StateHint;
+    wmhints.icon_window = dockapp->iconwin;
+    wmhints.icon_x = sizehints.x;
+    wmhints.icon_y = sizehints.y;
+    wmhints.window_group = dockapp->win;
+    wmhints.flags =
+       StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;
+    XSetWMHints(dockapp->display, dockapp->win, &wmhints);
+
+    XMapWindow(dockapp->display, dockapp->win);
+}
+
+static void render_text(char *string)
+{
+    int i, c, k;
+
+    if (strlen(string) > 53)
+       return;
+
+    /* prepare the text area by clearing it */
+    for (i = 0; i < 54; i++) {
+       XCopyArea(dockapp->display, dockapp->pixmap, dockapp->text,
+                 dockapp->gc, 133, 57, 6, 8, i * 6, 0);
+    }
+    k = 0;
+
+    for (i = 0; string[i]; i++) {
+       c = toupper(string[i]);
+       if (c >= 'A' && c <= 'Z') {     /* letter */
+           c = c - 'A';
+           XCopyArea(dockapp->display, dockapp->pixmap, dockapp->text,
+                     dockapp->gc, c * 6, 67, 6, 7, k, 0);
+       } else if (c >= '0' && c <= '9') {      /* number */
+           c = c - '0';
+           XCopyArea(dockapp->display, dockapp->pixmap, dockapp->text,
+                     dockapp->gc, c * 6 + 66, 58, 6, 7, k, 0);
+       } else if (c == '.') {
+           XCopyArea(dockapp->display, dockapp->pixmap, dockapp->text,
+                     dockapp->gc, 140, 58, 6, 7, k, 0);
+       } else if (c == '-') {
+           XCopyArea(dockapp->display, dockapp->pixmap, dockapp->text,
+                     dockapp->gc, 126, 58, 6, 7, k, 0);
+       }
+       k += 6;
+    }
+    dockapp->tw = k;           /* length of text segment */
+    /* re-scroll the message */
+    scroll_text(6, 50, 52, dockapp->tw, 1);
+    /* reset the scroll repeat counter */
+    count = 0;
+}
+
+static int open_display(char *display)
+{
+    dockapp->display = XOpenDisplay(display);
+    if (!dockapp->display) {
+       perr("Unable to open display '%s'\n", display);
+       return 1;
+    }
+    return 0;
+}
+
+static void scroll_text(int x, int y, int width, int tw, int reset)
+{
+    static int pos, first, stop;
+
+    if (reset) {
+       pos = 0;
+       first = 0;
+       stop = 0;
+       XCopyArea(dockapp->display, dockapp->pixmap, dockapp->text,
+                 dockapp->gc, 0, 0, width, 7, x, y);
+    }
+
+    if (stop) {
+       return;
+    }
+
+    if ((first == 0) && pos == 0) {
+       pos = width;
+       first = 1;
+    }
+
+    if (pos == (0 - tw - 2)) {
+       first = 1;
+       pos = width;
+       stop = 1;
+       return;
+    }
+    pos -= 2;
+
+    if (pos > 0) {
+       copy_xpm_area(66, 9, pos, 7, x, y);     /* clear */
+       XCopyArea(dockapp->display, dockapp->text, dockapp->pixmap,
+                 dockapp->gc, 0, 0, width - pos, 7, x + pos, y);
+    } else {                   /* don't need to clear, already in text */
+       XCopyArea(dockapp->display, dockapp->text, dockapp->pixmap,
+                 dockapp->gc, abs(pos), 0, width, 7, x, y);
+    }
+    dockapp->update = 1;
+}
+
+static void display_percentage(int percent)
+{
+    static int op = -1;
+    static unsigned int obar;
+    unsigned int bar;
+
+    if (percent == -1)
+       percent = 0;
+
+    if (op == percent)
+       return;
+
+    if (percent < 0)
+       percent = 0;
+    if (percent > 100)
+       percent = 100;
+
+    if (percent < 100) {       /* 0 - 99 */
+       copy_xpm_area(95, 48, 8, 7, 37, 17);
+       if (percent >= 10)
+           copy_xpm_area((percent / 10) * 6 + 67, 28, 5, 7, 40, 17);
+       copy_xpm_area((percent % 10) * 6 + 67, 28, 5, 7, 46, 17);
+    } else
+       copy_xpm_area(95, 37, 21, 9, 37, 16);   /* 100% */
+    op = percent;
+
+    bar = percent / 1.8518;
+
+    if (bar == obar)
+       return;
+
+    copy_xpm_area(66, 0, bar, 8, 5, 5);
+    if (bar < 54)
+       copy_xpm_area(66 + bar, 18, 54 - bar, 8, bar + 5, 5);
+    obar = bar;
+}
+
+static void display_time(int minutes)
+{
+    static int ohour = -1, omin = -1;
+    int hour, min, tmp;
+
+    if (minutes <= 0) {        /* error - clear the display */
+       invalid_time_display();
+       ohour = omin = -1;
+       return;
+    }
+
+    /* render time on the display */
+    hour = minutes / 60;
+    /* our display area only fits %2d:%2d, so we need to make sure
+     * what we're displaying will fit in those constraints. I don't
+     * think we're likely to see any batteries that do more than 
+     * 100 hours any time soon, so it's fairly safe. */
+    if (hour >= 100) {
+       hour = 99;
+       min = 59;
+    } else
+       min = minutes % 60;
+
+    if (hour == ohour && min == omin)
+       return;
+
+    tmp = hour / 10;
+    copy_xpm_area(tmp * 7 + 1, 76, 6, 11, 7, 32);
+    tmp = hour % 10;
+    copy_xpm_area(tmp * 7 + 1, 76, 6, 11, 14, 32);
+    tmp = min / 10;
+    copy_xpm_area(tmp * 7 + 1, 76, 6, 11, 25, 32);
+    tmp = min % 10;
+    copy_xpm_area(tmp * 7 + 1, 76, 6, 11, 32, 32);
+    copy_xpm_area(71, 76, 3, 11, 21, 32);
+    ohour = hour;
+    omin = min;
+}
+
+/* 
+ * The reworked state handling stuff.
+ */
+
+/* set the current state of the power panel */
+enum panel_states {
+    PS_AC,
+    PS_BATT,
+    PS_NULL,
+};
+
+static void really_blink_power_glyph(void)
+{
+    static int counter = 0;
+
+    if (counter == 10) 
+       display_power_glyph();
+    else if (counter == 20) 
+       kill_power_glyph();
+    else if (counter > 30)
+       counter = 0;
+    counter++;
+}
+
+static void blink_power_glyph(void)
+{
+    if (dockapp->blink)
+       really_blink_power_glyph();
+}
+
+static void really_blink_battery_glyph(void)
+{
+    static int counter = 0;
+
+    if (counter == 10)
+       display_battery_glyph();
+    else if (counter == 20)
+       kill_battery_glyph();
+    else if (counter > 30)
+       counter = 0;
+    counter++;
+}    
+
+static void blink_battery_glyph(void)
+{
+    if (dockapp->blink)
+       really_blink_battery_glyph();
+}
+
+static void set_power_panel(void)
+{
+    enum panel_states power = PS_NULL;
+    battery_t *binfo = globals->binfo;
+    adapter_t *ap = &globals->adapter;
+
+    if (ap->power == AC) {
+       if (power != PS_AC) {
+           power = PS_AC;
+           kill_battery_glyph();
+           display_power_glyph();
+       }
+    } else if (ap->power == BATT) {
+       if (power != PS_BATT) {
+           power = PS_BATT;
+           kill_power_glyph();
+           display_battery_glyph();
+       }
+    }
+
+    if (binfo->charge_state == CHARGE)
+       blink_power_glyph();
+
+    if (binfo->state == CRIT)
+       blink_battery_glyph();
+
+    if (binfo->state == HARD_CRIT)
+       really_blink_battery_glyph();
+}
+
+/* 
+ * The message that needs to be displayed needs to be decided
+ * according to a heirarchy: a message like not present needs to take
+ * precedence over a global thing like the current power status, and
+ * something like a low battery warning should take precedence over
+ * the "on battery" message. Likewise, a battery charging message
+ * needs to take precedence over the on ac power message. The other
+ * question is how much of a precedence local messages should take
+ * over global ones . . . 
+ *
+ * So, there are three possible sets of messages: not present, on-line
+ * and off-line messages. We need to decide which of those sets is
+ * appropriate right now, and then decide within them. 
+ */
+enum messages {
+    M_NP,      /* not present */
+    M_AC,      /* on ac power */
+    M_CH,      /* battery charging */
+    M_BATT,    /* on battery */
+    M_LB,      /* low battery */
+    M_CB,      /* critical low battery */
+    M_HCB,     /* battery reported critical capacity state */
+    M_NULL,    /* empty starting state */
+};
+
+static void set_message(void)
+{
+    static enum messages state = M_NULL;
+    battery_t *binfo = globals->binfo;
+    adapter_t *ap = &globals->adapter;
+    
+    /* battery not present case */
+    if (!binfo->present) {
+       if (state != M_NP) {
+           state = M_NP;
+           render_text("not present");
+       }
+    } else if (ap->power == AC) {
+       if (binfo->charge_state == CHARGE) {
+           if (state != M_CH) {
+               state = M_CH;
+               update_timeout = DEFAULT_UPDATE;
+               render_text("battery charging");
+           }
+       } else {
+           if (state != M_AC) {
+               state = M_AC;
+               update_timeout = DEFAULT_UPDATE;
+               render_text("on ac power");
+           }
+       }
+    } else {
+       if (binfo->state == CRIT) {
+           if (state != M_CB) {
+               state = M_CB;
+               update_timeout = 80;
+               render_text("critical low battery");
+           }
+       } else if (binfo->state == HARD_CRIT) {
+           if (state != M_HCB) {
+               state = M_HCB;
+               update_timeout = 60;
+               render_text("hard critical low battery");
+           }
+       } else if (binfo->state == LOW) {
+           if (state != M_LB) {
+               state = M_LB;
+               update_timeout = 100;
+               render_text("low battery");
+           }
+       } else {
+           if (state != M_BATT) {
+               state = M_BATT;
+               update_timeout = DEFAULT_UPDATE;
+               render_text("on battery");
+           }
+       }
+    }    
+}
+
+void set_time_display(void)
+{
+    battery_t *binfo = &batteries[battery_no];
+    
+    if (binfo->charge_state == CHARGE)
+       display_time(binfo->charge_time);
+    else if (binfo->charge_state == DISCHARGE)
+       display_time(globals->rtime);
+    else
+       invalid_time_display();
+}
+
+/*
+ * This should really be fixed so that it can handle more than two batteries.
+ */
+
+void set_id_1(void)
+{
+    copy_xpm_area(118, 38, 15, 15, 44, 30);
+}    
+
+void set_id_2(void)
+{
+    copy_xpm_area(136, 38, 15, 15, 44, 30);
+}
+
+void set_batt_id_area(int bno)
+{
+    switch(bno) {
+    case 0:
+       set_id_1();
+       break;
+    case 1:
+       set_id_2();
+       break;
+    }
+}
+
+void usage(char *name)
+{
+    printf("%s - help\t\t[[email protected]]\n\n"
+          "-d display\t\tdisplay on remote display <display>\n"
+          "-b\t\t\tmake noise when battery is critical low (beep)\n"
+          "-c value\t\tset critical low alarm at <value> percent\n"
+          "\t\t\t(default: 10 percent)\n"
+          "-m <battery number>\tbattery number to monitor\n"
+          "-v\t\t\tincrease verbosity.\n"
+          "-h\t\t\tdisplay this help\n",
+          name);
+}
+
+void print_version(void)
+{
+    printf("wmacpi version %s\n", WMACPI_VER);
+    printf(" Using libacpi version %s\n", LIBACPI_VER);
+}
+
+void cli_wmacpi(int samples)
+{
+    int i, j, sleep_time;
+    battery_t *binfo;
+    adapter_t *ap;
+    
+    sleep_time = 1000000/samples;
+
+    /* we want to acquire samples over some period of time, so . . . */
+    for(i = 0; i < samples + 2; i++) {
+       for(j = 0; j < batt_count; j++)
+           acquire_batt_info(j);
+       acquire_global_info();
+       usleep(sleep_time);
+    }
+    
+    ap = &globals->adapter;
+    if(ap->power == AC) {
+       printf("On AC Power");
+       for(i = 0; i < batt_count; i++) {
+           binfo = &batteries[i];
+           if(binfo->present && (binfo->charge_state == CHARGE)) {
+               printf("; Battery %s charging", binfo->name);
+               printf(", currently at %2d%%", binfo->percentage);
+               if(binfo->charge_time >= 0) 
+                   printf(", %2d:%02d remaining", 
+                          binfo->charge_time/60,
+                          binfo->charge_time%60);
+           }
+       }
+       printf("\n");
+    } else if(ap->power == BATT) {
+       printf("On Battery");
+       for(i = 0; i < batt_count; i++) {
+           binfo = &batteries[i];
+           if(binfo->present && (binfo->percentage >= 0))
+               printf(", Battery %s at %d%%", binfo->name,
+                      binfo->percentage);
+       }
+       if(globals->rtime >= 0)
+           printf("; %d:%02d remaining", globals->rtime/60, 
+                  globals->rtime%60);
+       printf("\n");
+    }
+    return;
+}
+
+int main(int argc, char **argv)
+{
+    char *display = NULL;
+    char ch;
+    int update = 0;
+    int cli = 0, samples = 1;
+    int samplerate = 100;
+    battery_t *binfo;
+
+    dockapp = calloc(1, sizeof(Dockapp));
+    globals = calloc(1, sizeof(global_t));
+
+    dockapp->blink = 1;
+    globals->crit_level = 10;
+    battery_no = 1;
+
+    /* see if whatever we want to use is supported */
+    if (power_init())
+       /* power_init functions handle printing error messages */
+       exit(1);
+
+    /* parse command-line options */
+    while ((ch = getopt(argc, argv, "d:c:m:s:a:hnwvV")) != EOF) {
+       switch (ch) {
+       case 'c':
+           if (optarg) {
+               globals->crit_level = atoi(optarg);
+               if ((globals->crit_level < 0) || (globals->crit_level > 100)) {
+                   fprintf(stderr, "Please use values between 0 and 100%%\n");
+                   globals->crit_level = 10;
+                   fprintf(stderr, "Using default value of 10%%\n");
+               }
+           }
+           break;
+       case 'd':
+           if (optarg)
+               display = strdup(optarg);
+           break;
+       case 'm':
+           if (optarg) {
+               battery_no = atoi(optarg);
+               if (battery_no >= MAXBATT) {
+                   fprintf(stderr, "Please specify a battery number below 
%d\n",
+                           MAXBATT);
+                   return 1;
+               }
+               if (battery_no > batt_count) {
+                   fprintf(stderr, "Battery %d does not appear to be 
installed\n",
+                           battery_no);
+                   return 1;
+               }
+               fprintf(stderr, "Monitoring battery %d\n", battery_no);
+           } 
+           break;
+       case 's':
+           if (optarg) {
+               samplerate = atoi(optarg);
+               if (samplerate == 0) samplerate = 1;
+               if (samplerate > 3000) samplerate = 3000;
+           } else {
+               usage(argv[0]);
+               exit(1);
+           }
+           break;
+       case 'h':
+           usage(argv[0]);
+           return 0;
+       case 'v':
+           verbosity++;
+           break;
+       case 'V':
+           print_version();
+           return 0;
+       case 'n':
+           dockapp->blink = 0;
+           break;
+       case 'w':
+           cli = 1;
+           break;
+       case 'a':
+           if(optarg != NULL) {
+               samples = atoi(optarg);
+               if(samples > 1000 || samples <= 0) {
+                   printf("Please specify a reasonable number of samples\n");
+                   exit(1);
+               }
+           }
+           break;
+       default:
+           usage(argv[0]);
+           return 1;
+       }
+       
+    }
+    
+    /* check for cli mode */
+    if (cli) {
+       cli_wmacpi(samples);
+       exit(0);
+    }
+
+    battery_no--;
+
+    /* open local or command-line specified display */
+    if (open_display(display))
+       exit(1);
+
+    /* make new dockapp window */
+    /* Don't even /think/ of asking me why, but if I set the window name to 
+     * "acpi", the app refuses to dock properly - it's just plain /weird/ */
+/*    new_window("acpi"); */
+    new_window("apm");
+
+    /* get initial statistics */
+    acquire_all_info();
+    binfo = &batteries[battery_no];
+    globals->binfo = binfo;
+    pinfo("monitoring battery %s\n", binfo->name);
+    clear_time_display();
+    set_power_panel();
+    set_message();
+    set_batt_id_area(battery_no);
+
+    /* main loop */
+    while (1) {
+       XEvent event;
+       while (XPending(dockapp->display)) {
+           XNextEvent(dockapp->display, &event);
+           switch (event.type) {
+           case Expose:
+               /* update */
+               dockapp->update = 1;
+               while (XCheckTypedEvent(dockapp->display, Expose, &event));
+               redraw_window();
+               break;
+           case DestroyNotify:
+               XCloseDisplay(dockapp->display);
+               exit(0);
+               break;
+           case ButtonPress:
+               break;
+           case ButtonRelease:
+               /* cycle through the known batteries. */
+               battery_no++;
+               battery_no = battery_no % batt_count;
+               globals->binfo = &batteries[battery_no];
+               binfo = globals->binfo;
+               pinfo("changing to monitor battery %d\n", battery_no + 1);
+               set_batt_id_area(battery_no);
+               break;
+           }
+       }
+
+       /* XXX: some laptops have problems with sampling the battery
+        * regularly - apparently, the BIOS disables interrupts while
+        * reading from the battery, which is generally on a slow bus 
+        * and is a slow device, so you get significant periods without
+        * interrupts. This causes interactivity to suffer . . . 
+        * 
+        * My proposed workaround is to allow the user to set the sample
+        * rate - it defaults to ten, but can be set lower (or higher).
+        *
+        * The only problem with this is that we need to sample less 
+        * frequently, while still allowing the app to update normally. 
+        * That means calling redraw_window() and all the set_*() functions
+        * normally, but only calling acquire_all_info() every so often. 
+        * As it stands, we only call acquire_all_info() once every three
+        * seconds (once every thirty updates) . . . I'm not entirely sure
+        * /how/ this could cause interactivity problems, but hey . . . 
+        *
+        * So, given the base rate of once every three seconds, we want to
+        * change this test to . . . */
+       if (update++ == (3000/samplerate)) {
+           acquire_all_info();
+           update = 0;
+       }
+
+       if (count++ == update_timeout) {
+           scroll_text(6, 50, 52, dockapp->tw, 1);
+           count = 0;
+       }
+
+       /* the old code had some kind of weird crap with timers and the like. 
+        * As far as I can tell, it's meaningless - the time we want to display
+        * is the time calculated from the remaining capacity, as per the 
+        * ACPI spec. The only thing I'd change is the handling of a charging
+        * state: my best guess, based on the behaviour I'm seeing with my 
+        * Lifebook, is that the present rate value when charging is the rate
+        * at which the batteries are being charged, which would mean I'd just
+        * need to reverse the rtime calculation to be able to work out how 
+        * much time remained until the batteries were fully charged . . . 
+        * That would be rather useful, though given it would vary rather a lot
+        * it seems likely that it'd be little more than a rough guesstimate. */
+       set_time_display();
+       set_power_panel();
+       set_message();
+       display_percentage(binfo->percentage);
+       scroll_text(6, 50, 52, dockapp->tw, 0);
+
+       /* redraw_window, if anything changed - determined inside 
+        * redraw_window. */
+       redraw_window();
+       usleep(100000);
+    }
+    return 0;
+}
diff --git a/wmacpi/wmacpi.h b/wmacpi/wmacpi.h
new file mode 100644
index 0000000..a49acdf
--- /dev/null
+++ b/wmacpi/wmacpi.h
@@ -0,0 +1,9 @@
+#ifndef _WMACPI_H_
+#define _WMACPI_H_
+
+#include "libacpi.h"
+
+/* we need to make these available generally. */
+int battery_no;
+
+#endif /* _WMACPI_H_ */
-- 
1.9.1


-- 
To unsubscribe, send mail to [email protected].

Reply via email to