status

statusbar program for dwm
git clone anongit@rnpnr.xyz:status.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 492d541a2af303d3822ce7adb597fdadbc998572
Parent: 267f86ff9db191c807a558752815a37c905543bf
Author: Randy Palamar
Date:   Tue, 16 Mar 2021 19:32:48 -0600

update batinfo functions

Diffstat:
MMakefile | 1+
Mblocks/battery.c | 26++++++++++++--------------
Mblocks/battery.h | 3+--
Mblocks/volume.c | 2--
Mconfig.def.h | 2++
Mstatus.c | 1+
Mstatus.h | 2++
Mutil.c | 1+
8 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/Makefile b/Makefile @@ -2,6 +2,7 @@ include config.mk SRC =\ + blocks/battery.c\ blocks/gettime.c\ blocks/volume.c\ status.c util.c diff --git a/blocks/battery.c b/blocks/battery.c @@ -7,15 +7,14 @@ #include "../util.h" #include "battery.h" -#if 0 #if defined(__linux__) size_t batinfo(struct Block *b) { + static char path[PATH_MAX], state[12]; int perc; unsigned long power_now, energy_now, h, m; double timeleft; - char path[PATH_MAX], state[12]; snprintf(path, sizeof(path), "/sys/class/power_supply/%s/capacity", bat); if (pscanf(path, "%d", &perc) != 1) @@ -40,10 +39,11 @@ batinfo(struct Block *b) h = timeleft; m = (timeleft - (double)h) * 60; - return bprintf("%d%% (%d:%02d)", perc, h, m); - } + bprintf(buf, sizeof(buf), "%d%% (%d:%02d)", perc, h, m); + } else + bprintf(buf, sizeof(buf), "%d%% (%s)", perc, state); - return bprintf("%d%% (%s)", perc, state); + return bprintf(b->curstr, BLOCKLEN, b->fmt, buf); } #elif defined(__OpenBSD__) @@ -52,8 +52,8 @@ batinfo(struct Block *b) #include <sys/ioctl.h> #include <unistd.h> -const char * -batinfo(const char *bat) +size_t +batinfo(struct Block *b) { struct apm_power_info pi; int fd; @@ -69,16 +69,14 @@ batinfo(const char *bat) switch (pi.ac_state) { case APM_AC_OFF: - return smprintf("%d%% (%d:%02d)", pi.battery_life, - pi.minutes_left / 60, pi.minutes_left % 60); + bprintf(buf, sizeof(buf), "%d%% (%d:%02d)", pi.battery_life, + pi.minutes_left / 60, pi.minutes_left % 60); case APM_AC_ON: case APM_BATT_CHARGING: - return bprintf("%d%% (ac)", pi.battery_life); + bprintf(buf, sizeof(buf), "%d%% (ac)", pi.battery_life); default: - return bprintf("%d%% (unknown)", pi.battery_life); + bprintf(buf, sizeof(buf), "%d%% (unknown)", pi.battery_life); } + return bprintf(b->curstr, BLOCKLEN, b->fmt, buf); } - -#else -#endif #endif diff --git a/blocks/battery.h b/blocks/battery.h @@ -1,2 +1,2 @@ extern const char *bat; -size_t batinfo(struct Block *b); -\ No newline at end of file +size_t batinfo(struct Block *b); diff --git a/blocks/volume.c b/blocks/volume.c @@ -14,8 +14,6 @@ size_t getvol(struct Block *b) { - static char buf[6]; - snd_mixer_t *handle; snd_mixer_selem_id_t *sid; snd_mixer_elem_t *elem; diff --git a/config.def.h b/config.def.h @@ -1,3 +1,4 @@ +#include "blocks/battery.h" #include "blocks/gettime.h" #include "blocks/volume.h" @@ -19,6 +20,7 @@ static const char *bat = "BAT0"; /* status block definitions */ struct Block blks[] = { /* fn fmt interval signal */ + { batinfo, "[ %s ]", 0, 0 }, { getvol, "[ %s ]", 0, 0 }, { gettime, "[ %R ]", 20, 0 }, { NULL }, diff --git a/status.c b/status.c @@ -12,6 +12,7 @@ static int done = 0; static int dflag = 0; +char buf[BLOCKLEN]; static Display *dpy; diff --git a/status.h b/status.h @@ -8,3 +8,5 @@ struct Block { char prevstr[BLOCKLEN]; size_t len; }; + +extern char buf[BLOCKLEN]; diff --git a/util.c b/util.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include "status.h" +#include "util.h" void die(const char *errstr, ...)