summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2007-09-17 21:52:09 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2007-09-17 21:52:09 +0200
commit545c8310cb216c39d9bb9262167387d448863132 (patch)
tree765dcfd9cdbd488eb81ab7a1198ebc819eb5f0d2
parent44a84f6d0984fe5fca1fb7d52bff68763fda86c5 (diff)
Print uptime in statusbar
-rw-r--r--Makefile14
-rw-r--r--statusbar.c19
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 <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;
}