summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--statusbar.c79
1 files changed, 44 insertions, 35 deletions
diff --git a/statusbar.c b/statusbar.c
index 234cb70..ba36dc8 100644
--- a/statusbar.c
+++ b/statusbar.c
@@ -1,6 +1,8 @@
/*
* Fast and easy way to gather the necessary information for dwm status bar
*
+ * Needs libacpi-dev and libcpufreq-dev
+ *
* Copyright (c) 2007 T. Klauser <tklauser@distanz.ch>
*/
@@ -13,7 +15,7 @@
#include <libacpi.h>
#include <cpufreq.h>
-#define DATE_STR "%a %Y-%m-%d %H:%M:%S"
+#define DATE_STR "%a %Y-%m-%d %H:%M"
#define HOUR 3600 /* sec per hour */
#define MINUTE 60 /* sec per min */
#define LOADS_SCALE 65536.0
@@ -23,6 +25,7 @@ int main(int argc, char **argv)
time_t today;
struct tm tim;
char str[25];
+ int temp;
unsigned long freq, tmp_freq;
long up, uph, upm;
struct sysinfo info;
@@ -49,49 +52,55 @@ int main(int argc, char **argv)
if (batteries[0].present)
printf("%d%% %s| ", batteries[0].percentage,
g.adapt.ac_state == P_AC ? "(ac) " : "");
+ else
+ printf("n/a%% | ");
/* 3) Temperature */
- printf("%d C | ", g.temperature);
+ temp = g.temperature;
+ if (temp < 0 || temp == NOT_SUPPORTED)
+ printf("n/a C | ");
+ else
+ printf("%d C | ", temp);
/* 4) Current CPU frequency */
freq = cpufreq_get_freq_kernel(0);
- if (!freq)
- return -1;
+ if (freq) {
+ /* Taken from cpufrequtils */
+ if (freq > 1000000) {
+ tmp_freq = freq % 10000;
+ if (tmp_freq >= 5000)
+ freq += 10000;
+ printf("%u.%02u G", ((unsigned int) freq / 1000000),
+ ((unsigned int) (freq % 1000000) / 10000));
+ } else if (freq > 100000) {
+ tmp_freq = freq % 1000;
+ if (tmp_freq >= 500)
+ freq += 1000;
+ printf("%u M", ((unsigned int) freq / 1000));
+ } else if (freq > 1000) {
+ tmp_freq = freq % 100;
+ if (tmp_freq >= 50)
+ freq += 100;
+ printf("%u.%01u M", ((unsigned int) freq / 1000),
+ ((unsigned int) (freq % 1000) / 100));
+ } else
+ printf("%lu k", freq);
- /* Taken from cpufrequtils */
- if (freq > 1000000) {
- tmp_freq = freq % 10000;
- if (tmp_freq >= 5000)
- freq += 10000;
- printf("%u.%02u G", ((unsigned int) freq / 1000000),
- ((unsigned int) (freq % 1000000) / 10000));
- } else if (freq > 100000) {
- tmp_freq = freq % 1000;
- if (tmp_freq >= 500)
- freq += 1000;
- printf("%u M", ((unsigned int) freq / 1000));
- } else if (freq > 1000) {
- tmp_freq = freq % 100;
- if (tmp_freq >= 50)
- freq += 100;
- printf("%u.%01u M", ((unsigned int) freq / 1000),
- ((unsigned int) (freq % 1000) / 100));
+ printf("Hz | ");
} else
- printf("%lu k", freq);
-
- printf("Hz | ");
+ printf("n/a | ");
/* 5) Uptime and load average */
- if (sysinfo(&info) < 0)
- return -1;
-
- 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);
+ if (sysinfo(&info) == 0) {
+ 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);
+ } else
+ printf("n/a | n/a\n");
return 0;
}