diff --git a/wmacpi/.arch-ids/AUTHORS.id b/wmacpi/.arch-ids/AUTHORS.id new file mode 100644 index 0000000..1572aa8 --- /dev/null +++ b/wmacpi/.arch-ids/AUTHORS.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.0 diff --git a/wmacpi/.arch-ids/COPYING.id b/wmacpi/.arch-ids/COPYING.id new file mode 100644 index 0000000..ce8aeb1 --- /dev/null +++ b/wmacpi/.arch-ids/COPYING.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.1 diff --git a/wmacpi/.arch-ids/ChangeLog.id b/wmacpi/.arch-ids/ChangeLog.id new file mode 100644 index 0000000..884ade8 --- /dev/null +++ b/wmacpi/.arch-ids/ChangeLog.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.2 diff --git a/wmacpi/.arch-ids/INSTALL.id b/wmacpi/.arch-ids/INSTALL.id new file mode 100644 index 0000000..0993c0e --- /dev/null +++ b/wmacpi/.arch-ids/INSTALL.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.3 diff --git a/wmacpi/.arch-ids/Makefile.id b/wmacpi/.arch-ids/Makefile.id new file mode 100644 index 0000000..56b09e7 --- /dev/null +++ b/wmacpi/.arch-ids/Makefile.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.4 diff --git a/wmacpi/.arch-ids/README.id b/wmacpi/.arch-ids/README.id new file mode 100644 index 0000000..4e519aa --- /dev/null +++ b/wmacpi/.arch-ids/README.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.5 diff --git a/wmacpi/.arch-ids/TODO.id b/wmacpi/.arch-ids/TODO.id new file mode 100644 index 0000000..c7eed4f --- /dev/null +++ b/wmacpi/.arch-ids/TODO.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:59:50 2004 11909.0 diff --git a/wmacpi/.arch-ids/acpi.1.id b/wmacpi/.arch-ids/acpi.1.id new file mode 100644 index 0000000..86c3a00 --- /dev/null +++ b/wmacpi/.arch-ids/acpi.1.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 13:18:00 2004 13139.0 diff --git a/wmacpi/.arch-ids/acpi.c.id b/wmacpi/.arch-ids/acpi.c.id new file mode 100644 index 0000000..064283e --- /dev/null +++ b/wmacpi/.arch-ids/acpi.c.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 12:21:51 2004 12157.0 diff --git a/wmacpi/.arch-ids/libacpi.c.id b/wmacpi/.arch-ids/libacpi.c.id new file mode 100644 index 0000000..3de5e17 --- /dev/null +++ b/wmacpi/.arch-ids/libacpi.c.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.6 diff --git a/wmacpi/.arch-ids/libacpi.h.id b/wmacpi/.arch-ids/libacpi.h.id new file mode 100644 index 0000000..f09d2ec --- /dev/null +++ b/wmacpi/.arch-ids/libacpi.h.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 12:18:57 2004 12091.0 diff --git a/wmacpi/.arch-ids/master.xpm.id b/wmacpi/.arch-ids/master.xpm.id new file mode 100644 index 0000000..f4904ab --- /dev/null +++ b/wmacpi/.arch-ids/master.xpm.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.10 diff --git a/wmacpi/.arch-ids/master_low.xpm.id b/wmacpi/.arch-ids/master_low.xpm.id new file mode 100644 index 0000000..a1f2ac5 --- /dev/null +++ b/wmacpi/.arch-ids/master_low.xpm.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.11 diff --git a/wmacpi/.arch-ids/wmacpi.1.id b/wmacpi/.arch-ids/wmacpi.1.id new file mode 100644 index 0000000..1ca7de9 --- /dev/null +++ b/wmacpi/.arch-ids/wmacpi.1.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.22 diff --git a/wmacpi/.arch-ids/wmacpi.c.id b/wmacpi/.arch-ids/wmacpi.c.id new file mode 100644 index 0000000..50862e2 --- /dev/null +++ b/wmacpi/.arch-ids/wmacpi.c.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.8 diff --git a/wmacpi/.arch-ids/wmacpi.h.id b/wmacpi/.arch-ids/wmacpi.h.id new file mode 100644 index 0000000..6a77ff5 --- /dev/null +++ b/wmacpi/.arch-ids/wmacpi.h.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.9 diff --git a/wmacpi/.hg_archival.txt b/wmacpi/.hg_archival.txt new file mode 100644 index 0000000..f6a93fa --- /dev/null +++ b/wmacpi/.hg_archival.txt @@ -0,0 +1,2 @@ +repo: 9cde42e7fe71d3618c7c14b2f4fec73f079b283d +node: 65f88f7c4b29c4c74f068ba63c1c63c83c193eec diff --git a/wmacpi/.hgempty b/wmacpi/.hgempty new file mode 100644 index 0000000..dafe3bc --- /dev/null +++ b/wmacpi/.hgempty @@ -0,0 +1,35 @@ + +Empty original changeset by Simon Fowler : +[project @ simon@himi.org--wmacpi/wmacpi--mainline--2.0--patch-2] +Fixes for compiling against libdockapp-0.5.0 +This amounted to a four line patch - narrowing the type of +the dockapp width and height to an unsigned short. + +Unfortunately this isn't compatible with libdockapp-0.4.0 +now. + +Empty original changeset by Simon Fowler : +[project @ simon@himi.org--wmacpi/wmacpi--mainline--2.0--patch-3] +Upped version numbers for 2.1 release. +That's about it. + +Empty original changeset by Simon Fowler : +[project @ simon@himi.org--wmacpi/wmacpi--mainline--2.0--patch-4] +Small patch submitted by Patrice Dumas +Keywords: libdockapp build fixes +Build fixes for newer versions of libdockapp. + +Empty original changeset by Simon Fowler : +[project @ simon@himi.org--wmacpi/wmacpi--mainline--2.0--patch-5] +Updated email address and changelog for alpha release. +Since my dreamcraft.com.au address will be going away at some point . . . + +Empty original changeset by Simon Fowler : +[project @ simon@himi.org--wmacpi/wmacpi--mainline--2.0--patch-6] +Fix for 'charged' battery status +Some batteries report their status as 'discharging' when they're +fully charged, some report their status as 'charged' - previously +I was only checking for 'discharging' when switching out of the +battery charging state, now we check for 'charged' as well. + +This fixes part of Debian bug #393617. diff --git a/wmacpi/.hgignore b/wmacpi/.hgignore new file mode 100644 index 0000000..ae1d399 --- /dev/null +++ b/wmacpi/.hgignore @@ -0,0 +1,3 @@ +(^|/)\{arch\}($|/) +(^|/)\.hg($|/) +(^|/)\.hgtags($|/) diff --git a/wmacpi/.hgtags b/wmacpi/.hgtags new file mode 100644 index 0000000..ee1f745 --- /dev/null +++ b/wmacpi/.hgtags @@ -0,0 +1 @@ +8b1a90b86e0bf59867af5dc51de1db30b76458e7 v2.2rc1 diff --git a/wmacpi/ChangeLog b/wmacpi/ChangeLog index 46925c6..8524a1f 100644 --- a/wmacpi/ChangeLog +++ b/wmacpi/ChangeLog @@ -1,3 +1,23 @@ +2007 July 14 2.2rc1 + Major changes to command line handling and to the way we use + libdockapp, courtesy of Patrice Dumas. This should hopefully fix + several long-standing bugs with non-wmaker window managers (in + particular Debian bugs #280495 and 293546). + + Updated to support newer kernels that no longer support + /proc/acpi/info - thanks to Samuel Ortiz. + + Fixed a longstanding issue with redrawing - thanks to Vito + Caputo. + + This version changes a number of command line options (little used + ones, but they're still incompatible changes) due to the + libdockapp work. In particular, -w becomes -x, -v becomes -V (and + takes an argument rather than being repeated), and -V becomes -v + (thanks to libdockapp grabbing -h, -v and -w for itself). Also, + long options are now supported for everything in wmacpi (but not + acpi, since it doesn't use libdockapp for command line parsing). + 2007 January 10 2.2a1 Added a patch from Patrice Dumas to support newer versions of libdockapp. diff --git a/wmacpi/Makefile b/wmacpi/Makefile index 4d53ae1..0572999 100644 --- a/wmacpi/Makefile +++ b/wmacpi/Makefile @@ -14,7 +14,7 @@ BUILD_CLI = 1 CC := gcc CFLAGS := $(OPT) -Wall -W -g -ansi -I/usr/X11R6/include -LDFLAGS := $(OPT) -L/usr/X11R6/lib -lX11 -lXpm -lXext -ldockapp +LDFLAGS := $(OPT) -lX11 -ldockapp WMSRC := wmacpi.c libacpi.c HEADERS := libacpi.h wmacpi.h @@ -34,7 +34,7 @@ all: $(targets) WMOBJ := $(patsubst %.c,%.o,$(filter %.c,$(WMSRC))) # include per-file dependencies -include $(WMOBJ:.o=.d) +-include $(WMOBJ:.o=.d) wmacpi: $(WMOBJ) $(CC) $(LDFLAGS) -o $@ $^ @@ -44,7 +44,7 @@ wmacpi: $(WMOBJ) ifdef BUILD_CLI CLSRC := acpi.c libacpi.c CLOBJ := $(patsubst %.c,%.o,$(filter %.c,$(CLSRC))) -include $(CLOBJ:.o=.d) +-include $(CLOBJ:.o=.d) acpi: $(CLOBJ) $(CC) $(LDFLAGS) -o $@ $^ diff --git a/wmacpi/README b/wmacpi/README index 97fcb19..c3e13e8 100644 --- a/wmacpi/README +++ b/wmacpi/README @@ -18,14 +18,14 @@ wmacpi is a dockapp ACPI battery monitor for modern kernels (ie, 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 battery 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 +Version 1.99 and later provides full support for multiple batteries. +You can tell it to monitor a particular battery 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 @@ -38,10 +38,10 @@ 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 . . . +line. The --sample-rate option specifies the number of times the +battery is sampled every minute - the default is 20, and the maximum +value is 600. Since -s 600 translates to sampling every 0.1 seconds, +you really don't want to 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 @@ -49,6 +49,6 @@ 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 . +Please report bugs to -Simon Fowler, 2003-11-23. +Simon Fowler, 2007-07-13. diff --git a/wmacpi/TODO b/wmacpi/TODO index ef29553..d016ac7 100644 --- a/wmacpi/TODO +++ b/wmacpi/TODO @@ -1,6 +1,9 @@ +2007 July 13 2.2rc1 + * Make sure that everything works properly on modern kernels. + 2004 January 18 1.99r3 * Correctly handle changing batteries at runtime, if possible. Note - the bug reported by Joey Hess against wmacpi 1.33 . . . + the bug reported by Joey Hess against wmacpi 1.33 . . . 2003 November 23 1.99 * Expand libacpi to handle everything else under @@ -46,4 +49,4 @@ * Code cleanups . . . - -- Simon Fowler, + -- Simon Fowler, diff --git a/wmacpi/acpi.c b/wmacpi/acpi.c index 85a6c84..ffca2cb 100644 --- a/wmacpi/acpi.c +++ b/wmacpi/acpi.c @@ -26,7 +26,7 @@ #include "libacpi.h" -#define ACPI_VER "2.1" +#define ACPI_VER "2.2rc1" global_t *globals; @@ -38,7 +38,8 @@ void usage(char *name) " 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", + " V - increase verbosity\n" + " v - print version information\n", name, name); } @@ -61,10 +62,10 @@ int main(int argc, char *argv[]) case 'h': usage(argv[0]); return 0; - case 'v': + case 'V': verbosity++; break; - case 'V': + case 'v': print_version(); return 0; case 'a': diff --git a/wmacpi/debian/.arch-ids/=id b/wmacpi/debian/.arch-ids/=id new file mode 100644 index 0000000..54348a1 --- /dev/null +++ b/wmacpi/debian/.arch-ids/=id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.12 diff --git a/wmacpi/debian/.arch-ids/changelog.id b/wmacpi/debian/.arch-ids/changelog.id new file mode 100644 index 0000000..6354ec6 --- /dev/null +++ b/wmacpi/debian/.arch-ids/changelog.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.13 diff --git a/wmacpi/debian/.arch-ids/compat.id b/wmacpi/debian/.arch-ids/compat.id new file mode 100644 index 0000000..feef00b --- /dev/null +++ b/wmacpi/debian/.arch-ids/compat.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.14 diff --git a/wmacpi/debian/.arch-ids/control.id b/wmacpi/debian/.arch-ids/control.id new file mode 100644 index 0000000..637216d --- /dev/null +++ b/wmacpi/debian/.arch-ids/control.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.15 diff --git a/wmacpi/debian/.arch-ids/copyright.id b/wmacpi/debian/.arch-ids/copyright.id new file mode 100644 index 0000000..fca28a6 --- /dev/null +++ b/wmacpi/debian/.arch-ids/copyright.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.16 diff --git a/wmacpi/debian/.arch-ids/dirs.id b/wmacpi/debian/.arch-ids/dirs.id new file mode 100644 index 0000000..fdf03e3 --- /dev/null +++ b/wmacpi/debian/.arch-ids/dirs.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.17 diff --git a/wmacpi/debian/.arch-ids/docs.id b/wmacpi/debian/.arch-ids/docs.id new file mode 100644 index 0000000..048e9c8 --- /dev/null +++ b/wmacpi/debian/.arch-ids/docs.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.18 diff --git a/wmacpi/debian/.arch-ids/menu.id b/wmacpi/debian/.arch-ids/menu.id new file mode 100644 index 0000000..26846c8 --- /dev/null +++ b/wmacpi/debian/.arch-ids/menu.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.19 diff --git a/wmacpi/debian/.arch-ids/rules.id b/wmacpi/debian/.arch-ids/rules.id new file mode 100644 index 0000000..c2404c0 --- /dev/null +++ b/wmacpi/debian/.arch-ids/rules.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.20 diff --git a/wmacpi/debian/.arch-ids/watch.id b/wmacpi/debian/.arch-ids/watch.id new file mode 100644 index 0000000..a935f53 --- /dev/null +++ b/wmacpi/debian/.arch-ids/watch.id @@ -0,0 +1 @@ +Simon Fowler Sun Jul 11 11:28:38 2004 11066.21 diff --git a/wmacpi/libacpi.c b/wmacpi/libacpi.c index 6ea74d6..2a3890d 100644 --- a/wmacpi/libacpi.c +++ b/wmacpi/libacpi.c @@ -139,15 +139,20 @@ int power_init(global_t *globals) char buf[4096]; int acpi_ver = 0; int retval; + unsigned int version_offset = 0; - if (!(acpi = fopen("/proc/acpi/info", "r"))) { - pfatal("This system does not support ACPI\n"); - return 1; + if (!(acpi = fopen("/sys/module/acpi/parameters/acpica_version", "r"))) { + if (!(acpi = fopen("/proc/acpi/info", "r"))) { + pfatal("This system does not support ACPI\n"); + return 1; + } else { + version_offset = 25; + } } /* okay, now see if we got the right version */ fread(buf, 4096, 1, acpi); - acpi_ver = strtol(buf + 25, NULL, 10); + acpi_ver = strtol(buf + version_offset, NULL, 10); pinfo("ACPI version detected: %d\n", acpi_ver); if (acpi_ver < 20020214) { pfatal("This version requires ACPI subsystem version 20020214\n"); @@ -169,9 +174,11 @@ int power_reinit(global_t *globals) FILE *acpi; int retval; - if (!(acpi = fopen("/proc/acpi/info", "r"))) { - pfatal("Could not reopen ACPI info file - does this system support ACPI?\n"); - return 1; + if (!(acpi = fopen("/sys/module/acpi/parameters/acpica_version", "r"))) { + if (!(acpi = fopen("/proc/acpi/info", "r"))) { + pfatal("Could not reopen ACPI info file - does this system support ACPI?\n"); + return 1; + } } if (!(retval = reinit_batteries(globals))) @@ -337,6 +344,12 @@ int get_battery_info(int batt_no) info->charge_state = CH_ERR; else if ((strncmp(val, "discharging", 10)) == 0) info->charge_state = DISCHARGE; + else if ((strncmp(val, "charged", 7)) == 0) + /* this is a workaround for machines that report + * their charge state as 'charged', rather than + * what my laptop does, which is go straight to + * 'discharging'. dunno which matches the standard */ + info->charge_state = DISCHARGE; else info->charge_state = CHARGE; diff --git a/wmacpi/libacpi.h b/wmacpi/libacpi.h index 7cdaf5d..fd89c2f 100644 --- a/wmacpi/libacpi.h +++ b/wmacpi/libacpi.h @@ -2,7 +2,7 @@ #define _LIBACPI_H_ -#define LIBACPI_VER "0.92" +#define LIBACPI_VER "0.93" /* Here because we need it for definitions in this file . . . */ #define MAX_NAME 128 diff --git a/wmacpi/wmacpi.1 b/wmacpi/wmacpi.1 index 362606c..93cf646 100644 --- a/wmacpi/wmacpi.1 +++ b/wmacpi/wmacpi.1 @@ -1,4 +1,4 @@ -.TH WMACPI 1 "August 15 2004" +.TH WMACPI 1 "July 13 2007" .SH NAME wmacpi \- Battery status monitor for systems supporting ACPI .SH NAME @@ -27,13 +27,13 @@ sample rate ] .RI -n ] [ -.RI -w +.RI -x ] [ .RI -a samples ] [ -.RI -V +.RI -v ] [ .RI -h @@ -44,10 +44,10 @@ samples ] .RI -a samples ] [ -.RI -v +.RI -V ] [ -.RI -V +.RI -v ] ] .RI -b @@ -85,24 +85,24 @@ battery to reach full charge if the batteries are charging. .SH OPTIONS .B wmacpi .TP -.B \-c percentage -Set critical low alarm at % (default: 10%). +.B \-c, --critical=percentage +Set critical low alarm at % (default: 10%). .TP -.B \-d display +.B \-d, --display=display Set the X display to open the window on. .TP -.B \-m battery number +.B \-m, --battery=battery number Set the battery to monitor initially. .TP -.B \-s sample rate +.B \-s, --sample-rate=sample rate Set the rate at which to sample the ACPI data, in number of times per minute. Minimum is 1, ie once a minute, default is 20, maximum is 600. .TP -.B \-n +.B \-n, --no-blink Disable blinking power glyph when charging. Note that it still blinks when the battery reports its capacity state as critical. .TP -.B \-f +.B \-f, --force-capacity-mode Force the use of capacity mode for calculating time remaining. By defalt .B wmacpi will use the reported values of remaining capacity and present rate to @@ -113,29 +113,27 @@ of calculation generally underreports the time remaining. This mode works around certain buggy ACPI BIOSes that fail to report the current rate. .TP -.B \-w +.B \-x, --cmdline Run wmacpi in command line mode - this operates identically to .B acpi .. .TP -.B \-a num +.B \-a, --samples=samples 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. +.B \-V, --verbosity=num +Increase the verbosity of the program. Setting this to 1 will print extra +error information; 2 will produce informational output; 3 will produce +copious debugging output. .TP -.B \-V +.B \-v, --version Print the version information. .TP -.B \-b -Enable blinking of the power glyph when charging the batteries. -.TP -.B \-r +.B \-r, --no-scroll Disable scrolling message. .TP -.B \-h +.B \-h, --help Display help. .TP .B acpi @@ -144,11 +142,15 @@ Display help. 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 +Increase the verbosity of the program. If repeated, the result is the +same as setting +.B \--verbosity +for +.B wmacpi +to the number of repetitions. +.TP +.B \-v Print the version information. .TP .B \-h @@ -162,4 +164,4 @@ This manual page was originally written by Simon Richter for the Debian GNU/Linux system, and then updated by Simon Fowler. .br -Last modification by Simon Fowler , 2007-01-10. +Last modification by Simon Fowler , 2007-07-13. diff --git a/wmacpi/wmacpi.c b/wmacpi/wmacpi.c index 622b36f..241eeb5 100644 --- a/wmacpi/wmacpi.c +++ b/wmacpi/wmacpi.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -37,7 +36,7 @@ #include "libacpi.h" #include "wmacpi.h" -#define WMACPI_VER "2.1" +#define WMACPI_VER "2.2rc1" /* main pixmap */ #ifdef LOW_COLOR @@ -136,13 +135,9 @@ static void redraw_window(void) static void new_window(char *display, char *name, int argc, char **argv) { + XSizeHints *hints; + /* Initialise the dockapp window and appicon */ - /* we don't want libdocapp to parse the command line, but we have to - initialize it with DAParseArguments, so we set argc to 1 */ - DAParseArguments(1, argv, NULL, 0, - "help option done", "version option done"); - /* deprecated - DAInitialize(display, name, 64, 64, argc, argv); */ DAOpenDisplay(display, argc, argv); DACreateIcon(name, 64, 64, argc, argv); dockapp->display = DADisplay; @@ -166,6 +161,20 @@ static void new_window(char *display, char *name, int argc, char **argv) pfatal("FATAL: Cannot create text scroll pixmap!\n"); exit(1); } + + /* force the window to stay this size - otherwise the user could + * resize us and see our panties^Wmaster pixmap . . . */ + hints = XAllocSizeHints(); + if(hints) { + hints->flags |= PMinSize | PMaxSize; + hints->min_width = 64; + hints->max_width = 64; + hints->min_height = 64; + hints->max_height = 64; + XSetWMNormalHints(dockapp->display, dockapp->win, hints); + XFree(hints); + } + DAShow(); } @@ -419,7 +428,7 @@ static void blink_battery_glyph(void) static void set_power_panel(global_t *globals) { - enum panel_states power = PS_NULL; + static enum panel_states power = PS_NULL; battery_t *binfo = globals->binfo; adapter_t *ap = &globals->adapter; @@ -568,32 +577,7 @@ void set_batt_id_area(int bno) copy_xpm_area(sx, sy, w, h, dx, dy); } -void usage(char *name) -{ - printf("%s - help\t\t[simon@dreamcraft.com.au]\n\n" - "-d display\t\tdisplay on remote display \n" - "-b\t\t\tenable blinking of various UI elements\n" - "-r\t\t\tdisable scrolling message\n" - "-c value\t\tset critical low alarm at percent\n" - "\t\t\t(default: 10 percent)\n" - "-m \tbattery number to monitor\n" - "-s \tnumber of times per minute to sample battery information\n" - "\t\t\tdefault 20 (once every three seconds)\n" - "-f\t\t\tforce the use of capacity mode for calculating time remaining\n" - "-n\t\t\tdo not blink\n" - "-w\t\t\trun in command line mode\n" - "-a \t\tsamples to average over (cli mode only)\n" - "-v\t\t\tincrease verbosity\n" - "\t\t\tcan be used multiple times to increase verbosity further\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); -} +#define VERSION "wmacpi version " WMACPI_VER "\nUsing libacpi version " LIBACPI_VER void cli_wmacpi(global_t *globals, int samples) { @@ -647,12 +631,11 @@ void cli_wmacpi(global_t *globals, int samples) int main(int argc, char **argv) { char *display = NULL; - int ch; int sample_count = 0; int batt_reinit, ac_reinit; int batt_count = 0; int ac_count = 0; - int cli = 0, samples = 1; + int cli = 0, samples = 1, critical = 10; int samplerate = 20; int sleep_rate = 10; int sleep_time = 1000000/sleep_rate; @@ -662,6 +645,19 @@ int main(int argc, char **argv) battery_t *binfo; global_t *globals; + DAProgramOption options[] = { + {"-r", "--no-scroll", "disable scrolling message", DONone, False, {NULL}}, + {"-n", "--no-blink", "disable blinking of various UI elements", DONone, False, {NULL}}, + {"-x", "--cmdline", "run in command line mode", DONone, False, {NULL}}, + {"-f", "--force-capacity-mode", "force the use of capacity mode for calculating time remaining", DONone, False, {NULL}}, + {"-d", "--display", "display or remote display", DOString, False, {&display}}, + {"-c", "--critical", "set critical low alarm at percent\n (default: 10 percent)", DONatural, False, {&critical}}, + {"-m", "--battery", "battery number to monitor", DONatural, False, {&battery_no}}, + {"-s", "--sample-rate", "number of times per minute to sample battery information\n default 20 (once every three seconds)", DONatural, False, {&samplerate}}, + {"-V", "--verbosity", "Set verbosity", DONatural, False, {&verbosity}}, + {"-a", "--samples", "number of samples to average over (cli mode only)", DONatural, False, {&samples}}, + }; + dockapp = calloc(1, sizeof(struct dockapp)); globals = calloc(1, sizeof(global_t)); @@ -682,84 +678,37 @@ int main(int argc, char **argv) * are available /before/ we can decide if the battery we want to * monitor is available. */ /* parse command-line options */ - while ((ch = getopt(argc, argv, "d:c:m:s:a:fhnwbrvV")) != 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; - } - pinfo("Monitoring battery %d\n", battery_no); - } - break; - case 's': - if (optarg) { - samplerate = atoi(optarg); - if (samplerate == 0) samplerate = 1; - if (samplerate > 600) samplerate = 600; - } else { - usage(argv[0]); - exit(1); - } - break; - case 'f': - rt_mode = RT_CAP; - rt_forced = 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) { - fprintf(stderr, "Please specify a reasonable number of samples\n"); - exit(1); - } - } - break; - case 'b': - dockapp->blink = 1; - break; - case 'r': - dockapp->scroll = 0; - break; - default: - usage(argv[0]); - return 1; - } - + DAParseArguments(argc, argv, options, 10, + "A battery monitor dockapp for ACPI based systems", + VERSION); + + if (options[0].used) + dockapp->scroll = 0; + if (options[1].used) + dockapp->blink = 0; + if (options[2].used) + cli = 1; + if (options[3].used) { + rt_mode = RT_CAP; + rt_forced = 1; } - + + if (samplerate == 0) samplerate = 1; + if (samplerate > 600) samplerate = 600; + + if (critical > 100) { + fprintf(stderr, "Please use values between 0 and 100%%\n"); + fprintf(stderr, "Using default value of 10%%\n"); + critical = 10; + } + globals->crit_level = critical; + + if (battery_no >= MAXBATT) { + fprintf(stderr, "Please specify a battery number below %d\n", MAXBATT); + return 1; + } + pinfo("Monitoring battery %d\n", battery_no); + if (power_init(globals)) /* power_init functions handle printing error messages */ exit(1); @@ -805,6 +754,8 @@ int main(int argc, char **argv) /* main loop */ while (1) { + Atom atom; + Atom wmdelwin; XEvent event; while (XPending(dockapp->display)) { XNextEvent(dockapp->display, &event); @@ -831,6 +782,28 @@ int main(int argc, char **argv) set_batt_id_area(battery_no); dockapp->update = 1; break; + case ClientMessage: + /* what /is/ this crap? + * Turns out that libdockapp adds the WM_DELETE_WINDOW atom to + * the WM_PROTOCOLS property for the window, which means that + * rather than get a simple DestroyNotify message, we get a + * nice little message from the WM saying "hey, can you delete + * yourself, pretty please?". So, when running as a window + * rather than an icon, we're impossible to kill in a friendly + * manner, because we're expecting to die from a DestroyNotify + * and thus blithely ignoring the WM knocking on our window + * border . . . + * + * This simply checks for that scenario - it may fail oddly if + * something else comes to us via a WM_PROTOCOLS ClientMessage + * event, but I suspect it's not going to be an issue. */ + wmdelwin = XInternAtom(dockapp->display, "WM_DELETE_WINDOW", 1); + atom = event.xclient.data.l[0]; + if (atom == wmdelwin) { + XCloseDisplay(dockapp->display); + exit(0); + } + break; } }