From 545c8310cb216c39d9bb9262167387d448863132 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 17 Sep 2007 21:52:09 +0200 Subject: Print uptime in statusbar --- Makefile | 14 +++++++++++++- statusbar.c | 19 +++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 3234256..c622673 100644 --- a/Makefile +++ b/Makefile @@ -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 */ @@ -11,10 +9,14 @@ #include #include #include +#include #include #include #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; } -- cgit v1.2.3-54-g00ecf