i3 - improved tiling WM


Fix Dragonfly BSD CPU temperature gauge

Patch status: merged

Patch by Robin Hahling

Long description:

This patch fixes CPU temperature gauge for DragonFly BSD.
Commit 0eeded8 assumed that fetching CPU temperature for DragonFly
BSD was similar to that of FreeBSD but this assumption is false.

To apply this patch, use:
curl http://cr.i3wm.org/patch/635/raw.patch | git am

b/src/print_cpu_temperature.c

16
@@ -8,7 +8,7 @@
17
 
18
 #include "i3status.h"
19
 
20
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
21
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
22
 #include <err.h>
23
 #include <sys/types.h>
24
 #include <sys/sysctl.h>
25
@@ -17,6 +17,13 @@
26
 #define TZ_AVG(x) ((x) - TZ_ZEROC) / 10
27
 #endif
28
 
29
+#if defined(__DragonFly__)
30
+#include <sys/sysctl.h>
31
+#include <sys/types.h>
32
+#include <sys/sensors.h>
33
+#define MUKTOC(v) ((v - 273150000) / 1000000.0)
34
+#endif
35
+
36
 #if defined(__OpenBSD__)
37
 #include <sys/param.h>
38
 #include <sys/types.h>
39
@@ -82,7 +89,27 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
40
                                         colorful_output = false;
41
                                 }
42
                         }
43
-#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
44
+#elif defined(__DragonFly__)
45
+			struct sensor th_sensor;
46
+			size_t th_sensorlen;
47
+
48
+			th_sensorlen = sizeof(th_sensor);
49
+
50
+			if (sysctlbyname(thermal_zone, &th_sensor, &th_sensorlen, NULL, 0) == -1) {
51
+				perror("sysctlbyname");
52
+				goto error;
53
+			}
54
+			if (MUKTOC(th_sensor.value) >= max_threshold) {
55
+				START_COLOR("color_bad");
56
+				colorful_output = true;
57
+			}
58
+			outwalk += sprintf(outwalk, "%.2f", MUKTOC(th_sensor.value));
59
+			if (colorful_output) {
60
+				END_COLOR;
61
+				colorful_output = false;
62
+			}
63
+
64
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
65
                         int sysctl_rslt;
66
                         size_t sysctl_size = sizeof(sysctl_rslt);
67
                         if (sysctlbyname(thermal_zone, &sysctl_rslt, &sysctl_size, NULL, 0))