status

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

Commit: 309468cd71cefd05240ce20f6f2373a904f41b79
Parent: d2225033d5b3acd9b8d8231f341e22f7cc776b4d
Author: Randy Palamar
Date:   Wed, 17 Mar 2021 12:50:37 -0600

add an arg field to Block struct

this consists of an int/char * union and will be used by certain blocks
which require parameters

Diffstat:
Mblocks/battery.c | 8++++----
Mblocks/battery.h | 1-
Mblocks/volume.c | 2+-
Mblocks/volume.h | 2--
Mconfig.def.h | 21++++++++-------------
Mstatus.h | 1+
6 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/blocks/battery.c b/blocks/battery.c @@ -16,22 +16,22 @@ batinfo(struct Block *b) unsigned long power_now, energy_now, h, m; double timeleft; - snprintf(path, sizeof(path), "/sys/class/power_supply/%s/capacity", bat); + snprintf(path, sizeof(path), "/sys/class/power_supply/%s/capacity", b->u.s); if (pscanf(path, "%d", &perc) != 1) perc = 0; - snprintf(path, sizeof(path), "/sys/class/power_supply/%s/status", bat); + snprintf(path, sizeof(path), "/sys/class/power_supply/%s/status", b->u.s); if (pscanf(path, "%12s", &state) != 1) snprintf(state, sizeof(state), "Unknown"); if (!strcmp(state, "Discharging")) { snprintf(path, sizeof(path), - "/sys/class/power_supply/%s/power_now", bat); + "/sys/class/power_supply/%s/power_now", b->u.s); if (pscanf(path, "%lu", &power_now) != 1) power_now = 1; snprintf(path, sizeof(path), - "/sys/class/power_supply/%s/energy_now", bat); + "/sys/class/power_supply/%s/energy_now", b->u.s); if (pscanf(path, "%lu", &energy_now) != 1) energy_now = 0; diff --git a/blocks/battery.h b/blocks/battery.h @@ -1,2 +1 @@ -extern const char *bat; size_t batinfo(struct Block *b); diff --git a/blocks/volume.c b/blocks/volume.c @@ -28,7 +28,7 @@ getvol(struct Block *b) snd_mixer_selem_id_malloc(&sid); snd_mixer_selem_id_set_index(sid, 0); - snd_mixer_selem_id_set_name(sid, alsaoutput); + snd_mixer_selem_id_set_name(sid, b->u.s); elem = snd_mixer_find_selem(handle, sid); snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_MONO, &vol); diff --git a/blocks/volume.h b/blocks/volume.h @@ -1,4 +1,2 @@ extern const char *alsacard; -extern const char *alsaoutput; - size_t getvol(struct Block *b); diff --git a/config.def.h b/config.def.h @@ -5,23 +5,18 @@ #define STATUSLEN 1024 /* host for connecting to MPD, set to NULL for the MPD_HOST env variable */ -static const char *mpdhost = "localhost"; +const char *mpdhost = "localhost"; /* alsa card and output */ -/* card is whatever alsamixer lists as card, default is probably correct - output is the output from that specific card you want the vol from */ -static const char *alsacard = "default"; -static const char *alsaoutput = "Speaker"; - -/* main battery in system */ -/* found in /sys/class/power_supply/ */ -static const char *bat = "BAT0"; +/* card is found with 'aplay -L', default is probably correct + * output is specified as an arg */ +const char *alsacard = "default"; /* status block definitions */ struct Block blks[] = { -/* fn fmt interval signal */ - { batinfo, "[ %s ]", 0, 0 }, - { getvol, "[ %s ]", 0, 0 }, - { gettime, "[ %R ]", 20, 0 }, +/* fn fmt interval signal arg */ + { batinfo, "[ %s ]", 0, 0, { .s = "BAT0" } }, + { getvol, "[ %s ]", 0, 0, { .s = "Speaker" } }, + { gettime, "[ %R ]", 20, 0, {0} }, { NULL }, }; diff --git a/status.h b/status.h @@ -4,6 +4,7 @@ struct Block { const char *fmt; const int interval; const int signal; + union { const char *s; const int i; } u; char curstr[BLOCKLEN]; char prevstr[BLOCKLEN]; size_t len;