summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2007-09-17 17:49:01 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2007-09-17 17:49:01 +0200
commit8ba73b98bb5f5ab8103c71875399a6c73cfc827d (patch)
treefcf3954b25e8c1a0238c5d6180473d0ab7ce9a66
Initial import
-rw-r--r--statusbar.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/statusbar.c b/statusbar.c
new file mode 100644
index 0000000..5f36935
--- /dev/null
+++ b/statusbar.c
@@ -0,0 +1,85 @@
+/*
+ * 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>
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <libacpi.h>
+#include <cpufreq.h>
+
+#define DATE_STR "%a %Y-%m-%d %H:%M:%S"
+
+int main(int argc, char **argv)
+{
+ time_t today;
+ struct tm tim;
+ char str[25];
+ unsigned long freq, tmp_freq;
+ double load[3];
+ global_t g;
+
+ if (check_acpi_support() == NOT_SUPPORTED)
+ return -1;
+ if (!(init_acpi_batt(&g) == SUCCESS))
+ return -1;
+ if (!(init_acpi_thermal(&g) == SUCCESS))
+ return -1;
+
+ /* 1) Date */
+ time(&today);
+ tim = *localtime(&today);
+ strftime(str, 25, DATE_STR, &tim);
+ str[25] = '\0';
+ printf("%s | ", str);
+
+ /* 2) Battery percentage (only the first battery matters for now) */
+ read_acpi_batt(0);
+ if (batteries[0].present)
+ printf("%d%% | ", batteries[0].percentage);
+
+ /* 3) Temperature */
+ printf("%d C | ", g.temperature);
+
+ /* 4) Current CPU frequency */
+ freq = cpufreq_get_freq_kernel(0);
+ if (!freq)
+ return -1;
+
+ /* 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);
+
+ printf("Hz | ");
+
+ /* 5) Load average */
+ if (getloadavg(load, 3) < 0)
+ return -1;
+ printf("%.02f %.02f %.02f\n", load[0], load[1], load[2]);
+
+ return 0;
+}
+