From 696b2785b4b99e0a12e735009b33f471a0131d40 Mon Sep 17 00:00:00 2001 From: broke Date: Mon, 6 Jul 2026 05:14:37 +0600 Subject: [PATCH] OpenBSD battery percentage status addon for xstatus 0.1 --- apm.c | 21 +++++++++++++++++++++ config.h | 1 + status.c | 1 + 3 files changed, 23 insertions(+) create mode 100644 apm.c diff --git a/apm.c b/apm.c new file mode 100644 index 0000000..02231c8 --- /dev/null +++ b/apm.c @@ -0,0 +1,21 @@ +#include +#include +#include +#include +#include +#include "config.h" + +struct apm_power_info info; +int apm_fd; +extern char *status; +extern int pos; + +void battery(char *status) +{ + if (apm_fd == 0) apm_fd = open("/dev/apm",O_RDONLY); + if (ioctl(apm_fd,APM_IOC_GETPOWER,&info) != -1) + { + snprintf(status+pos,MAXSIZE,"[%3d%%]",info.battery_life); + pos += strlen(status); + } +} diff --git a/config.h b/config.h index 811847a..fd106ef 100644 --- a/config.h +++ b/config.h @@ -2,6 +2,7 @@ #define CONFIG_H /* addon function declaration */ +void battery(char *); /* main configuration */ #define TIME 1 /* Delay time, if you use %H:%m, set this to 60 */ diff --git a/status.c b/status.c index ea93a12..aa0d886 100644 --- a/status.c +++ b/status.c @@ -43,6 +43,7 @@ int main(void) pos = 0; /* Addons */ + battery(status); /* Time */ timeaddr = time(NULL); -- 2.54.0