diff options
-rw-r--r-- | Makefile | 14 | ||||
-rw-r--r-- | statusbar.c | 19 |
2 files changed, 26 insertions, 7 deletions
@@ -1,7 +1,19 @@ CFLAGS=-Wall LDFLAGS=-lacpi -lcpufreq +BINDIR=$(HOME)/bin + all: statusbar statusbar: statusbar.c - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< + @echo "CC $@" + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< + @echo "strip $@" + +install: statusbar + @echo "installing $< to $(BINDIR)" + @install -m 700 -D $< $(BINDIR)/$< + +clean: + @echo "cleaning" + @rm -f statusbar diff --git a/statusbar.c b/statusbar.c index 5f36935..e055100 100644 --- a/statusbar.c +++ b/statusbar.c @@ -1,8 +1,6 @@ /* * Fast and easy way to gather the necessary information for dwm status bar * - * Compile with gcc -Wall -lacpi -lcpufreq -o statusbar statusbar.c - * * Copyright (c) 2007 T. Klauser <tklauser@distanz.ch> */ @@ -11,10 +9,14 @@ #include <stdio.h> #include <stdlib.h> #include <time.h> +#include <sys/sysinfo.h> #include <libacpi.h> #include <cpufreq.h> #define DATE_STR "%a %Y-%m-%d %H:%M:%S" +#define HOUR 3600 /* sec per hour */ +#define MINUTE 60 /* sec per min */ +#define LOADS_SCALE 65536.0 int main(int argc, char **argv) { @@ -22,7 +24,8 @@ int main(int argc, char **argv) struct tm tim; char str[25]; unsigned long freq, tmp_freq; - double load[3]; + long up, uph, upm; + struct sysinfo info; global_t g; if (check_acpi_support() == NOT_SUPPORTED) @@ -75,10 +78,14 @@ int main(int argc, char **argv) printf("Hz | "); - /* 5) Load average */ - if (getloadavg(load, 3) < 0) + /* 5) Uptime and load average */ + if (sysinfo(&info) < 0) return -1; - printf("%.02f %.02f %.02f\n", load[0], load[1], load[2]); + + up = info.uptime; + uph = up / HOUR; + upm = (up % HOUR) / MINUTE; + printf("%lu:%.02lu | %.02f %.02f %.02f\n", uph, upm, info.loads[0] / LOADS_SCALE, info.loads[1] / LOADS_SCALE, info.loads[2] / LOADS_SCALE); return 0; } |