openbsd-ports/sysutils/xbatt/patches/patch-aa
kevlo 28f03c5de2 - Upgrade to version 1.2.1
- Clean up the Makefile
- Add @comment to PLIST
2000-06-21 03:11:12 +00:00

79 lines
2.1 KiB
Plaintext

--- xbatt.c.orig Wed Jun 21 18:58:25 2000
+++ xbatt.c Wed Jun 21 19:02:20 2000
@@ -65,6 +65,11 @@
# define APMDEV22 "/dev/apm"
#endif
+#ifdef __OpenBSD__
+# include <machine/apmvar.h>
+# define APMDEV "/dev/apm"
+#endif /* __OpenBSD__ */
+
#include "pixmaps/battery.xpm"
#include "pixmaps/unknown.xpm"
#include "bitmaps/full.xbm"
@@ -195,6 +200,12 @@
}
#endif
+#ifdef __OpenBSD__
+ /* initialize APM Interface */
+ if ((apmfd = open(APMDEV, O_RDONLY)) == -1)
+ err(1, "cannot open apm device");
+#endif /* __OpenBSD__ */
+
/* start X-Window session */
XtSetLanguageProc( NULL, NULL, NULL );
toplevel = XtOpenApplication(&appContext, "XBatt",
@@ -371,6 +382,50 @@
/* chrging or not. */
}
#endif /* FreeBSD */
+
+#ifdef __OpenBSD__
+ struct apm_power_info info;
+
+ if (ioctl(apmfd, APM_IOC_GETPOWER, &info) == -1)
+ err(1, "ioctl APM_IOC_GETPOWER failed");
+
+ /* get current status */
+ if (info.battery_life == APM_BATT_LIFE_UNKNOWN) {
+ switch (info.battery_state) {
+ case APM_BATT_HIGH:
+ ret.remain = 100;
+ break;
+ case APM_BATT_LOW:
+ ret.remain = 40;
+ break;
+ case APM_BATT_CRITICAL:
+ ret.remain = 10;
+ break;
+ default: /* expected to be APM_STAT_UNKNOWN */
+ ret.remain = APM_STAT_UNKNOWN;
+ }
+ } else if (info.battery_life > 100) {
+ /* some APM BIOSes return values slightly > 100 */
+ ret.remain = 100;
+ } else {
+ ret.remain = info.battery_life;
+ }
+
+ /* get AC-line status */
+ if (info.ac_state == APM_AC_ON) {
+ ret.acline = APM_STAT_LINE_ON;
+ } else {
+ ret.acline = APM_STAT_LINE_OFF;
+ }
+
+ /* get charging status */
+ if (info.battery_state == APM_BATT_CHARGING) {
+ ret.charge = APM_STAT_BATT_CHARGING;
+ } else {
+ ret.charge = APM_STAT_BATT_HIGH; /* I only want to know, */
+ /* chrging or not. */
+ }
+#endif /* __OpenBSD__ */
#ifdef __linux__
char buffer[64];