status

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

Commit: 6bc72b5404d9e6d77f66c8835b57a83787ab32be
Parent: 9074d06ac54b924b2d24df2b5fb03420563691c8
Author: Randy Palamar
Date:   Fri,  3 Jun 2022 17:26:41 -0600

add a block for printing display brightness in percent

Diffstat:
MLICENSE | 2+-
Ablocks/blight_linux.c | 30++++++++++++++++++++++++++++++
Ablocks/blight_linux.h | 1+
Mconfig.def.h | 2++
Mconfig.mk | 1+
5 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/LICENSE b/LICENSE @@ -1,6 +1,6 @@ ISC License (ISC) -© 2019-2021 Randy Palamar <palamar@ualberta.ca> +© 2019-2022 Randy Palamar <palamar@ualberta.ca> © 2021 Ashish Kumar Yadav Permission to use, copy, modify, and distribute this software for any diff --git a/blocks/blight_linux.c b/blocks/blight_linux.c @@ -0,0 +1,30 @@ +/* See LICENSE for license details. */ +#include <limits.h> +#include <stdio.h> +#include <string.h> + +#include "../status.h" +#include "../util.h" +#include "blight_linux.h" + +size_t +blight(struct Block *b) +{ + char path[PATH_MAX]; + int perc; + unsigned long max, now; + + snprintf(path, sizeof(path), "/sys/class/backlight/%s/brightness", b->u.s); + if (pscanf(path, "%lu", &now) != 1) + now = 0; + + snprintf(path, sizeof(path), "/sys/class/backlight/%s/max_brightness", b->u.s); + if (pscanf(path, "%lu", &max) != 1) + /* avoid divison by 0 */ + max = 1; + + perc = 100 * now / max; + snprintf(buf, sizeof(buf), "%d%%", perc); + + return snprintf(b->curstr, LEN(b->curstr), b->fmt, buf); +} diff --git a/blocks/blight_linux.h b/blocks/blight_linux.h @@ -0,0 +1 @@ +size_t blight(struct Block *); diff --git a/config.def.h b/config.def.h @@ -1,4 +1,5 @@ #include "blocks/battery.h" +#include "blocks/blight_linux.h" #include "blocks/gettime.h" #include "blocks/mpd.h" #include "blocks/volume.h" @@ -24,6 +25,7 @@ struct Block blks[] = { { mpd_tag, "[ %s ", 0, 1, { .i = MPD_TAG_ARTIST } }, { mpd_tag, "- %s ]", 0, 1, { .i = MPD_TAG_TITLE } }, { batinfo, "[ %s ]", 30, 0, { .s = "BAT0" } }, + { blight, "[ %s ]", 0, 3, { .s = "intel_backlight" } }, { getvol, "[ %s ]", 0, 2, { .s = "Speaker" } }, { gettime, "[ %R ]", 20, 0, {0} }, { NULL }, diff --git a/config.mk b/config.mk @@ -1,5 +1,6 @@ SRC =\ blocks/battery.c\ + blocks/blight_linux.c\ blocks/gettime.c\ blocks/mpd.c\ blocks/volume.c