status

statusbar program for dwm
git clone anongit@rnpnr.xyz:status.git
Log | Files | Refs | Feed | README | LICENSE

blight.c (587B)


      1 /* See LICENSE for license details. */
      2 #include <limits.h>
      3 
      4 static size_t
      5 blight(struct Block *b)
      6 {
      7 	char path[PATH_MAX];
      8 	int perc;
      9 	unsigned long max, now;
     10 
     11 	snprintf(path, sizeof(path), "/sys/class/backlight/%s/brightness", (char *)b->arg);
     12 	if (pscanf(path, "%lu", &now) != 1)
     13 		now = 0;
     14 
     15 	snprintf(path, sizeof(path), "/sys/class/backlight/%s/max_brightness", (char *)b->arg);
     16 	if (pscanf(path, "%lu", &max) != 1)
     17 		/* avoid divison by 0 */
     18 		max = 1;
     19 
     20 	perc = 100 * now / max;
     21 	snprintf(buf, sizeof(buf), "%d%%", perc);
     22 
     23 	return snprintf(b->curstr, LEN(b->curstr), b->fmt, buf);
     24 }