summaryrefslogtreecommitdiff
path: root/dwmstatus/custom.diff
blob: 11e5d052a954129e3fa72d74ebeb6114103fc04d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
diff --git a/dwmstatus.c b/dwmstatus.c
index d2a4b03..555f0bd 100644
--- a/dwmstatus.c
+++ b/dwmstatus.c
@@ -17,8 +17,6 @@
 
 #include <X11/Xlib.h>
 
-char *tzargentina = "America/Buenos_Aires";
-char *tzutc = "UTC";
 char *tzberlin = "Europe/Berlin";
 
 static Display *dpy;
@@ -89,7 +87,7 @@ loadavg(void)
 	if (getloadavg(avgs, 3) < 0)
 		return smprintf("");
 
-	return smprintf("%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]);
+	return smprintf("%.2f", avgs[1]);
 }
 
 char *
@@ -155,7 +153,7 @@ getbattery(char *base)
 	} else if(!strncmp(co, "Charging", 8)) {
 		status = '+';
 	} else {
-		status = '?';
+		status = '\0';
 	}
 
 	if (remcap < 0 || descap < 0)
@@ -175,47 +173,70 @@ gettemperature(char *base, char *sensor)
 	return smprintf("%02.0f°C", atof(co) / 1000);
 }
 
+char *
+getpartition(char *partition) {
+	char *co = smprintf("df -lh | grep %s | tr -s ' ' | cut -d ' ' -f 4 | tr -d '\n'", partition);
+	FILE *fd = popen(co, "r");
+	if (fd == NULL)
+		return smprintf("invalid");
+
+	char ret[8];
+	if (fgets(ret, 8, fd) == NULL)
+		return smprintf("invalid");
+
+	if (pclose(fd) == -1)
+		return smprintf("invalid");
+
+	return smprintf("%s", ret);
+}
+
+char *
+getvolume() {
+	char *co = smprintf("amixer -D pulse sget Master | grep % | head -n 1 | cut -d ' ' -f 7 | tr -d '[]\n'");
+	FILE *fd = popen(co, "r");
+
+	if (fd == NULL)
+		return smprintf("invalid");
+
+	char ret[8];
+	if (fgets(ret, 8, fd) == NULL)
+		return smprintf("invalid");
+
+	if (pclose(fd) == -1)
+		return smprintf("invalid");
+
+	return smprintf("%s", ret);
+}
+
 int
 main(void)
 {
 	char *status;
 	char *avgs;
 	char *bat;
-	char *bat1;
-	char *tmar;
-	char *tmutc;
 	char *tmbln;
-	char *t0, *t1, *t2;
+	char *partition;
+	char *volume;
 
 	if (!(dpy = XOpenDisplay(NULL))) {
 		fprintf(stderr, "dwmstatus: cannot open display.\n");
 		return 1;
 	}
 
-	for (;;sleep(60)) {
+	for (;;sleep(1)) {
 		avgs = loadavg();
+		partition = getpartition("/$");
 		bat = getbattery("/sys/class/power_supply/BAT0");
-		bat1 = getbattery("/sys/class/power_supply/BAT1");
-		tmar = mktimes("%H:%M", tzargentina);
-		tmutc = mktimes("%H:%M", tzutc);
-		tmbln = mktimes("KW %W %a %d %b %H:%M %Z %Y", tzberlin);
-		t0 = gettemperature("/sys/devices/virtual/hwmon/hwmon0", "temp1_input");
-		t1 = gettemperature("/sys/devices/virtual/hwmon/hwmon2", "temp1_input");
-		t2 = gettemperature("/sys/devices/virtual/hwmon/hwmon4", "temp1_input");
-
-		status = smprintf("T:%s|%s|%s L:%s B:%s|%s A:%s U:%s %s",
-				t0, t1, t2, avgs, bat, bat1, tmar, tmutc,
-				tmbln);
+		tmbln = mktimes("%a %d %b %H:%M", tzberlin);
+		volume = getvolume();
+
+		status = smprintf(" %s | %s | %s | %s | %s",
+				  avgs, partition, volume, bat, tmbln);
 		setstatus(status);
 
-		free(t0);
-		free(t1);
-		free(t2);
 		free(avgs);
+		free(volume);
 		free(bat);
-		free(bat1);
-		free(tmar);
-		free(tmutc);
 		free(tmbln);
 		free(status);
 	}