spoon

set dwm status
git clone git://git.2f30.org/spoon
Log | Files | Refs | LICENSE

commit a1183652b40ef2d2b72ee5a84e72ed499c9544f8
parent 013798f7c8c22eec779f63fbf2558092b29d2c0d
Author: sin <sin@2f30.org>
Date:   Mon, 17 Oct 2016 16:43:19 +0100

Add support for passing an argument to a plugin

Diffstat:
Mbatt.c | 4++--
Mconfig.def.h | 18+++++++++---------
Mcpu.c | 2+-
Mdate.c | 6++----
Mload.c | 2+-
Mmix.c | 2+-
Mmpd.c | 2+-
Mspoon.c | 27++++++++++++++-------------
Mstub.c | 14+++++++-------
Mtemp.c | 4++--
Mwifi.c | 2+-
Mxkblayout.c | 2+-
12 files changed, 42 insertions(+), 43 deletions(-)

diff --git a/batt.c b/batt.c @@ -30,7 +30,7 @@ battprint(char *buf, size_t len, int acon , int life) #include <machine/apmvar.h> int -battread(char *buf, size_t len) +battread(void *arg, char *buf, size_t len) { struct apm_power_info info; int ret, fd; @@ -52,7 +52,7 @@ battread(char *buf, size_t len) } #elif __linux__ int -battread(char *buf, size_t len) +battread(void *arg, char *buf, size_t len) { FILE *fp; int acon; diff --git a/config.def.h b/config.def.h @@ -5,13 +5,13 @@ char timeformat[] = "%a %d %b %Y %H:%M %Z"; struct ent ents[] = { /* reorder/remove these as you see fit */ - { .fmt = "[%s] ", .read = mpdread }, - { .fmt = "[%s] ", .read = mixread }, - { .fmt = "[%s] ", .read = loadread }, - { .fmt = "[%s] ", .read = cpuread }, - { .fmt = "[%s] ", .read = tempread }, - { .fmt = "%s ", .read = battread }, - { .fmt = "%s ", .read = wifiread }, - { .fmt = "[%s] ", .read = xkblayoutread }, - { .fmt = "%s", .read = dateread }, + { .fmt = "[%s] ", .read = mpdread, .arg = NULL }, + { .fmt = "[%s] ", .read = mixread, .arg = NULL }, + { .fmt = "[%s] ", .read = loadread, .arg = NULL }, + { .fmt = "[%s] ", .read = cpuread, .arg = NULL }, + { .fmt = "[%s] ", .read = tempread, .arg = NULL }, + { .fmt = "%s ", .read = battread, .arg = NULL }, + { .fmt = "%s ", .read = wifiread, .arg = NULL }, + { .fmt = "[%s] ", .read = xkblayoutread, .arg = NULL }, + { .fmt = "%s", .read = dateread, .arg = (char []){"%a %d %b %Y %H:%M %Z"} }, }; diff --git a/cpu.c b/cpu.c @@ -4,7 +4,7 @@ #include <sys/sysctl.h> int -cpuread(char *buf, size_t len) +cpuread(void *arg, char *buf, size_t len) { int mib[2], cpuspeed; size_t sz; diff --git a/date.c b/date.c @@ -3,10 +3,8 @@ #include <stdio.h> #include <time.h> -extern char timeformat[]; - int -dateread(char *buf, size_t len) +dateread(void *arg, char *buf, size_t len) { struct tm *now; time_t t; @@ -15,6 +13,6 @@ dateread(char *buf, size_t len) now = localtime(&t); if (now == NULL) return -1; - strftime(buf, len, timeformat, now); + strftime(buf, len, arg, now); return 0; } diff --git a/load.c b/load.c @@ -2,7 +2,7 @@ #include <stdio.h> int -loadread(char *buf, size_t len) +loadread(void *arg, char *buf, size_t len) { double avgs[3]; diff --git a/mix.c b/mix.c @@ -9,7 +9,7 @@ #include <string.h> int -mixread(char *buf, size_t len) +mixread(void *arg, char *buf, size_t len) { mixer_devinfo_t dinfo; mixer_ctrl_t mctl; diff --git a/mpd.c b/mpd.c @@ -6,7 +6,7 @@ #include "util.h" int -mpdread(char *buf, size_t len) +mpdread(void *arg, char *buf, size_t len) { static struct mpd_connection *conn; struct mpd_song *song; diff --git a/spoon.c b/spoon.c @@ -6,26 +6,27 @@ #define LEN(x) (sizeof (x) / sizeof *(x)) -int battread(char *, size_t); -int cpuread(char *, size_t); -int dateread(char *, size_t); -int dummyread(char *, size_t); -int loadread(char *, size_t); -int mixread(char *, size_t); -int mpdread(char *, size_t); -int tempread(char *, size_t); -int wifiread(char *, size_t); -int xkblayoutread(char *, size_t); +int battread(void *, char *, size_t); +int cpuread(void *, char *, size_t); +int dateread(void *, char *, size_t); +int dummyread(void *, char *, size_t); +int loadread(void *, char *, size_t); +int mixread(void *, char *, size_t); +int mpdread(void *, char *, size_t); +int tempread(void *, char *, size_t); +int wifiread(void *, char *, size_t); +int xkblayoutread(void *, char *, size_t); struct ent { char *fmt; - int (*read)(char *, size_t); + int (*read)(void *, char *, size_t); + void *arg; }; #include "config.h" int -dummyread(char *buf, size_t len) +dummyread(void *arg, char *buf, size_t len) { buf[0] = '\0'; return 0; @@ -43,7 +44,7 @@ entcat(char *line, size_t len) e = line + len; for (i = 0; i < LEN(ents); i++) { ent = &ents[i]; - ret = ent->read(buf, sizeof(buf)); + ret = ent->read(ent->arg, buf, sizeof(buf)); if (ret == 0 && s < e) s += snprintf(s, e - s, ent->fmt, buf); } diff --git a/stub.c b/stub.c @@ -2,49 +2,49 @@ #pragma weak battread int -battread(char *buf, size_t len) +battread(void *arg, char *buf, size_t len) { return -1; } #pragma weak cpuread int -cpuread(char *buf, size_t len) +cpuread(void *arg, char *buf, size_t len) { return -1; } #pragma weak mixread int -mixread(char *buf, size_t len) +mixread(void *arg, char *buf, size_t len) { return -1; } #pragma weak mpdread int -mpdread(char *buf, size_t len) +mpdread(void *arg, char *buf, size_t len) { return -1; } #pragma weak tempread int -tempread(char *buf, size_t len) +tempread(void *arg, char *buf, size_t len) { return -1; } #pragma weak wifiread int -wifiread(char *buf, size_t len) +wifiread(void *arg, char *buf, size_t len) { return -1; } #pragma weak xkblayoutread int -xkblayoutread(char *buf, size_t len) +xkblayoutread(void *arg, char *buf, size_t len) { return -1; } diff --git a/temp.c b/temp.c @@ -7,7 +7,7 @@ #include <sys/sensors.h> int -tempread(char *buf, size_t len) +tempread(void *arg, char *buf, size_t len) { int mib[5]; struct sensor temp; @@ -26,7 +26,7 @@ tempread(char *buf, size_t len) } #elif __linux__ int -tempread(char *buf, size_t len) +tempread(void *arg, char *buf, size_t len) { FILE *fp; int temp; diff --git a/wifi.c b/wifi.c @@ -35,7 +35,7 @@ wifiprint(char *buf, size_t len, int quality) #include <unistd.h> int -wifiread(char *buf, size_t len) +wifiread(void *arg, char *buf, size_t len) { struct ifaddrs *ifa, *ifas; struct ifmediareq ifmr; diff --git a/xkblayout.c b/xkblayout.c @@ -10,7 +10,7 @@ #include "util.h" int -xkblayoutread(char *buf, size_t len) +xkblayoutread(void *arg, char *buf, size_t len) { Display *dpy; XkbStateRec state;