dotfiles

personal configuration files and scripts
git clone https://tongong.net/git/dotfiles.git
Log | Files | Refs | README

commit cd06c3807e9fd9d64a8c5dc54f4b4673b0622271
parent 7a3cd01aece6cc774751e8cc5e0cc24dbfa3c1c2
Author: tongong <tongong@gmx.net>
Date:   Mon, 19 Jul 2021 16:33:17 +0200

added backlight-control get option

Diffstat:
Msuckless/README.md | 2++
Msuckless/backlight-control/backlight-control.c | 21++++++++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/suckless/README.md b/suckless/README.md @@ -10,6 +10,8 @@ something like `git subtree` in the future. ## backlight-control - from https://github.com/Hendrikto/backlight_control +- renamed from `backlight_control` to `backlight-control` +- added `backlight-control get` command ## clipmenu & clipnotify - not modified by me, but it's there nevertheless lol diff --git a/suckless/backlight-control/backlight-control.c b/suckless/backlight-control/backlight-control.c @@ -1,10 +1,12 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> /** * A program to control the backlight brightness. * * @author: Hendrik Werner + * modified by tongong */ #define MIN_BRIGHTNESS 1 @@ -19,7 +21,8 @@ void print_usage(char *name) { "Examples:\n" "\t%1$s +10\n" "\t%1$s -10\n" - "\t%1$s 50\n", + "\t%1$s 50\n" + "\t%1$s get\n", name ); } @@ -33,11 +36,27 @@ FILE *open_file(char *name) { return file; } +unsigned int round_closest(unsigned int dividend, unsigned int divisor) +{ + return (dividend + (divisor / 2)) / divisor; +} + int main(int argc, char **argv) { if (argc != 2) { print_usage(argv[0]); return EXIT_FAILURE; } + + if (!strcmp(argv[1], "get")) { + int brightness_value; + FILE *brightness = open_file(BRIGHTNESS_FILE); + fscanf(brightness, "%d", &brightness_value); + fclose(brightness); + + printf("%d\n", round_closest(brightness_value * 100, MAX_BRIGHTNESS)); + return EXIT_SUCCESS; + } + int value = strtol(argv[1], NULL, 10); FILE *brightness = open_file(BRIGHTNESS_FILE); int brightness_value = MIN_BRIGHTNESS;