diff options
-rw-r--r-- | include/common.h | 32 | ||||
-rw-r--r-- | include/status/battery.h | 7 | ||||
-rw-r--r-- | include/status/cpuusage.h | 7 | ||||
-rw-r--r-- | include/status/datetime.h | 7 | ||||
-rw-r--r-- | include/status/fan.h | 7 | ||||
-rw-r--r-- | include/status/memusage.h | 7 | ||||
-rw-r--r-- | include/status/netif.h | 7 | ||||
-rw-r--r-- | include/status/temp.h | 7 | ||||
-rw-r--r-- | include/status/uptime.h | 7 | ||||
-rw-r--r-- | include/status/volume_alsa.h | 9 | ||||
-rw-r--r-- | include/statuses.h | 18 | ||||
-rw-r--r-- | src/common/common.c | 74 | ||||
-rw-r--r-- | src/status/battery.c | 30 | ||||
-rw-r--r-- | src/status/cpuusage.c | 33 | ||||
-rw-r--r-- | src/status/datetime.c | 61 | ||||
-rw-r--r-- | src/status/fan.c | 25 | ||||
-rw-r--r-- | src/status/memusage.c | 18 | ||||
-rw-r--r-- | src/status/netif.c | 27 | ||||
-rw-r--r-- | src/status/temp.c | 29 | ||||
-rw-r--r-- | src/status/uptime.c | 83 | ||||
-rw-r--r-- | src/status/volume_alsa.c | 32 | ||||
-rw-r--r-- | src/sysstatus.c | 61 |
22 files changed, 364 insertions, 224 deletions
diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..04869bb --- /dev/null +++ b/include/common.h @@ -0,0 +1,32 @@ +#ifndef __COMMON_H__ +#define __COMMON_H__ + +#include <sys/types.h> + +typedef struct GlobalData GlobalData; + +typedef struct { + char *color; + char *text; +} StatusItem; + + +typedef struct GlobalData { + char *line; + size_t linelen; + size_t linemax; /* Buffer size, including NUL */ +} GlobalData; + + + +void line_clear(GlobalData *g); +void line_append_strn(GlobalData *g, char *string, size_t len); +void line_append_str(GlobalData *g, char *string); + +void line_append_item(GlobalData *g, StatusItem *s); + +void line_print(GlobalData *g); + +void statusitem_init(StatusItem *s); + +#endif diff --git a/include/status/battery.h b/include/status/battery.h deleted file mode 100644 index 0824392..0000000 --- a/include/status/battery.h +++ /dev/null @@ -1,7 +0,0 @@ - -#ifndef __BATTERY_H__ -#define __BATTERY_H__ - -void status_battery(char *batname); - -#endif diff --git a/include/status/cpuusage.h b/include/status/cpuusage.h deleted file mode 100644 index 1de2aed..0000000 --- a/include/status/cpuusage.h +++ /dev/null @@ -1,7 +0,0 @@ - -#ifndef __CPUUSAGE_H__ -#define __CPUUSAGE_H__ - -void status_cpuusage(); - -#endif diff --git a/include/status/datetime.h b/include/status/datetime.h deleted file mode 100644 index e4c9554..0000000 --- a/include/status/datetime.h +++ /dev/null @@ -1,7 +0,0 @@ - -#ifndef __DATETIME_H__ -#define __DATETIME_H__ - -void status_datetime(); - -#endif diff --git a/include/status/fan.h b/include/status/fan.h deleted file mode 100644 index dd5e494..0000000 --- a/include/status/fan.h +++ /dev/null @@ -1,7 +0,0 @@ - -#ifndef __FAN_H__ -#define __FAN_H__ - -void status_fan(char *title, char *sysfile); - -#endif diff --git a/include/status/memusage.h b/include/status/memusage.h deleted file mode 100644 index 9db9719..0000000 --- a/include/status/memusage.h +++ /dev/null @@ -1,7 +0,0 @@ - -#ifndef __MEMUSAGE_H__ -#define __MEMUSAGE_H__ - -void status_memusage(); - -#endif diff --git a/include/status/netif.h b/include/status/netif.h deleted file mode 100644 index 92ccc1f..0000000 --- a/include/status/netif.h +++ /dev/null @@ -1,7 +0,0 @@ - -#ifndef __NETIF_H__ -#define __NETIF_H__ - -void status_netif(char *ifname); - -#endif diff --git a/include/status/temp.h b/include/status/temp.h deleted file mode 100644 index 0856a17..0000000 --- a/include/status/temp.h +++ /dev/null @@ -1,7 +0,0 @@ - -#ifndef __TEMP_H__ -#define __TEMP_H__ - -void status_temp(char *title, char *sysfile); - -#endif diff --git a/include/status/uptime.h b/include/status/uptime.h deleted file mode 100644 index 153f35d..0000000 --- a/include/status/uptime.h +++ /dev/null @@ -1,7 +0,0 @@ - -#ifndef __UPTIME_H__ -#define __UPTIME_H__ - -void status_uptime(); - -#endif diff --git a/include/status/volume_alsa.h b/include/status/volume_alsa.h deleted file mode 100644 index 044824d..0000000 --- a/include/status/volume_alsa.h +++ /dev/null @@ -1,9 +0,0 @@ - -#ifndef __VOLUME_ALSA_H__ -#define __VOLUME_ALSA_H__ - -#include <alsa/asoundlib.h> - -int status_volume_alsa(char *cardname, char *mixername, snd_mixer_selem_channel_id_t channel); - -#endif diff --git a/include/statuses.h b/include/statuses.h new file mode 100644 index 0000000..c523afd --- /dev/null +++ b/include/statuses.h @@ -0,0 +1,18 @@ +#ifndef __STATUSES_H__ +#define __STATUSES_H__ + +#include <alsa/asoundlib.h> + +#include "common.h" + +void status_battery(GlobalData *g, char *batname); +void status_cpuusage(GlobalData *g); +void status_datetime(GlobalData *g); +void status_fan(GlobalData *g, char *title, char *sysfile); +void status_memusage(GlobalData *g); +void status_netif(GlobalData *g, char *ifname); +void status_temp(GlobalData *g, char *title, char *sysfile); +void status_uptime(GlobalData *g); +int status_volume_alsa(GlobalData *g, char *cardname, char *mixername, snd_mixer_selem_channel_id_t channel); + +#endif diff --git a/src/common/common.c b/src/common/common.c new file mode 100644 index 0000000..9e62259 --- /dev/null +++ b/src/common/common.c @@ -0,0 +1,74 @@ +#include <assert.h> +#include <stdio.h> +#include <string.h> +#include <sys/types.h> + +#include "common.h" + + +static int linebuf_sane(GlobalData *g) +{ + return (g->linelen < g->linemax); +} + + +void line_clear(GlobalData *g) +{ + assert(g->linemax > 0); + + g->line[0] = '\0'; + g->linelen = 0; +} + + +void line_append_strn(GlobalData *g, char *string, size_t len) +{ + assert(linebuf_sane(g)); + + if (g->linemax <= g->linelen + len) { + /* Buffer full. Tough luck. */ + return; + } + + memcpy(&g->line[g->linelen], string, len); + g->linelen += len; + g->line[g->linelen] = '\0'; +} + + +void line_append_str(GlobalData *g, char *string) +{ + line_append_strn(g, string, strlen(string)); +} + + + +void line_append_item(GlobalData *g, StatusItem *s) +{ + line_append_str(g, " "); + + if (s->color) { + line_append_str(g, "^fg("); + line_append_str(g, s->color); + line_append_str(g, ")"); + } + + if (s->text) { + line_append_str(g, s->text); + } + + line_append_str(g, " "); +} + + +void line_print(GlobalData *g) +{ + puts(g->line); +} + + +void statusitem_init(StatusItem *s) +{ + s->color = NULL; + s->text = NULL; +} diff --git a/src/status/battery.c b/src/status/battery.c index 34bfcc0..65fdd1b 100644 --- a/src/status/battery.c +++ b/src/status/battery.c @@ -3,7 +3,7 @@ #include <unistd.h> #include <string.h> -#include "status/battery.h" +#include "common.h" #include "tools.h" #ifndef POWER_BASEDIR @@ -11,8 +11,11 @@ #endif -void status_battery(char *batname) +void status_battery(GlobalData *g, char *batname) { + StatusItem s; + char text[32] = { 0 }; + char batpath[256]; int batpathlen; @@ -26,6 +29,9 @@ void status_battery(char *batname) float battTime = -1; + statusitem_init(&s); + s.text = text; + /* Prepare path */ batpathlen = sizeof(POWER_BASEDIR) - 1 + strlen(batname); if (batpathlen + 1 + sizeof("/energy_full") >= sizeof(batpath)) { @@ -73,21 +79,21 @@ void status_battery(char *batname) if (chargePercent <= 40) { if (chargePercent <= 25) { if (chargePercent <= 10) { - fputs("^fg(red)", stdout); + s.color = "red"; } else { // 11-25% - fputs("^fg(orange)", stdout); + s.color = "orange"; } } else { // 26-40% - fputs("^fg(yellow)", stdout); + s.color = "yellow"; } } else { if (chargePercent > 70) { - fputs("^fg(white)", stdout); + s.color = "white"; } else { // 41-70% - fputs("^fg(green)", stdout); + s.color = "green"; } } @@ -95,10 +101,12 @@ void status_battery(char *batname) if (battW == 0) { // fully charged and not in use - printf(" %s: %d%% _ _ ", - batname, chargePercent); + snprintf(text, sizeof(text), "%s: %d%% _ _", + batname, chargePercent); } else { - printf(" %s: %d%% %.1fh %.1fW ", - batname, chargePercent, battTime, (float)battW / 1000000.0); + snprintf(text, sizeof(text), "%s: %d%% %.1fh %.1fW", + batname, chargePercent, battTime, (float)battW / 1000000.0); } + + line_append_item(g, &s); } diff --git a/src/status/cpuusage.c b/src/status/cpuusage.c index 1bb34ae..a3b1d5d 100644 --- a/src/status/cpuusage.c +++ b/src/status/cpuusage.c @@ -3,7 +3,7 @@ #include <unistd.h> #include <stdlib.h> -#include "status/cpuusage.h" +#include "common.h" #include "config.h" #ifndef NUM_CPUS @@ -21,8 +21,11 @@ unsigned long last_cpu_used = 0; unsigned long last_cpu_total = 0; float cpu_history[CPU_HISTORY_SIZE]; // don't care about init values -void status_cpuusage() +void status_cpuusage(GlobalData *g) { + StatusItem s; + char text[32] = { 0 }; + double loadavg[3] = { -13.37, -13.37, -13.37 } ; char *stline = NULL; @@ -38,8 +41,11 @@ void status_cpuusage() int i; + statusitem_init(&s); + s.text = text; + // Error signaling color - fputs("^fg(yellow)", stdout); + s.color = "yellow"; stfile = fopen("/proc/stat", "r"); if (stfile != NULL) { @@ -65,13 +71,11 @@ void status_cpuusage() if (cpu_history[0] < 0.4) { // CPU idling OK - fputs("^fg(#0077FF)", stdout); + s.color = "#0077FF"; } else { // CPU busy - fputs("^fg(#FF00FF)", stdout); + s.color = "#FF00FF"; } - - //printf(" CPU: %.0f%% ", cpu_history[0] * 100); } free(stline); @@ -79,13 +83,14 @@ void status_cpuusage() if (getloadavg(loadavg, 3) > 0) { - printf(" %s%.0f,%.0f,%.0f,%.0f ", - cpu_history[0] < 0.1000 ? " " : "", - cpu_history[0] * 100, - loadavg[0] * (100 / 1), - loadavg[1] * (100 / 1), // (100 / NUM_CPUS) - loadavg[2] * (100 / 1)); + snprintf(text, sizeof(text), + "%s%.0f,%.0f,%.0f,%.0f", + cpu_history[0] < 0.1000 ? " " : "", + cpu_history[0] * 100, + loadavg[0] * (100 / 1), + loadavg[1] * (100 / 1), // (100 / NUM_CPUS) + loadavg[2] * (100 / 1)); } - //fputs(" CPU usage ", stdout); + line_append_item(g, &s); } diff --git a/src/status/datetime.c b/src/status/datetime.c index a25d411..d7d9d0a 100644 --- a/src/status/datetime.c +++ b/src/status/datetime.c @@ -1,36 +1,53 @@ #include <stdio.h> #include <time.h> -#include "status/datetime.h" +#include "common.h" #include "config.h" -void status_datetime() +void status_datetime(GlobalData *g) { + StatusItem s; + char text[32] = { 0 }; + time_t nows = 0; struct tm *nowtm; + + statusitem_init(&s); + s.text = text; + nows = time(NULL); if (nows == ((time_t) -1)) { - printf(" ^fg(red)ERROR: DATETIME"); - return; - } + s.color = "red"; + s.text = "ERROR: DATETIME"; - nowtm = localtime(&nows); - - printf(" ^fg(#666666)%d.%d.%d ^fg(grey)%d:%.2d" - #ifdef SHOW_SECONDS - ":%.2d" - #endif - " " - ,nowtm -> tm_mday, - (nowtm -> tm_mon) + 1, - (nowtm -> tm_year) + 1900, - nowtm -> tm_hour, - nowtm -> tm_min - - #ifdef SHOW_SECONDS - ,nowtm -> tm_sec - #endif - ); + line_append_item(g, &s); + } else { + nowtm = localtime(&nows); + + s.color = "#666666"; + snprintf(text, sizeof(text), + "%d.%d.%d", + nowtm->tm_mday, + (nowtm->tm_mon) + 1, + (nowtm->tm_year) + 1900 + ); + line_append_item(g, &s); + + s.color = "grey"; + snprintf(text, sizeof(text), + "%d:%.2d" + #ifdef SHOW_SECONDS + ":%.2d" + #endif + ,nowtm->tm_hour, + nowtm->tm_min + + #ifdef SHOW_SECONDS + ,nowtm -> tm_sec + #endif + ); + line_append_item(g, &s); + } } diff --git a/src/status/fan.c b/src/status/fan.c index 0e7cfdf..6b26678 100644 --- a/src/status/fan.c +++ b/src/status/fan.c @@ -2,15 +2,22 @@ #include <fcntl.h> #include <unistd.h> -#include "status/fan.h" +#include "common.h" #include "tools.h" -void status_fan(char *title, char *sysfile) +void status_fan(GlobalData *g, char *title, char *sysfile) { + StatusItem s; + char text[16] = { 0 }; + char stline[16]; ssize_t stlen; + + statusitem_init(&s); + s.text = text; + stlen = fileRead(stline, sizeof(stline), sysfile); if (stlen <= 0) { return; @@ -18,12 +25,14 @@ void status_fan(char *title, char *sysfile) // Read a valid value? Sometimes we get garbage from sysfs... if (stlen > 5) { - printf(" ^fg(red)%sERROR ", title); - return; + s.color = "red"; + snprintf(text, sizeof(text), "%sERROR", title); + } else { + stline[stlen - 1] = '\0'; + + s.color = "#CCCCCC"; + snprintf(text, sizeof(text), "%s%s rpm", title, stline); } - fputs(" ^fg(#CCCCCC)", stdout); - fputs(title, stdout); - fwrite(stline, 1, stlen - 1, stdout); - fputs(" rpm ", stdout); + line_append_item(g, &s); } diff --git a/src/status/memusage.c b/src/status/memusage.c index 6a6cb21..f69c027 100644 --- a/src/status/memusage.c +++ b/src/status/memusage.c @@ -1,12 +1,15 @@ #include <stdio.h> #include <stdlib.h> -#include "status/memusage.h" +#include "common.h" #include "tools.h" -void status_memusage() +void status_memusage(GlobalData *g) { + StatusItem s; + char text[16] = { 0 }; + char *stline = NULL; size_t stlen; FILE *stfile; @@ -18,6 +21,9 @@ void status_memusage() int memcached = 0; + statusitem_init(&s); + s.text = text; + stfile = fopen("/proc/meminfo", "r"); if (stfile != NULL) { stlen = getline(&stline, &stlen, stfile); @@ -41,11 +47,13 @@ void status_memusage() /* Change color based on % of RAM used */ if ((float)memused / (float)memtotal < 0.85) { - fputs("^fg(green)", stdout); + s.color = "green"; } else { - fputs("^fg(red)", stdout); + s.color = "red"; } - printf(" Mem: %d M ", memused); + snprintf(text, sizeof(text), "Mem: %d M", memused); + + line_append_item(g, &s); } } diff --git a/src/status/netif.c b/src/status/netif.c index 23e6520..3c0fef0 100644 --- a/src/status/netif.c +++ b/src/status/netif.c @@ -3,7 +3,7 @@ #include <unistd.h> #include <string.h> -#include "status/netif.h" +#include "common.h" #include "tools.h" #include "config.h" @@ -12,8 +12,11 @@ #endif -void status_netif(char *ifname) +void status_netif(GlobalData *g, char *ifname) { + StatusItem s; + char text[16] = { 0 }; + char ifpath[256]; int ifpathlen; @@ -24,6 +27,9 @@ void status_netif(char *ifname) int ifsumpower; + statusitem_init(&s); + s.text = text; + /* Prepare path */ ifpathlen = sizeof(NETIF_BASEDIR) - 1 + strlen(ifname); if (ifpathlen + 1 + sizeof("/statistics/rx_bytes") >= sizeof(ifpath)) { @@ -38,7 +44,7 @@ void status_netif(char *ifname) /* Is the interface up? */ if (access(ifpath, F_OK)) { - //printf(" ^fg(grey)[%s] ", ifname); + //s.color = "grey"; return; } @@ -47,9 +53,9 @@ void status_netif(char *ifname) stlen = fileRead(stline, sizeof(stline), ifpath); if (stlen > 0) { if (stline[0] == '1') { - fputs("^fg(yellow)", stdout); + s.color = "yellow"; } else { - //fputs("^fg(red)", stdout); + //s.color = "red"; return; } } else { @@ -73,8 +79,11 @@ void status_netif(char *ifname) ifsum = ifsum / 1024; } - printf(" %s: %.*f %c ", ifname, - ifsumpower ? ifsumpower - 1 : ifsumpower, - ifsum, - powerToChar(ifsumpower)); + snprintf(text, sizeof(text), "%s: %.*f %c", + ifname, + ifsumpower ? ifsumpower - 1 : ifsumpower, + ifsum, + powerToChar(ifsumpower)); + + line_append_item(g, &s); } diff --git a/src/status/temp.c b/src/status/temp.c index e6763d0..c102fcd 100644 --- a/src/status/temp.c +++ b/src/status/temp.c @@ -2,15 +2,22 @@ #include <fcntl.h> #include <unistd.h> -#include "status/temp.h" +#include "common.h" #include "tools.h" -void status_temp(char *title, char *sysfile) +void status_temp(GlobalData *g, char *title, char *sysfile) { + StatusItem s; + char text[16] = { 0 }; + char stline[16]; ssize_t stlen; + + statusitem_init(&s); + s.text = text; + stlen = fileRead(stline, sizeof(stline), sysfile); if (stlen <= 0) { return; @@ -21,16 +28,14 @@ void status_temp(char *title, char *sysfile) * Sometimes we get garbage from sysfs... */ if (stlen < 6 || stlen > 7) { - printf(" ^fg(red)%sERROR ", title); - return; + s.color = "red"; + snprintf(text, sizeof(text), "%sERROR", title); + } else { + stline[stlen - 4] = '\0'; + + s.color = "#FF33FF"; + snprintf(text, sizeof(text), "%s%s°C", title, stline); } - fputs(" ^fg(#FF33FF)", stdout); - fputs(title, stdout); - fwrite(stline, 1, stlen - 4, stdout); - /* - fputs(".", stdout); - fwrite(&stline[stlen - 3], 1, 1, stdout); - */ - fputs("°C ", stdout); + line_append_item(g, &s); } diff --git a/src/status/uptime.c b/src/status/uptime.c index 106051c..ef5b2e5 100644 --- a/src/status/uptime.c +++ b/src/status/uptime.c @@ -3,57 +3,70 @@ #include <unistd.h> #include <stdlib.h> -#include "status/uptime.h" +#include "common.h" #include "tools.h" #include "config.h" -void status_uptime() +void status_uptime(GlobalData *g) { + StatusItem s; + char text[16] = { 0 }; + char stline[16]; ssize_t stlen; int i; int upts, uptm, upth, uptd; - fputs(" ^fg(#AAAAAA)up: ", stdout); + + statusitem_init(&s); + s.text = text; stlen = fileRead(stline, sizeof(stline), "/proc/uptime"); if (stlen < 0) { - fputs(" ^fg(red)ERROR ", stdout); - return; - } + s.color = "red"; + s.text = "up: ERROR"; + } else { + unsigned textlen = 0; - /* Cut first element */ - for(i = 0; i < stlen; i++) { - if (stline[i] == ' ') { - stline[i] = '\0'; - break; + /* Cut first element */ + for(i = 0; i < stlen; i++) { + if (stline[i] == ' ') { + stline[i] = '\0'; + break; + } } - } - // Split time into days, hours, mins, secs - upts = atoi(stline); - uptd = upts / (24 * 60 * 60); - upts -= uptd * (24 * 60 * 60); - upth = upts / (60 * 60); - upts -= upth * (60 * 60); - uptm = upts / (60); - upts -= uptm * (60); - - if (uptd > 0) { - printf("%dd ", uptd); - } + // Split time into days, hours, mins, secs + upts = atoi(stline); + uptd = upts / (24 * 60 * 60); + upts -= uptd * (24 * 60 * 60); + upth = upts / (60 * 60); + upts -= upth * (60 * 60); + uptm = upts / (60); + upts -= uptm * (60); - printf("%d:%.2d" - #ifdef SHOW_SECONDS - ":%.2d" - #endif + s.color = "#AAAAAA"; + textlen = snprintf(text, sizeof(text), "up: "); + if (uptd > 0) { + textlen += snprintf(&text[textlen], sizeof(text) - textlen, "%dd ", uptd); + } + + + snprintf(&text[textlen], sizeof(text) - textlen, + "%d:%.2d" + #ifdef SHOW_SECONDS + ":%.2d" + #endif - " " - ,upth - ,uptm + "" + ,upth + ,uptm - #ifdef SHOW_SECONDS - ,upts - #endif - ); + #ifdef SHOW_SECONDS + ,upts + #endif + ); + + line_append_item(g, &s); + } } diff --git a/src/status/volume_alsa.c b/src/status/volume_alsa.c index 41f61b8..54fe44e 100644 --- a/src/status/volume_alsa.c +++ b/src/status/volume_alsa.c @@ -1,10 +1,16 @@ #include <alsa/asoundlib.h> -#include "status/volume_alsa.h" +#include "common.h" -int status_volume_alsa(char *cardname, char *mixername, snd_mixer_selem_channel_id_t channel) +int status_volume_alsa(GlobalData *g, + char *cardname, + char *mixername, + snd_mixer_selem_channel_id_t channel) { + StatusItem s; + char text[16] = { 0 }; + snd_mixer_t *handle = NULL; snd_mixer_elem_t *elem; snd_mixer_selem_id_t *sid; @@ -14,6 +20,9 @@ int status_volume_alsa(char *cardname, char *mixername, snd_mixer_selem_channel_ int on_off; + statusitem_init(&s); + s.text = text; + snd_mixer_selem_id_alloca(&sid); if (snd_mixer_open(&handle, 0) < 0) { @@ -42,26 +51,17 @@ int status_volume_alsa(char *cardname, char *mixername, snd_mixer_selem_channel_ if (snd_mixer_selem_has_playback_volume(elem) && snd_mixer_selem_has_playback_channel(elem, channel)) { snd_mixer_selem_get_playback_switch(elem, channel, &on_off); - if (on_off) { - fputs("^fg(#22FF22)", stdout); - } else { - fputs("^fg(red)", stdout); - } - snd_mixer_selem_get_playback_volume_range(elem, &min, &max); - snd_mixer_selem_get_playback_volume(elem, channel, &volume); - fputs("^ca(1, amixer sset Master toggle)", stdout); - fputs("^ca(4, amixer sset Master 2+ unmute)", stdout); - fputs("^ca(5, amixer sset Master 2- unmute)", stdout); - printf(" Vol: %d ", (int)volume); - fputs("^ca()", stdout); - fputs("^ca()", stdout); - fputs("^ca()", stdout); + + s.color = on_off ? "#22FF22" : "red"; + snprintf(text, sizeof(text), "Vol: %d", (int)volume); } snd_mixer_close(handle); + line_append_item(g, &s); + return 0; ERROR: diff --git a/src/sysstatus.c b/src/sysstatus.c index bbc945b..cc11c11 100644 --- a/src/sysstatus.c +++ b/src/sysstatus.c @@ -1,49 +1,56 @@ #include <stdio.h> #include <stdlib.h> +#include "common.h" #include "config.h" -#include "status/battery.h" -#include "status/cpuusage.h" -#include "status/datetime.h" -#include "status/fan.h" -#include "status/memusage.h" -#include "status/netif.h" -#include "status/volume_alsa.h" -#include "status/temp.h" -#include "status/uptime.h" +#include "statuses.h" + + +static char outline[1024]; + +static GlobalData gd = { + .line = outline, + .linemax = sizeof(outline), +}; void updatestatus() { - //status_uptime(); + GlobalData *g = &gd; + - status_cpuusage(); + line_clear(g); - status_battery("BAT0"); - status_battery("BAT1"); + //status_uptime(g); - status_memusage(); + status_cpuusage(g); - status_netif("eth0"); - //status_netif("eth1"); - //status_netif("eth2"); - status_netif("wlan0"); - //status_netif("wlan1"); - status_netif("wlan2"); - //status_netif("usb0"); - status_netif("ppp0"); + status_battery(g, "BAT0"); + status_battery(g, "BAT1"); + + status_memusage(g); + + status_netif(g, "eth0"); + //status_netif(g, "eth1"); + //status_netif(g, "eth2"); + status_netif(g, "wlan0"); + //status_netif(g, "wlan1"); + status_netif(g, "wlan2"); + //status_netif(g, "usb0"); + status_netif(g, "ppp0"); //status_temp("GPU: ", "/sys/class/hwmon/hwmon0/device/temp4_input"); //status_temp("CPU: ", "/sys/class/hwmon/hwmon0/device/temp2_input"); - status_temp("CPU: ", "/sys/devices/platform/coretemp.0/temp1_input"); + status_temp(g, "CPU: ", "/sys/devices/platform/coretemp.0/temp1_input"); + + status_fan(g, "Fan: ", "/sys/devices/platform/thinkpad_hwmon/fan1_input"); - status_fan("Fan: ", "/sys/devices/platform/thinkpad_hwmon/fan1_input"); + status_volume_alsa(g, "default", "Master", 0); - status_volume_alsa("default", "Master", 0); + status_datetime(g); - status_datetime(); + line_print(g); - fputs("\n", stdout); fflush(stdout); } |