diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | components/cpu.c | 3 | ||||
| -rw-r--r-- | components/mpd.c | 38 | ||||
| -rw-r--r-- | components/ram.c | 6 | ||||
| -rw-r--r-- | components/swap.c | 6 | ||||
| -rw-r--r-- | components/vpn.c | 18 | ||||
| -rw-r--r-- | slstatus.h | 6 |
7 files changed, 74 insertions, 5 deletions
@@ -27,6 +27,8 @@ COM =\ components/uptime\ components/user\ components/volume\ + components/mpd\ + components/vpn\ components/wifi all: slstatus diff --git a/components/cpu.c b/components/cpu.c index d0d03c7..a0b7314 100644 --- a/components/cpu.c +++ b/components/cpu.c @@ -18,7 +18,8 @@ if (pscanf(CPU_FREQ, "%ju", &freq) != 1) return NULL; - return fmt_human(freq * 1000, 1000); + //return fmt_human(freq * 1000, 1000); + return bprintf("%.1f", freq/1e6); } const char * diff --git a/components/mpd.c b/components/mpd.c new file mode 100644 index 0000000..b32706e --- /dev/null +++ b/components/mpd.c @@ -0,0 +1,38 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdint.h> +#include <stdio.h> +#include <string.h> + +#include "../slstatus.h" +#include "../util.h" + +const char * +mpd_track(const char *path) +{ + FILE *fp; + const unsigned short N = 128; + char track[N]; + char state[16]; + + if (!(fp = fopen(path, "r"))) + return NULL; + + if (fgets(track, N, fp) == NULL || fscanf(fp, "%s", state) != 1) + { + fclose(fp); + return NULL; + } + + fclose(fp); + + // otherwise statusbar will show a weird symbol + track[strlen(track)-1] = '\0'; + + if (strcmp(state, "[playing]") == 0) + return bprintf("%s ", track); + + if (strcmp(state, "[paused]") == 0) + return bprintf("%s ", track); + + return NULL; +} diff --git a/components/ram.c b/components/ram.c index 15c4b74..503e7be 100644 --- a/components/ram.c +++ b/components/ram.c @@ -53,7 +53,8 @@ != 1) return NULL; - return fmt_human(total * 1024, 1024); + //return fmt_human(total * 1024, 1024); + return bprintf("%.1f", total/1048576.); } const char * @@ -71,7 +72,8 @@ return NULL; used = (total - free - buffers - cached); - return fmt_human(used * 1024, 1024); + //return fmt_human(used * 1024, 1024); + return bprintf("%4.1f", used/1048576.); } #elif defined(__OpenBSD__) #include <stdlib.h> diff --git a/components/swap.c b/components/swap.c index f270d93..6f47795 100644 --- a/components/swap.c +++ b/components/swap.c @@ -86,7 +86,8 @@ if (get_swap_info(&total, NULL, NULL)) return NULL; - return fmt_human(total * 1024, 1024); + //return fmt_human(total * 1024, 1024); + return bprintf("%4.1f", total/1048576.); } const char * @@ -97,7 +98,8 @@ if (get_swap_info(&total, &free, &cached)) return NULL; - return fmt_human((total - free - cached) * 1024, 1024); + //return fmt_human((total - free - cached) * 1024, 1024); + return bprintf("%4.1f", (total - free - cached)/1048576.); } #elif defined(__OpenBSD__) #include <stdlib.h> diff --git a/components/vpn.c b/components/vpn.c new file mode 100644 index 0000000..e5439fb --- /dev/null +++ b/components/vpn.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdint.h> +#include <stdio.h> +#include <string.h> + +#include "../slstatus.h" +#include "../util.h" + +const char * +vpn_status(const char *unused) +{ + char state[32]; + + if (pscanf("/sys/class/net/tun0/operstate", "%s", state) != 1) + return bprintf(""); + + return bprintf(""); +} @@ -82,3 +82,9 @@ const char *vol_perc(const char *card); /* wifi */ const char *wifi_essid(const char *interface); const char *wifi_perc(const char *interface); + +/* mpd */ +const char *mpd_track(const char *unused); + +/* vpn */ +const char *vpn_status(const char *unused); |
