diff options
| author | Inqiyad Sabr <sabr@ariamath.xyz> | 2025-10-28 15:22:06 +0600 |
|---|---|---|
| committer | Inqiyad Sabr <sabr@ariamath.xyz> | 2025-10-28 15:22:06 +0600 |
| commit | 52aa2298a1b42c3da24e3bb39fee1ed894231c03 (patch) | |
| tree | afbb44c2cf419b37bc674a3973bb5fcada5bf1b5 | |
| parent | 0d4272c8bc1c8d7cca4178584f4f9ad42fcc1fd6 (diff) | |
Add screen brightness module
Though it's only for Unix likes... I really wanna support BSDs next time.
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | bstatus.c | 1 | ||||
| -rw-r--r-- | modules.h | 5 | ||||
| -rw-r--r-- | scrbr.c | 42 |
5 files changed, 53 insertions, 2 deletions
@@ -27,6 +27,6 @@ clean: $(RM) ./*.o install: - install -s -m0755 bstatus $(DESTDIR) + install -s -m 0755 bstatus $(DESTDIR) .PHONY: make clean install @@ -24,10 +24,13 @@ The modules aren't directly portable, I'd say to modify and port it than to comp - [x] datetime - [x] battery - [x] cpu -- [ ] memory +- [x] memory +- [x] brightness (screen) - [ ] volume - [ ] network +All work perfectly fine if you are using Linux. But I would love to write a bstatus seperately for the BSDs as well, instead of having them all in there to bloat the source code. + # Contribute Send a patch [to my email](mailto:sabr@ariamath.xyz) or [at xmpp](xmpp:sabr@ariamath.xyz). @@ -16,6 +16,7 @@ int main(void) datetime(); battery(); cpu(); + scrbr(); mem(); write(1,"],",2); sleep(1); @@ -18,6 +18,11 @@ void cpu(void); #define MEM_H void mem(void); #endif +// screen brightness +#ifndef SCRBR_H +#define SCRBR_H +void scrbr(void); +#endif // cmus #ifndef CMUS_H #define CMUS_H @@ -0,0 +1,42 @@ +#include <stdio.h> +#include <stdlib.h> +#include "block.h" +#define ICON_BR " " +#define FG "#222222" +#define BG "#dfb24999" +#define BDIR "/sys/class/backlight/amdgpu_bl1" +#define BMAXF max_brightness_f +#define BCURF current_brightness_f +FILE *BCURF, *BMAXF; +void scrbr(void) +{ + char *buf; + unsigned short current_brightness; + unsigned short max_brightness; + unsigned short size; + + if (!BCURF) BCURF = fopen(BDIR"/brightness","r"); + if (!BMAXF) BMAXF = fopen(BDIR"/max_brightness","r"); + + fseek(BCURF, 0, SEEK_END); + fseek(BMAXF, 0, SEEK_END); + + size = ftell(BCURF); + buf = malloc(size); + rewind(BCURF); + fgets(buf, size, BCURF); + current_brightness = atoi(buf); + free(buf); + + size = ftell(BMAXF); + buf = malloc(size); + rewind(BMAXF); + fgets(buf, size, BMAXF); + max_brightness = atoi(buf); + free(buf); + + char brightness[10]; + snprintf(brightness,10,ICON_BR"%3d%%", + current_brightness*100/max_brightness); + block(brightness,FG,BG,BG); +} |