From 424dc5abe49891c6c211cd50f3680bd5a06bd690 Mon Sep 17 00:00:00 2001 From: broke Date: Wed, 22 Jul 2026 08:10:30 +0600 Subject: [PATCH] OpenBSD battery percentage status addon for xstatus 0.2-beta --- apm.c | 28 ++++++++++++++++++++++++++++ config.h | 1 + status.c | 1 + 3 files changed, 30 insertions(+) create mode 100644 apm.c diff --git a/apm.c b/apm.c new file mode 100644 index 0000000..8926d17 --- /dev/null +++ b/apm.c @@ -0,0 +1,28 @@ +/* See LICENSE file for license and copyright details */ + +#include +#include +#include +#include +#include +#include "config.h" + +/* initiate the apm struct and a apm_fd */ +struct apm_power_info apm_info; +int apm_fd; + +/* Calling the status and pos variables from status.c */ +extern char *status; +extern int pos; + +void battery(char *status) +{ + /* I don't have any better idea than this... yet */ + /* TODO handle opening /dev/apm correctly (help please) */ + if (apm_fd == 0) apm_fd = open("/dev/apm", O_RDONLY); + if (ioctl(apm_fd,APM_IOC_GETPOWER,&apm_info) != -1) + { + snprintf(status+pos,MAXSIZE,"[%3d%%]",apm_info.battery_life); + pos += strlen(status); + } +} diff --git a/config.h b/config.h index 84c3674..e878daa 100644 --- a/config.h +++ b/config.h @@ -4,6 +4,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 c81c07d..57e05c0 100644 --- a/status.c +++ b/status.c @@ -41,6 +41,7 @@ int main(void) pos = 0; /* Addons */ + battery(status); /* Time */ timeaddr = time(NULL); -- 2.54.0