Make battery option optional

This commit is contained in:
Alexander Weidinger
2018-11-25 15:02:50 +01:00
parent 6f64315083
commit c4e9657e1b
2 changed files with 31 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
all: all:
gcc -o dwmst -lX11 dwmst.c gcc -o dwmst -lX11 -D OPTION_BATTERY=0 dwmst.c
clean: clean:
rm -f dwmst rm -f dwmst

View File

@@ -31,6 +31,7 @@ int main(void) {
strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M", timeinfo); strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M", timeinfo);
if (OPTION_BATTERY) {
/* battery status */ /* battery status */
f = fopen("/sys/class/power_supply/BAT0/capacity", "r"); f = fopen("/sys/class/power_supply/BAT0/capacity", "r");
if (f == NULL) { if (f == NULL) {
@@ -39,8 +40,8 @@ int main(void) {
fgets(bbuffer, 4, f); fgets(bbuffer, 4, f);
strtok(bbuffer, "\n"); /* remove trailing white space */ strtok(bbuffer, "\n"); /* remove trailing white space */
strcat(bbuffer, "%"); strcat(bbuffer, "%");
}
fclose(f); fclose(f);
}
f = fopen("/sys/class/power_supply/BAT0/status", "r"); f = fopen("/sys/class/power_supply/BAT0/status", "r");
if (f == NULL) { if (f == NULL) {
@@ -56,11 +57,15 @@ int main(void) {
case 'F': /* Full */ case 'F': /* Full */
strcat(bbuffer, "="); strcat(bbuffer, "=");
} }
}
fclose(f); fclose(f);
}
}
/* build status */ /* build status */
if (OPTION_BATTERY)
sprintf(status, "%s | %s", tbuffer, bbuffer); sprintf(status, "%s | %s", tbuffer, bbuffer);
else
sprintf(status, "%s", tbuffer);
/* store root window name */ /* store root window name */
XStoreName(display, DefaultRootWindow(display), status); XStoreName(display, DefaultRootWindow(display), status);