xbattmon

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

commit b425c2fc6abcc4e1107b077a7a8d6f5ce2da9789
parent 6a5ad5d8f77e28637529a77f7619808bb97255f7
Author: sin <sin@2f30.org>
Date:   Fri,  7 Nov 2014 14:57:22 +0000

Factor out the battery path configuration to config.*.mk

Diffstat:
config.bsd.mk | 3++-
config.linux.mk | 2++
xbattmon.c | 17++++++-----------
3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/config.bsd.mk b/config.bsd.mk @@ -1,6 +1,7 @@ PREFIX = /usr/local MANPREFIX = $(PREFIX)/man -CPPFLAGS = -I/usr/X11R6/include +CPPFLAGS = -DPATH_APM='"/dev/apm"' +CFLAGS = -I/usr/X11R6/include LDFLAGS = -L/usr/X11R6/lib LDLIBS = -lX11 diff --git a/config.linux.mk b/config.linux.mk @@ -1,4 +1,6 @@ PREFIX = /usr/local MANPREFIX = $(PREFIX)/man +CPPFLAGS = -DPATH_BAT_CAP='"/sys/class/power_supply/BAT0/capacity"' \ + -DPATH_AC_ONLINE='"/sys/class/power_supply/AC/online"' LDLIBS = -lX11 -lbsd diff --git a/xbattmon.c b/xbattmon.c @@ -9,14 +9,14 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef __linux__ -#include <bsd/stdlib.h> -#endif + +#include <X11/Xlib.h> #ifdef __OpenBSD__ #include <machine/apmvar.h> +#elif __linux__ +#include <bsd/stdlib.h> #endif -#include <X11/Xlib.h> #include "arg.h" @@ -137,7 +137,6 @@ pollbat(void) int r; int fd; -#define PATH_APM "/dev/apm" fd = open(PATH_APM, O_RDONLY); if (fd < 0) err(1, "open %s", PATH_APM); @@ -162,17 +161,15 @@ pollbat(void) FILE *fp; int acon; -#define PATH_BAT0_CAP "/sys/class/power_supply/BAT0/capacity" - fp = fopen(PATH_BAT0_CAP, "r"); + fp = fopen(PATH_BAT_CAP, "r"); if (fp == NULL) - err(1, "fopen %s", PATH_BAT0_CAP); + err(1, "fopen %s", PATH_BAT_CAP); fscanf(fp, "%d", &batcap); fclose(fp); if (batcap > maxcap) batcap = maxcap; -#define PATH_AC_ONLINE "/sys/class/power_supply/AC/online" fp = fopen(PATH_AC_ONLINE, "r"); if (fp == NULL) err(1, "fopen %s", PATH_AC_ONLINE); @@ -181,8 +178,6 @@ pollbat(void) state = acon != 0 ? AC_ON : AC_OFF; } -#else -#error unsupported system #endif Bool