wmacpi: Bump to version 1.99.
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.
This commit is contained in:
parent
310714058f
commit
6961aed640
|
@ -1,3 +1,6 @@
|
|||
Simon Fowler <simon@dreamcraft.com.au>
|
||||
Complete rewriting of the code from wmacpi-1.34.
|
||||
|
||||
timecop
|
||||
timecop@japan.co.jp
|
||||
all the code
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,10 +1,20 @@
|
|||
to install:
|
||||
The basic install is very simple: make, make 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)
|
||||
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 <simon@dreamcraft.com.au>, 2003-11-23
|
|
@ -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)
|
||||
|
||||
wmacpi: $(WMOBJ)
|
||||
$(CC) $(LDFLAGS) -o $@ $^
|
||||
|
||||
# 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)
|
||||
|
||||
wmacpi-ng: $(WMOBJ)
|
||||
$(CC) $(LDFLAGS) -o $@ $^
|
||||
|
||||
acpi-ng: $(CLOBJ)
|
||||
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.
|
||||
|
|
|
@ -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.
|
||||
**********************************************************************
|
||||
|
||||
******************************************************************************
|
||||
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.
|
||||
|
||||
Implementation of "ACPI" mode:
|
||||
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).
|
||||
|
||||
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)
|
||||
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.
|
||||
|
||||
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.
|
||||
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 . . .
|
||||
|
||||
Implementation of "APM" mode
|
||||
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.
|
||||
|
||||
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 <daniel@rimspace.net>, 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):
|
||||
Please report bugs to <simon@dreamcraft.com.au>.
|
||||
|
||||
#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
|
||||
Simon Fowler, 2003-11-23.
|
|
@ -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.
|
||||
|
||||
|
|
1
wmacpi/acpi.1
Normal file
1
wmacpi/acpi.1
Normal file
|
@ -0,0 +1 @@
|
|||
.so man1/wmacpi.1
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
#include "libacpi.h"
|
||||
|
||||
#define ACPI_NG_VER "0.99"
|
||||
#define ACPI_VER "1.99"
|
||||
|
||||
global_t *globals;
|
||||
|
||||
|
@ -44,7 +44,7 @@ void usage(char *name)
|
|||
|
||||
void print_version(void)
|
||||
{
|
||||
printf("acpi-ng version %s\n", ACPI_NG_VER);
|
||||
printf("acpi version %s\n", ACPI_VER);
|
||||
printf(" Using libacpi version %s\n", LIBACPI_VER);
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
.so man1/wmacpi-ng.1
|
|
@ -1,21 +1,20 @@
|
|||
Source: wmacpi-ng
|
||||
Source: wmacpi
|
||||
Section: x11
|
||||
Priority: optional
|
||||
Maintainer: Simon Fowler <simon@dreamcraft.com.au>
|
||||
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 <simon@dreamcraft.com.au>
|
||||
This is a reworked version to handle modern kernels, done by Simon
|
||||
Fowler <simon@dreamcraft.com.au>
|
||||
.
|
||||
Author: Tim Copperfield <timecop@japan.co.jp>
|
||||
Homepage: http://www.ne.jp/asahi/linux/timecop/
|
||||
Author: Simon Fowler <simon@dreamcraft.com.au>
|
||||
Homepage: http://himi.org/wmacpi-ng/
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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...) \
|
||||
#define pdebug(fmt, arg...) \
|
||||
do { \
|
||||
if (level > verbosity) { \
|
||||
switch (level) { \
|
||||
case 0: \
|
||||
break; \
|
||||
case 1: \
|
||||
if (verbosity > 2) \
|
||||
fprintf(stderr, fmt, ##arg); \
|
||||
break; \
|
||||
default: \
|
||||
fprintf(stderr, "%s: " fmt, __FUNCTION__, ##arg); \
|
||||
fprintf(stderr, "\n"); \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* since these /are/ needed here . . . */
|
||||
#define pinfo(fmt, arg...) \
|
||||
do { \
|
||||
if (verbosity > 1) \
|
||||
fprintf(stderr, fmt, ##arg); \
|
||||
} while (0)
|
||||
|
||||
#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;
|
||||
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
.TH WMACPI-NG 1 "July 11, 2003"
|
||||
.SH NAME
|
||||
wmacpi-ng \- Battery status monitor for systems supporting ACPI
|
||||
wmacpi \- Battery status monitor for systems supporting ACPI
|
||||
.SH NAME
|
||||
acpi-ng \- Query battery status for systems supporting ACPI
|
||||
acpi \- Query battery status for systems supporting ACPI
|
||||
.SH SYNOPSIS
|
||||
.B wmacpi-ng
|
||||
[
|
||||
.RI -b
|
||||
]
|
||||
.B wmacpi
|
||||
[
|
||||
.RI -c
|
||||
value ]
|
||||
|
@ -27,13 +24,19 @@ sample rate ]
|
|||
.RI -n
|
||||
]
|
||||
[
|
||||
.RI -w
|
||||
]
|
||||
[
|
||||
.RI -a
|
||||
samples ]
|
||||
[
|
||||
.RI -V
|
||||
]
|
||||
[
|
||||
.RI -h
|
||||
]
|
||||
.PP
|
||||
.B acpi-ng
|
||||
.B acpi
|
||||
[
|
||||
.RI -a
|
||||
samples ]
|
||||
|
@ -48,10 +51,10 @@ samples ]
|
|||
]
|
||||
.SH DESCRIPTION
|
||||
This manual page documents briefly the
|
||||
.B wmacpi-ng
|
||||
.B wmacpi
|
||||
command.
|
||||
.PP
|
||||
.B wmacpi-ng
|
||||
.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).
|
||||
|
@ -65,16 +68,13 @@ and a scrolling message with some hopefully useful information.
|
|||
Clicking on the window cycles through the batteries that the ACPI
|
||||
system knows about.
|
||||
.PP
|
||||
.B acpi-ng
|
||||
.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-ng
|
||||
.TP
|
||||
.B \-b
|
||||
Make noise when battery is critical low (beep).
|
||||
.B wmacpi
|
||||
.TP
|
||||
.B \-c percentage
|
||||
Set critical low alarm at <value>% (default: 10%).
|
||||
|
@ -94,6 +94,15 @@ translates to once every three seconds. 10 gives once every 30 seconds,
|
|||
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.
|
||||
|
@ -104,7 +113,7 @@ Print the version information.
|
|||
.B \-h
|
||||
Display help.
|
||||
.TP
|
||||
.B acpi-ng
|
||||
.B acpi
|
||||
.TP
|
||||
.B \-a num
|
||||
Average the time remaining over num samples. This greatly improves the
|
||||
|
@ -112,7 +121,7 @@ accuracy of the reported time remaining.
|
|||
.TP
|
||||
.B \-v
|
||||
Increase the verbosity of the program, as for
|
||||
.B wmacpi-ng
|
||||
.B wmacpi
|
||||
.TP
|
||||
.B \-V
|
||||
Print the version information.
|
||||
|
@ -125,16 +134,11 @@ Display help.
|
|||
.br
|
||||
.SH AUTHOR
|
||||
.B wmacpi
|
||||
as written by Tim Copperfield <timecop@japan.co.jp>.
|
||||
.B wmacpi-ng
|
||||
is a reworking of
|
||||
.B wmacpi 1.34
|
||||
to support recent kernel versions, performed by Simon Fowler
|
||||
<simon@dreamcraft.com.au>.
|
||||
was originally written by Tim Copperfield <timecop@japan.co.jp>, then
|
||||
completely rewritten after 1.34 by Simon Fowler <simon@dreamcraft.com.au>.
|
||||
.PP
|
||||
This manual page was originally written by Simon Richter
|
||||
<sjr@debian.org> for the Debian GNU/Linux system, and then updated for
|
||||
.B wmacpi-ng
|
||||
by Simon Fowler.
|
||||
<sjr@debian.org> for the Debian GNU/Linux system, and then updated by
|
||||
Simon Fowler.
|
||||
.br
|
||||
Last modification by Simon Fowler <simon@dreamcraft.com.au>, 2003-07-11.
|
||||
Last modification by Simon Fowler <simon@dreamcraft.com.au>, 2003-11-23.
|
|
@ -33,9 +33,9 @@
|
|||
#include <X11/xpm.h>
|
||||
|
||||
#include "libacpi.h"
|
||||
#include "wmacpi-ng.h"
|
||||
#include "wmacpi.h"
|
||||
|
||||
#define WMACPI_NG_VER "0.99"
|
||||
#define WMACPI_VER "1.99"
|
||||
|
||||
/* main pixmap */
|
||||
#ifdef LOW_COLOR
|
||||
|
@ -59,16 +59,10 @@ typedef struct {
|
|||
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
|
||||
|
@ -129,7 +123,6 @@ static void invalid_time_display(void)
|
|||
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,
|
||||
|
@ -195,7 +188,7 @@ static void new_window(char *name)
|
|||
if (XpmCreatePixmapFromData(dockapp->display, dockapp->win,
|
||||
master_xpm, &dockapp->pixmap,
|
||||
&dockapp->mask, &attr) != XpmSuccess) {
|
||||
fprintf(stderr, "FATAL: Not enough colors for main pixmap!\n");
|
||||
pfatal("FATAL: Not enough colors for main pixmap!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -204,7 +197,7 @@ static void new_window(char *name)
|
|||
DefaultDepth(dockapp->display,
|
||||
dockapp->screen));
|
||||
if (!dockapp->text) {
|
||||
fprintf(stderr, "FATAL: Cannot create text scroll pixmap!\n");
|
||||
pfatal("FATAL: Cannot create text scroll pixmap!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -233,8 +226,6 @@ static void render_text(char *string)
|
|||
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,
|
||||
|
@ -272,7 +263,7 @@ static int open_display(char *display)
|
|||
{
|
||||
dockapp->display = XOpenDisplay(display);
|
||||
if (!dockapp->display) {
|
||||
fprintf(stderr, "Unable to open display '%s'\n", display);
|
||||
perr("Unable to open display '%s'\n", display);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -324,8 +315,6 @@ static void display_percentage(int percent)
|
|||
static unsigned int obar;
|
||||
unsigned int bar;
|
||||
|
||||
eprint(0, "received: %d\n", percent);
|
||||
|
||||
if (percent == -1)
|
||||
percent = 0;
|
||||
|
||||
|
@ -383,7 +372,6 @@ static void display_time(int minutes)
|
|||
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;
|
||||
|
@ -609,15 +597,63 @@ void usage(char *name)
|
|||
|
||||
void print_version(void)
|
||||
{
|
||||
printf("wmacpi-ng version %s\n", WMACPI_NG_VER);
|
||||
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;
|
||||
|
||||
|
@ -634,11 +670,8 @@ int main(int argc, char **argv)
|
|||
exit(1);
|
||||
|
||||
/* parse command-line options */
|
||||
while ((ch = getopt(argc, argv, "bd:c:m:s:hnvV")) != EOF) {
|
||||
while ((ch = getopt(argc, argv, "d:c:m:s:a:hnwvV")) != EOF) {
|
||||
switch (ch) {
|
||||
case 'b':
|
||||
noisy_critical = 1;
|
||||
break;
|
||||
case 'c':
|
||||
if (optarg) {
|
||||
globals->crit_level = atoi(optarg);
|
||||
|
@ -691,12 +724,31 @@ int main(int argc, char **argv)
|
|||
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 */
|
||||
|
@ -713,7 +765,7 @@ int main(int argc, char **argv)
|
|||
acquire_all_info();
|
||||
binfo = &batteries[battery_no];
|
||||
globals->binfo = binfo;
|
||||
fprintf(stderr, "monitoring battery %s\n", binfo->name);
|
||||
pinfo("monitoring battery %s\n", binfo->name);
|
||||
clear_time_display();
|
||||
set_power_panel();
|
||||
set_message();
|
||||
|
@ -723,7 +775,6 @@ int main(int argc, char **argv)
|
|||
while (1) {
|
||||
XEvent event;
|
||||
while (XPending(dockapp->display)) {
|
||||
eprint(0, "X11 activity");
|
||||
XNextEvent(dockapp->display, &event);
|
||||
switch (event.type) {
|
||||
case Expose:
|
||||
|
@ -744,7 +795,7 @@ int main(int argc, char **argv)
|
|||
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);
|
||||
pinfo("changing to monitor battery %d\n", battery_no + 1);
|
||||
set_batt_id_area(battery_no);
|
||||
break;
|
||||
}
|
Loading…
Reference in a new issue