$NetBSD: patch-ab,v 1.4 2003/06/03 16:04:45 jmmv Exp $ --- src/aapm.cc.orig 2003-03-08 20:37:52.000000000 +0100 +++ src/aapm.cc @@ -15,6 +15,12 @@ #ifdef CONFIG_APPLET_APM +#if defined(__NetBSD__) +#include +#include +#include +#endif + #include "ylib.h" #include "sysdep.h" @@ -47,6 +53,7 @@ extern YColor *taskBarBg; void ApmStr(char *s, bool Tool) { +#if !defined(__NetBSD__) char buf[80]; int len, i, fd = open("/proc/apm", O_RDONLY); char driver[16]; @@ -121,6 +128,46 @@ void ApmStr(char *s, bool Tool) { strcat(s, _(" - Charging")); else strcat(s, _("C")); +#else + struct apm_power_info aip; + int fd = open(APMDEV, O_RDONLY); + + if (fd == -1) { + return; + } + + memset(&aip, 0, sizeof(aip)); + if (ioctl(fd, APM_IOC_GETPOWER, &aip) == -1) { + fprintf(stderr, "ioctl failed on APMDEV"); + close(fd); + 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 } int ignore_directory_entry(struct dirent *de) {