X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/1d43e2f2b2a31caa48f16d0042d56e57545b2b48..85dd971fb312f3c401937ea4ad118ecd701bee49:/slstatus.c diff --git a/slstatus.c b/slstatus.c index 9884aaa..0dee744 100644 --- a/slstatus.c +++ b/slstatus.c @@ -18,13 +18,52 @@ #include #include #include +#include #include #include #include #include -/* local headers */ -#include "slstatus.h" +/* statusbar configuration type and struct */ +typedef char *(*op_fun) (const char *); +struct arg { + op_fun func; + const char *format; + const char *args; +}; + +/* function declarations */ +void setstatus(const char *str); +char *smprintf(const char *fmt, ...); +char *battery_perc(const char *battery); +char *cpu_perc(const char *null); +char *datetime(const char *timeformat); +char *disk_free(const char *mountpoint); +char *disk_perc(const char *mountpoint); +char *disk_total(const char *mountpoint); +char *disk_used(const char *mountpoint); +char *entropy(const char *null); +char *gid(const char *null); +char *hostname(const char *null); +char *ip(const char *interface); +char *load_avg(const char *null); +char *ram_free(const char *null); +char *ram_perc(const char *null); +char *ram_used(const char *null); +char *ram_total(const char *null); +char *run_command(const char *command); +char *temp(const char *file); +char *uid(const char *null); +char *uptime(const char *null); +char *username(const char *null); +char *vol_perc(const char *soundcard); +char *wifi_perc(const char *wificard); +char *wifi_essid(const char *wificard); + +/* global variables */ +static Display *dpy; + +/* configuration header */ #include "config.h" /* set statusbar */ @@ -342,6 +381,22 @@ ip(const char *interface) return smprintf(unknowntext); } +/* load avg */ +char * +load_avg(const char *null) +{ + double avgs[3]; + + /* try to get load avg */ + if (getloadavg(avgs, 3) < 0) { + fprintf(stderr, "Error getting load avg.\n"); + return smprintf(unknowntext); + } + + /* return it */ + return smprintf("%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]); +} + /* ram free */ char * ram_free(const char *null) @@ -505,6 +560,23 @@ temp(const char *file) return smprintf("%d°C", temperature / 1000); } +/* uptime */ +char * +uptime(const char *null) +{ + struct sysinfo info; + int hours = 0; + int minutes = 0; + + /* get info */ + sysinfo(&info); + hours = info.uptime / 3600; + minutes = (info.uptime - hours * 3600 ) / 60; + + /* return it */ + return smprintf("%dh %dm", hours, minutes); +} + /* username */ char * username(const char *null)