$NetBSD: patch-ab,v 1.2 2002/02/26 09:41:40 martti Exp $

--- src/aapm.cc.orig	Tue Oct  9 16:54:03 2001
+++ src/aapm.cc	Tue Feb 26 09:02:17 2002
@@ -25,6 +25,12 @@
 
 #ifdef CONFIG_APPLET_APM
 
+#if defined(__NetBSD__)
+#include <sys/ioctl.h>
+#include <machine/apmvar.h>
+#include <fcntl.h>
+#endif
+
 YColor *YApm::apmBg = 0;
 YColor *YApm::apmFg = 0;
 YFont *YApm::apmFont = 0;
@@ -32,6 +38,7 @@
 extern YPixmap *taskbackPixmap;
 
 void ApmStr(char *s, bool Tool) {
+#if !defined(__NetBSD__)
     char buf[45];
     int len, i, fd = open("/proc/apm", O_RDONLY);
     char driver[16];
@@ -102,6 +109,44 @@
             strcat(s,_(" - Charging"));
         else
             strcat(s,_("M"));
+#else
+    struct apm_power_info aip;
+    int fd = open(APMDEV, O_RDONLY);
+
+    if (fd == -1) {
+        return;
+    }
+
+    if (ioctl(fd, APM_IOC_GETPOWER, &aip) == -1) {
+        fprintf(stderr, "ioctl failed on APMDEV");
+        return;
+    }
+
+    if (!Tool) {
+        if (taskBarShowApmTime) {
+            if (aip.minutes_left == 0) {
+                sprintf(s, "%02d", aip.battery_life);
+            } else
+                sprintf(s, "%d:%02d", aip.minutes_left/60, aip.minutes_left%60);
+        } else
+            sprintf(s, "%02d", aip.battery_life);
+    } else {
+        sprintf(s, "%d%%", aip.battery_life);
+    }
+
+    if (aip.ac_state == APM_AC_ON)
+        if (Tool)
+            strcat(s,_(" - Power"));
+        else
+            strcat(s,_("P"));
+    if (aip.battery_state == APM_BATT_CHARGING)
+        if (Tool)
+            strcat(s,_(" - Charging"));
+        else
+            strcat(s,_("M"));
+
+    close(fd);
+#endif
 }
 
 YApm::YApm(YWindow *aParent): YWindow(aParent) {
