Add brightness
This commit is contained in:
parent
763cfb7384
commit
9ea61f6907
39
dwmstatus.c
39
dwmstatus.c
@ -165,6 +165,36 @@ getbattery(char *base)
|
|||||||
return smprintf("%s %.0f%%", status, ((float)remcap / (float)descap) * 100);
|
return smprintf("%s %.0f%%", status, ((float)remcap / (float)descap) * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
getBrightness(char *base) {
|
||||||
|
char *co;
|
||||||
|
int brightness, max_brightness;
|
||||||
|
char *status;
|
||||||
|
|
||||||
|
co = readfile(base, "brightness");
|
||||||
|
if (co == NULL)
|
||||||
|
return smprintf("");
|
||||||
|
|
||||||
|
sscanf(co, "%d", &brightness);
|
||||||
|
free(co);
|
||||||
|
|
||||||
|
co = readfile(base, "max_brightness");
|
||||||
|
if (co == NULL)
|
||||||
|
return smprintf("");
|
||||||
|
sscanf(co, "%d", &max_brightness);
|
||||||
|
free(co);
|
||||||
|
|
||||||
|
int percentage = (((float)brightness / (float)max_brightness) * 100);
|
||||||
|
|
||||||
|
if(percentage < 50) {
|
||||||
|
status = "🔅";
|
||||||
|
} else {
|
||||||
|
status = "☀";
|
||||||
|
}
|
||||||
|
|
||||||
|
return smprintf("%s %d%% ", status, percentage);
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
gettemperature(char *base, char *sensor)
|
gettemperature(char *base, char *sensor)
|
||||||
{
|
{
|
||||||
@ -184,20 +214,22 @@ main(void)
|
|||||||
char *tmbln;
|
char *tmbln;
|
||||||
char *t0;
|
char *t0;
|
||||||
char *bat;
|
char *bat;
|
||||||
|
char *brightness;
|
||||||
|
|
||||||
if (!(dpy = XOpenDisplay(NULL))) {
|
if (!(dpy = XOpenDisplay(NULL))) {
|
||||||
fprintf(stderr, "dwmstatus: cannot open display.\n");
|
fprintf(stderr, "dwmstatus: cannot open display.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
// 🖱
|
||||||
for (;;sleep(60)) {
|
for (;;sleep(60)) {
|
||||||
avgs = loadavg();
|
avgs = loadavg();
|
||||||
tmbln = mktimes("%H:%M %d.%m.%Y", tzwarsaw);
|
tmbln = mktimes("%H:%M %d.%m.%Y", tzwarsaw);
|
||||||
t0 = gettemperature("/sys/class//hwmon/hwmon1", "temp1_input");
|
t0 = gettemperature("/sys/class//hwmon/hwmon1", "temp1_input");
|
||||||
bat = getbattery("/sys/class/power_supply/BAT0");
|
bat = getbattery("/sys/class/power_supply/BAT0");
|
||||||
|
brightness = getBrightness("/sys/class/backlight/amdgpu_bl0");
|
||||||
|
|
||||||
status = smprintf("%s 🌡 %s 📈 %s 📅 %s",
|
status = smprintf("%s %s🌡 %s 📈 %s 📅 %s",
|
||||||
bat, t0, avgs, tmbln);
|
bat, brightness, t0, avgs, tmbln);
|
||||||
setstatus(status);
|
setstatus(status);
|
||||||
|
|
||||||
free(t0);
|
free(t0);
|
||||||
@ -205,6 +237,7 @@ main(void)
|
|||||||
free(avgs);
|
free(avgs);
|
||||||
free(tmbln);
|
free(tmbln);
|
||||||
free(status);
|
free(status);
|
||||||
|
free(brightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
|
Loading…
Reference in New Issue
Block a user