xbattmon

simple battery monitor for X
git clone git://git.2f30.org/xbattmon.git
Log | Files | Refs | README | LICENSE

commit 9d5d2b8950db6d9cbaa3db608e08cbdbd7c120f8
parent 461669b5a2929381a5b96646b05a8a45660bbce3
Author: sin <sin@2f30.org>
Date:   Tue May 19 19:31:18 +0100

Add support for DragonFly BSD

Diffstat:
config.dfly.mk | 7+++++++
configure | 3+++
xbattmon.1 | 4++--
xbattmon.c | 24++++++++++++++++++++++++
4 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/config.dfly.mk b/config.dfly.mk @@ -0,0 +1,7 @@ +PREFIX = /usr/local +MANPREFIX = $(PREFIX)/man + +CPPFLAGS = -DVERSION=\"${VERSION}\" -DPATH_APM=\"/dev/apm\" +CFLAGS = -I/usr/local/include +LDFLAGS = -L/usr/local/lib +LDLIBS = -lX11 diff --git a/configure b/configure @@ -4,6 +4,9 @@ case `uname` in OpenBSD) ln -sf config.bsd.mk config.mk ;; +DragonFly) + ln -sf config.dfly.mk config.mk + ;; Linux) ln -sf config.linux.mk config.mk ;; diff --git a/xbattmon.1 b/xbattmon.1 @@ -1,4 +1,4 @@ -.Dd Apr 19, 2015 +.Dd May 19, 2015 .Dt XBATTMON 1 .Os .Sh NAME @@ -38,6 +38,6 @@ bars might find .Nm useful. .Sh PORTABILITY -It currently works on OpenBSD and Linux. +It currently works on DragonFly BSD, OpenBSD and Linux. .Sh AUTHORS .An Dimitris Papastamos Aq Mt sin@2f30.org . diff --git a/xbattmon.c b/xbattmon.c @@ -213,6 +213,30 @@ pollbat(void) state = info.ac_state == APM_AC_ON ? AC_ON : AC_OFF; } +#elif __DragonFly__ +#include <sys/ioctl.h> +#include <fcntl.h> +#include <machine/apm_bios.h> + +void +pollbat(void) +{ + struct apm_info ai; + int r; + int fd; + + fd = open(PATH_APM, O_RDONLY); + if (fd < 0) + err(1, "open %s", PATH_APM); + r = ioctl(fd, APMIO_GETINFO, &ai); + if (r < 0) + err(1, "APMIO_GETINFO %s", PATH_APM); + batcap = ai.ai_batt_life; + if (batcap > maxcap) + batcap = maxcap; + state = ai.ai_acline ? AC_ON : AC_OFF; + close(fd); +} #elif __linux__ void pollbat(void)