--- xbatt.c.orig	Tue Jan 21 15:21:27 1997
+++ xbatt.c	Tue Jul 21 15:24:07 1998
@@ -64,6 +64,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"
@@ -193,6 +198,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",
@@ -369,6 +380,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];
