[Pkg-wmaker-commits] [wmbattery] 97/241: * Bit the bullet, stopped trying to track the kernel's ever changing interfaces, and added support for querying battery information from hal. Support for the old kernel interfaces (APM, ACPI, etc) is still present, but to use new interfaces such 2.6.24's /sys/class/power_adapter, you'll have to have dbus and hal. Closes: #456247, #246641, #290712, #393616, #456248 * Fix -e option.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Mon Aug 24 23:37:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository wmbattery.

commit 19996c152158890e4728636534099467931c9e82
Author: Joey Hess <joey at kodama.kitenet.net>
Date:   Fri Feb 1 20:51:40 2008 -0500

    * Bit the bullet, stopped trying to track the kernel's ever changing
      interfaces, and added support for querying battery information from hal.
      Support for the old kernel interfaces (APM, ACPI, etc) is still present,
      but to use new interfaces such 2.6.24's /sys/class/power_adapter, you'll
      have to have dbus and hal.
      Closes: #456247, #246641, #290712, #393616, #456248
    * Fix -e option.
---
 Makefile             |  14 ++-
 README               |   1 +
 TODO                 |   2 +
 autoconf/makeinfo.in |   4 +-
 debian/changelog     |  10 +-
 debian/control       |   7 +-
 simplehal.c          | 134 ++++++++++++++++++++++++++
 simplehal.h          |   2 +
 sys_power.c          | 268 ---------------------------------------------------
 sys_power.h          |  28 ------
 wmbattery.1x         |  12 +--
 wmbattery.c          |  40 ++++----
 12 files changed, 193 insertions(+), 329 deletions(-)

diff --git a/Makefile b/Makefile
index 4aea723..edf87cc 100644
--- a/Makefile
+++ b/Makefile
@@ -21,8 +21,18 @@ install: all
 uninstall:
 	rm -rf $(bindir)/wmbattery $(man1dir)/wmbattery.1x $(icondir)
 
-wmbattery: wmbattery.o acpi.o sonypi.o sys_power.o
-	$(CC) $(LDFLAGS) wmbattery.o acpi.o sonypi.o sys_power.o -o wmbattery $(LIBS)
+OBJS=wmbattery.o acpi.o sonypi.o
+
+ifdef USE_HAL
+LIBS+=$(shell pkg-config --libs hal)
+OBJS+=simplehal.o
+CFLAGS+=-DHAL
+simplehal.o: simplehal.c
+	$(CC) $(CFLAGS) $(shell pkg-config --cflags hal) -c simplehal.c -o simplehal.o
+endif
+
+wmbattery: $(OBJS)
+	$(CC) -o wmbattery $(LDFLAGS) $(OBJS) $(LIBS)
 
 wmbattery.o: wmbattery.c wmbattery.h
 
diff --git a/README b/README
index 5a4a667..2d145dc 100644
--- a/README
+++ b/README
@@ -19,6 +19,7 @@ some improvements in wmbattery:
     for some Sony laptops that do not have apm support.
   - ACPI support, including multiple battery support and battery charging
     completion countdown timer.
+  - HAL support.
   - Can make its own estimatess of time remaining or time until full
     charge, even if APM does not.
 
diff --git a/TODO b/TODO
index 0aec4b9..7b41755 100644
--- a/TODO
+++ b/TODO
@@ -7,3 +7,5 @@
   programs use it).
 * Make -b 0 display an overall average of the status of all batteries,
   much like apm does on multi-battery laptops.
+* The simplehal interface is not very good. It polls once per second, 
+  it would be much better if it let HAL notify it about changes instead.
diff --git a/autoconf/makeinfo.in b/autoconf/makeinfo.in
index e23e6d0..192e8e0 100644
--- a/autoconf/makeinfo.in
+++ b/autoconf/makeinfo.in
@@ -7,10 +7,12 @@ prefix		= @prefix@
 srcdir		= @srcdir@
 
 CC		= @CC@
-CFLAGS		= @CFLAGS@ -Wall -DACPI_APM -DSYS_POWER_APM
+CFLAGS		= @CFLAGS@ -Wall -DACPI_APM
 CPPFLAGS	= @CPPFLAGS@ -DICONDIR=\"$(icondir)\"
 INSTALL		= @INSTALL@
 INSTALL_DATA	= @INSTALL_DATA@
 INSTALL_PROGRAM	= @INSTALL_PROGRAM@
 LDFLAGS		= @LDFLAGS@
 LIBS		= @LIBS@
+
+USE_HAL		= 1
diff --git a/debian/changelog b/debian/changelog
index 3652f3f..23c533c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,8 +1,12 @@
 wmbattery (2.34) UNRELEASED; urgency=low
 
-  * Add support for the new ACPI_SYSFS_POWER kernel interface in 2.6.24.
-    (Still quite rough and probably gets a few things wrong.)
-    Closes: #456247
+  * Bit the bullet, stopped trying to track the kernel's ever changing
+    interfaces, and added support for querying battery information from hal.
+    Support for the old kernel interfaces (APM, ACPI, etc) is still present,
+    but to use new interfaces such 2.6.24's /sys/class/power_adapter, you'll
+    have to have dbus and hal.
+    Closes: #456247, #246641, #290712, #393616, #456248
+  * Fix -e option.
 
  -- Joey Hess <joeyh at debian.org>  Fri, 01 Feb 2008 15:28:53 -0500
 
diff --git a/debian/control b/debian/control
index 948adab..df2d4aa 100644
--- a/debian/control
+++ b/debian/control
@@ -1,7 +1,7 @@
 Source: wmbattery
 Section: x11
 Priority: extra
-Build-Depends: debhelper (>= 4), libxext-dev, libxpm-dev, autoconf, libapm-dev, dpkg-dev (>= 1.9.0), libxt-dev
+Build-Depends: debhelper (>= 4), libxext-dev, libxpm-dev, autoconf, libapm-dev, dpkg-dev (>= 1.9.0), libxt-dev, libhal-dev
 Maintainer: Joey Hess <joeyh at debian.org>
 Standards-Version: 3.7.2
 Vcs-Git: git://git.kitenet.net/wmbattery
@@ -10,6 +10,7 @@ Homepage: http://kitenet.net/~joey/code/wmbattery/
 Package: wmbattery
 Architecture: any
 Depends: ${shlibs:Depends}, ${misc:Depends}
+Recommends: hal
 Suggests: wmaker
 Description: display laptop battery info, dockable in WindowMaker
  wmbattery displays the status of your laptop's battery in a small icon.
@@ -20,6 +21,6 @@ Description: display laptop battery info, dockable in WindowMaker
  There's nothing in the program that makes it require WindowMaker, except
  maybe the look. It can be docked in WindowMaker or AfterStep's dock.
  .
- wmbattery can use APM, ACPI, or even the SPIC that is in some Sony laptops.
- With ACPI, it supports multi-battery machines, and can estimate how long
+ wmbattery can use HAL, APM, ACPI, or even the SPIC that is in some Sony
+ laptops. It supports multi-battery machines, and can estimate how long
  it will take the battery to finish charging or discharging.
diff --git a/simplehal.c b/simplehal.c
new file mode 100644
index 0000000..315e349
--- /dev/null
+++ b/simplehal.c
@@ -0,0 +1,134 @@
+/* Not particularly good interface to hal, for programs that used to use
+ * apm.
+ */
+
+#include <apm.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <libhal.h>
+
+static LibHalContext *hal_ctx;
+
+char *udi_base = "/org/freedesktop/Hal/devices";
+
+char *gen_udi (const char *device) {
+	static char ret[256];
+	sprintf(ret, "%s/%s", udi_base, device);
+	return ret;
+}
+
+signed int get_hal_int (const char *device, const char *key) {
+	int ret;
+	DBusError error;
+
+	dbus_error_init(&error);
+	ret = libhal_device_get_property_int (hal_ctx, gen_udi(device), key, &error);
+	
+	if (dbus_error_is_set (&error)) {
+		fprintf(stderr, "error: libhal_device_get_property_int: %s: %s\n",
+			 error.name, error.message);
+		dbus_error_free (&error);
+		return -1;
+	}
+	return ret;
+}
+
+signed int get_hal_bool (const char *device, const char *key) {
+	int ret;
+	DBusError error;
+
+	dbus_error_init(&error);
+	ret = libhal_device_get_property_bool (hal_ctx, gen_udi(device), key, &error);
+	
+	if (dbus_error_is_set (&error)) {
+		fprintf(stderr, "error: libhal_device_get_property_int: %s: %s\n",
+			 error.name, error.message);
+		dbus_error_free (&error);
+		return -1;
+	}
+	return ret;
+}
+
+int simplehal_supported (void) {
+	DBusError error;
+	DBusConnection *conn;
+
+	dbus_error_init(&error);
+	conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+	if (conn == NULL) {
+		fprintf(stderr, "error: dbus_bus_get: %s: %s\n",
+			 error.name, error.message);
+		LIBHAL_FREE_DBUS_ERROR(&error);
+		return 0;
+	}
+	if ((hal_ctx = libhal_ctx_new()) == NULL) {
+		fprintf(stderr, "error: libhal_ctx_new\n");
+		return 0;
+	}
+	if (!libhal_ctx_set_dbus_connection (hal_ctx, conn)) {
+		fprintf(stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n",
+			 error.name, error.message);
+		return 0;
+	}
+	if (!libhal_ctx_init(hal_ctx, &error)) {
+		if (dbus_error_is_set(&error)) {
+			fprintf(stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
+			dbus_error_free(&error);
+		}
+		fprintf(stderr, "Could not initialise connection to hald.\n"
+				 "Normally this means the HAL daemon (hald) is not running or not ready.\n");
+		return 0;
+	}
+
+	return 1;
+}
+
+/* Fill the passed apm_info struct. */
+int simplehal_read (int battery, apm_info *info) {
+	char device[255];
+
+	info->battery_flags = 0;
+	info->using_minutes = 0;
+	info->ac_line_status = (get_hal_bool("computer_power_supply", "ac_adapter.present") == 1);
+
+	/* XXX There are probably better ways to enumerate batteries... */
+	sprintf(device, "computer_power_supply_%i", battery - 1);
+
+	if (get_hal_bool(device, "battery.present") != 1) {
+		info->battery_percentage = 0;
+		info->battery_time = 0;
+		info->battery_status = BATTERY_STATUS_ABSENT;
+		return 0;
+	}
+	
+	/* remaining_time and charge_level.percentage are not a mandatory
+	 * keys, so if not present, -1 will be returned */
+	info->battery_time = get_hal_int(device, "battery.remaining_time");
+	info->battery_percentage = get_hal_int(device, "battery.charge_level.percentage");
+	if (get_hal_bool(device, "battery.rechargeable.is_discharging") == 1) {
+		info->battery_status = BATTERY_STATUS_CHARGING;
+		/* charge_level.warning and charge_level.low are not
+		 * required to be available; this is good enough */
+		if (info->battery_percentage < 1) {
+			info->battery_status = BATTERY_STATUS_CRITICAL;
+		}
+		else if (info->battery_percentage < 10) {
+			info->battery_status = BATTERY_STATUS_LOW;
+		}
+	}
+	else if (get_hal_bool(device, "battery.rechargeable.is_charging") == 1) {
+		info->battery_status = BATTERY_STATUS_CHARGING;
+		info->battery_flags = info->battery_flags | BATTERY_FLAGS_CHARGING;
+	}
+	else if (info->ac_line_status) {
+		/* Must be fully charged. */
+		info->battery_status = BATTERY_STATUS_HIGH;
+	}
+	else {
+		fprintf(stderr, "unknown battery state\n");
+	}
+
+	return 0;
+}
diff --git a/simplehal.h b/simplehal.h
new file mode 100644
index 0000000..1f4cd2a
--- /dev/null
+++ b/simplehal.h
@@ -0,0 +1,2 @@
+int simplehal_supported (void);
+int simplehal_read (int battery, apm_info *info);
diff --git a/sys_power.c b/sys_power.c
deleted file mode 100644
index 95dc8cc..0000000
--- a/sys_power.c
+++ /dev/null
@@ -1,268 +0,0 @@
-/* 
- * Support for the linux ACPI_SYS_POWER interface.
- * By Joey Hess <joey at kitenet.net>
- */
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <string.h>
-#ifdef SYS_POWER_APM
-#include "apm.h"
-#endif
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#include "sys_power.h"
-
-int sys_power_batt_count = 0;
-int sys_power_ac_count = 0;
-char sys_power_batt_dirs[SYS_POWER_MAXITEM][128];
-char sys_power_ac_dirs[SYS_POWER_MAXITEM][128];
-/* Stores battery capacity, or 0 if the battery is absent. */
-int sys_power_batt_capacity[SYS_POWER_MAXITEM];
-
-/* Read a single value from a sys file from the specified directory (well,
- * the first 64 bytes anyway), and return a statically allocated array
- * containing it. The newline, if any, is stripped. If the file is not
- * present, "0" is returned. */
-char *get_sys_power_value (const char *dir, const char *file) {
-	int fd;
-	int end;
-	static char buf[64];
-	char fn[128];
-	snprintf(fn, 127, "%s/%s/%s", SYS_POWER, dir, file);
-	fd = open(fn, O_RDONLY);
-	if (fd == -1) return "0";
-	end = read(fd, buf, sizeof(buf));
-	close(fd);
-	buf[end-1] = '\0';
-	if (buf[end-2] == '\n')
-		buf[end-2] = '\0';
-	return buf;
-}
-
-/* Returns the maximum capacity of a battery.
- *
- * Note that this returns the highest possible capacity for the battery,
- * even if it can no longer charge that fully. So normally it uses the
- * design capacity. While the last full capacity of the battery should
- * never exceed the design capacity, some silly hardware might report
- * that it does. So if the last full capacity is greater, it will be
- * returned.
- */
-int get_sys_power_batt_capacity(int battery) {
-	int dcap=atoi(get_sys_power_value(sys_power_batt_dirs[battery], "charge_full_design"));
-	int lcap=atoi(get_sys_power_value(sys_power_batt_dirs[battery], "charge_full"));
-	
-	if (lcap > dcap)
-		return lcap;
-	else
-		return dcap;
-}
-
-/* Comparison function for qsort. */
-int _sys_power_compare_strings (const void *a, const void *b) {
-	const char **pa = (const char **)a;
-	const char **pb = (const char **)b;
-	return strcasecmp((const char *)*pa, (const char *)*pb);
-}
-
-/* Find something (batteries, ac adpaters, etc), and set up a string array
- * to hold the paths to the things found.
- * Returns the number of items found. */
-int find_sys_power_items (char *type, char dirarray[SYS_POWER_MAXITEM][128]) {
-	DIR *dir;
-	struct dirent *ent;
-	int num_devices=0;
-	
-	dir = opendir(SYS_POWER);
-	if (dir == NULL)
-		return 0;
-	while ((ent = readdir(dir))) {
-		if (!strcmp(".", ent->d_name) || 
-		    !strcmp("..", ent->d_name))
-			continue;
-
-		if (strcmp(get_sys_power_value(ent->d_name, "type"), type) == 0) {
-			sprintf(dirarray[num_devices], "%s", ent->d_name);
-			num_devices++;
-			if (num_devices >= SYS_POWER_MAXITEM)
-				break;
-		}
-	}
-	closedir(dir);
-	
-	/* Sort, since readdir can return in any order. */
-	qsort(dirarray, num_devices, sizeof(char *), _sys_power_compare_strings);
-
-	return num_devices;
-}
-
-/* Find batteries, return the number, and set sys_power_batt_count to it as
- * well. */
-int find_sys_power_batteries(void) {
-	int i;
-	sys_power_batt_count = find_sys_power_items("Battery", sys_power_batt_dirs);
-	for (i = 0; i < sys_power_batt_count; i++)
-		sys_power_batt_capacity[i] = get_sys_power_batt_capacity(i);
-	return sys_power_batt_count;
-}
-
-/* Find AC power adapters, return the number found, and set 
- * sys_power_ac_count to it as well. */
-int find_sys_power_ac_adapters(void) {
-	sys_power_ac_count = find_sys_power_items("Mains", sys_power_ac_dirs);
-	return sys_power_ac_count;
-}
-
-/* Returns true if the system is on ac power. Call find_sys_power_ac_adapters
- * first. */
-int sys_power_on_ac (void) {
-	int i;
-	for (i = 0; i < sys_power_ac_count; i++) {
-		if (strcmp(get_sys_power_value(sys_power_ac_dirs[i], "online"), "0") != 0)
-			return 1;
-		else
-			return 0;
-	}
-	return 0;
-}
-
-/* See if we have ACPI_SYS_POWER support. Also find batteries and ac power
- * adapters. */
-int sys_power_supported (void) {
-	DIR *dir;
-
-	if (!(dir = opendir(SYS_POWER))) {
-		return 0;
-	}
-	closedir(dir);
-	
-	find_sys_power_batteries();
-	find_sys_power_ac_adapters();
-
-	return 1;
-}
-
-#ifdef SYS_POWER_APM
-/* Read ACPI info on a given battery, and fill the passed apm_info struct. */
-int sys_power_read (int battery, apm_info *info) {
-	char *status;
-
-	if (sys_power_batt_count == 0) {
-		info->battery_percentage = 0;
-		info->battery_time = 0;
-		info->battery_status = BATTERY_STATUS_ABSENT;
-		sys_power_batt_capacity[battery] = 0;
-		/* Where else would the power come from, eh? ;-) */
-		info->ac_line_status = 1;
-		return 0;
-	}
-	
-	/* Internally it's zero indexed. */
-	battery--;
-	
-	info->ac_line_status = 0;
-	info->battery_flags = 0;
-	info->using_minutes = 1;
-	
-	/* Work out if the battery is present, and what percentage of full
-	 * it is and how much time is left. */
-	if (strcmp(get_sys_power_value(sys_power_batt_dirs[battery], "present"), "1") == 0) {
-		int charge, current;
-		
-		charge = atoi(get_sys_power_value(sys_power_batt_dirs[battery], "charge_now"));
-		/* Use average if it's available. */
-		current = atoi(get_sys_power_value(sys_power_batt_dirs[battery], "current_avg"));
-		if (! current)
-			current = atoi(get_sys_power_value(sys_power_batt_dirs[battery], "current_now"));
-
-		if (current) {
-			/* time remaining = (current_capacity / discharge rate) */
-			info->battery_time = (float) charge / (float) current * 60;
-		}
-		else {
-			/* a zero or unknown in the file; time 
-			 * unknown so use a negative one to
-			 * indicate this */
-			info->battery_time = -1;
-		}
-		
-		if (sys_power_batt_capacity[battery] == 0) {
-			/* The battery was absent, and now is present.
-			 * Well, it might be a different battery. So
-			 * re-probe the battery. */
-			sys_power_batt_capacity[battery] = get_sys_power_batt_capacity(battery);
-		}
-		else if (current > sys_power_batt_capacity[battery]) {
-			/* Battery is somehow charged to greater than max
-			 * capacity. Rescan for a new max capacity. */
-			sys_power_batt_capacity[battery] = get_sys_power_batt_capacity(battery);
-		}
-		
-		if (current && sys_power_batt_capacity[battery]) {
-			/* percentage = (current_capacity / max capacity) * 100 */
-			info->battery_percentage = (float) current / (float) sys_power_batt_capacity[battery] * 100;
-		}
-		else {
-			info->battery_percentage = -1;
-		}
-
-		status = get_sys_power_value(sys_power_batt_dirs[battery], "status");
-		if (strcasecmp(status, "discharging") == 0) {
-			info->battery_status = BATTERY_STATUS_CHARGING;
-			/* Explicit power check used here
-			 * because AC power might be on even if a
-			 * battery is discharging in some cases. */
-			info->ac_line_status = sys_power_on_ac();
-			if (! info->ac_line_status) {
-				/* Check for critical or low status. */ 
-				if (info->battery_percentage < 1) {
-					info->battery_status = BATTERY_STATUS_CRITICAL;
-				}
-				else if (info->battery_percentage <= 10) {
-					info->battery_status = BATTERY_STATUS_LOW;
-				}
-			}
-		}
-		else if (strcasecmp(status, "charging") == 0) {
-			info->battery_status = BATTERY_STATUS_CHARGING;
-			info->ac_line_status = 1;
-			info->battery_flags = info->battery_flags | BATTERY_FLAGS_CHARGING;
-			printf("charging; max cap: %i, charge: %i, current: %i\n", sys_power_batt_capacity[battery], charge, current);
-			if (current) {
-				info->battery_time = -1 * (float) (sys_power_batt_capacity[battery] - charge) / (float) current * 60;
-				printf("time est: %i\n", info->battery_time);
-			}
-			else {
-				info->battery_time = 0;
-			}
-			if (abs(info->battery_time) < 0.5)
-				info->battery_time = 0;
-		}
-		else {
-			fprintf(stderr, "unknown battery status: %s\n", status);
-			info->battery_status = BATTERY_STATUS_ABSENT;
-		}
-	}
-	else {
-		info->battery_percentage = 0;
-		info->battery_time = 0;
-		info->battery_status = BATTERY_STATUS_ABSENT;
-		sys_power_batt_capacity[battery] = 0;
-		if (sys_power_batt_count == 0) {
-			/* Where else would the power come from, eh? ;-) */
-			info->ac_line_status = 1;
-		}
-		else {
-			info->ac_line_status = sys_power_supported();
-		}
-	}
-	
-	return 0;
-}
-#endif
diff --git a/sys_power.h b/sys_power.h
deleted file mode 100644
index b9f452d..0000000
--- a/sys_power.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Support for the linux ACPI_SYS_POWER interface.
- * By Joey Hess <joey at kitenet.net>
- */
-
-/* Define SYS_POWER_APM to get the sys_power_read function, which is
- * like apm_read. */
-//#define SYS_POWER_APM 1
-
-/* If you don't have sysfs on /sys, change this.. */
-#define SYS_POWER "/sys/class/power_supply"
-
-/* The number of items of each class supported. */
-#define SYS_POWER_MAXITEM 8
-
-int sys_power_supported (void);
-#ifdef SYS_POWER_APM
-int sys_power_read (int battery, apm_info *info);
-#endif
-char *get_sys_power_value (const char *dir, const char *file);
-int get_sys_power_batt_capacity(int battery);
-
-extern int sys_power_batt_count;
-extern int sys_power_ac_count;
-extern char sys_power_batt_dirs[SYS_POWER_MAXITEM][128];
-extern char sys_power_ac_dirs[SYS_POWER_MAXITEM][128];
-/* Stores battery capacity, or 0 if the battery is absent. */
-extern int sys_power_batt_capacity[SYS_POWER_MAXITEM];
diff --git a/wmbattery.1x b/wmbattery.1x
index e691ab3..abdcea1 100644
--- a/wmbattery.1x
+++ b/wmbattery.1x
@@ -11,7 +11,7 @@ is a battery monitor.  It is used to visually display the system's battery
 status.
 .PP
 .B wmbattery
-can get battery information using /sys/class/power_supply, APM, /proc/acpi, or
+can get battery information using HAL, APM, ACPI, or
 the SPIC controller in some Sony laptops. You need to build your kernel with
 support for at least one of these for the program to work.
 .B wmbattery
@@ -66,9 +66,7 @@ it, it will turn red.
 Display list of command-line options.
 .TP
 .B \-w secs
-Pause this many seconds between updates. Defaults to 1 for most things, but
-3 for the /proc/acpi interface (since that interfaces takes quite a bit more
-CPU power).
+Pause this many seconds between updates.
 .TP
 .B \-d display
 Use the designated X display.
@@ -77,9 +75,9 @@ Use the designated X display.
 Specify geometry. This specifies position, not size.
 .TP
 .B \-b battnum
-Display the given battery. Only of use with the /sys/class/power_supply or 
-/proc/acpi interfaces on systems with more than one battery. The default is
-to display the first battery found.
+Display the given battery. Only of use with the HAL or ACPI interfaces on
+systems with more than one battery. The default is to display the first
+battery found.
 .TP
 .B \-l percent
 Set the percentage at which the battery is considered to be running low. By
diff --git a/wmbattery.c b/wmbattery.c
index 3e1ea2d..026e054 100644
--- a/wmbattery.c
+++ b/wmbattery.c
@@ -21,7 +21,9 @@
 #include "mask.xbm"
 #include "sonypi.h"
 #include "acpi.h"
-#include "sys_power.h"
+#ifdef HAL
+#include "simplehal.h"
+#endif
 
 Pixmap images[NUM_IMAGES];
 Window root, iconwin, win;
@@ -36,7 +38,9 @@ char *crit_audio;
 int crit_audio_size;
 
 int battnum = 1;
-int use_sys_power = 0;
+#ifdef HAL
+int use_simplehal = 0;
+#endif
 int use_sonypi = 0;
 int use_acpi = 0;
 int delay = 0;
@@ -244,7 +248,7 @@ char *parse_commandline(int argc, char *argv[]) {
 		  case 'c':
 			critical_pct = atoi(optarg);
 			break;
-		  case 'r':
+		  case 'e':
 			always_estimate_remaining = 1;
 			break;
 		  case 'a':
@@ -507,14 +511,16 @@ void alarmhandler(int sig) {
 	int old_status;
 
 	old_status = cur_info.battery_status;
-	if (use_sys_power) {
-		if (sys_power_read(battnum, &cur_info) != 0)
-			error("Cannot read " SYS_POWER " information.");
-	}
-	else if (use_acpi) {
+	if (use_acpi) {
 		if (acpi_read(battnum, &cur_info) != 0)
 			error("Cannot read ACPI information.");
 	}
+#ifdef HAL
+	else if (use_simplehal) {
+		if (simplehal_read(battnum, &cur_info) != 0)
+			error("Cannot read HAL information.");
+	}
+#endif
 	else if (! use_sonypi) {
 		if (apm_read(&cur_info) != 0)
 			error("Cannot read APM information.");
@@ -570,18 +576,19 @@ void check_battery_num(int real, int requested) {
 int main(int argc, char *argv[]) {
 	make_window(parse_commandline(argc, argv), argc ,argv);
 
-	/* Check for SYS_POWER support. */
-	if (sys_power_supported() && sys_power_batt_count > 0) {
-		check_battery_num(sys_power_batt_count, battnum);
-		use_sys_power = 1;
+	/*  Check for APM support (returns 0 on success). */
+	if (apm_exists() == 0) {
 		if (! delay)
 			delay = 1;
 	}
-	/*  Check for APM support (returns 0 on success). */
-	else if (apm_exists() == 0) {
+#ifdef HAL
+	/* Check for hal support. */
+	else if (simplehal_supported()) {
+		use_simplehal = 1;
 		if (! delay)
-			delay = 1;
+			delay = 2;
 	}
+#endif
 	/* Check for ACPI support. */
 	else if (acpi_supported() && acpi_batt_count > 0) {
 		check_battery_num(acpi_batt_count, battnum);
@@ -597,8 +604,7 @@ int main(int argc, char *argv[]) {
 			delay = 1;
 	}
 	else {
-	
-		error("No APM, ACPI, " SYS_POWER ", or SPIC support in kernel.");
+		error("No APM, ACPI, HAL or SPIC support detected.");
 	}
 		
 	load_images();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbattery.git



More information about the Pkg-wmaker-commits mailing list