dotfiles

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

commit 0933ca9f7d365f93ff4968e3d1da692df038f106
parent 202e16587584cf0d57b99f986627286c19fad5dd
Author: tongong <tongong@gmx.net>
Date:   Mon, 19 Jul 2021 15:42:19 +0200

added backlight-control

Diffstat:
Msuckless/README.md | 3+++
Asuckless/backlight_control/LICENSE | 7+++++++
Asuckless/backlight_control/Makefile | 24++++++++++++++++++++++++
Asuckless/backlight_control/README.md | 37+++++++++++++++++++++++++++++++++++++
Asuckless/backlight_control/backlight_control.c | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 129 insertions(+), 0 deletions(-)

diff --git a/suckless/README.md b/suckless/README.md @@ -8,6 +8,9 @@ now extremely hard to pull upstream changes. I will probably switch to something like `git subtree` in the future. +## backlight-control +- from https://github.com/Hendrikto/backlight_control + ## clipmenu & clipnotify - not modified by me, but it's there nevertheless lol diff --git a/suckless/backlight_control/LICENSE b/suckless/backlight_control/LICENSE @@ -0,0 +1,7 @@ +Copyright ©2018 Hendrik Werner + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/suckless/backlight_control/Makefile b/suckless/backlight_control/Makefile @@ -0,0 +1,24 @@ +CC = gcc +CFLAGS += -Wall -Wextra -O3 -march=native + +prefix = /usr/local +backlight_dir = /sys/class/backlight +vendor_backlight_dir = $(backlight_dir)/$(shell ls $(backlight_dir) | head -n1) +max_brightness = $(shell cat $(vendor_backlight_dir)/max_brightness) + +DEFINES += -D BRIGHTNESS_FILE=\"$(vendor_backlight_dir)/brightness\" +DEFINES += -D MAX_BRIGHTNESS=$(max_brightness) + +all: backlight_control + +%: %.c + $(CC) $(CFLAGS) $(DEFINES) $< -o $@ + +clean: + rm -f backlight_control + +install: backlight_control + install -D -m 4755 -o root -g root $< $(DESTDIR)$(prefix)/bin/$< + +uninstall: + rm -f $(DESTDIR)$(prefix)/bin/backlight_control diff --git a/suckless/backlight_control/README.md b/suckless/backlight_control/README.md @@ -0,0 +1,37 @@ +# backlight_control +Control the backlight brightness. + +I had some problems with `xbacklight` in combination with the proprietary nvidia driver, so I wrote a replacement. + +## Build +```sh +make +``` + +## Install +```sh +sudo make install +``` + +## Uninstall +```sh +sudo make uninstall +``` + +## Usage +```sh +$ backlight_control +Usage: backlight_control [+|-]<value> + +Examples: + backlight_control +10 + backlight_control -10 + backlight_control 50 + +``` + +`backlight_control +n` increases brightness by n% + +`backlight_control -n` decreases brightness by n% + +`backlight_control n` sets the brightness to n% diff --git a/suckless/backlight_control/backlight_control.c b/suckless/backlight_control/backlight_control.c @@ -0,0 +1,58 @@ +#include <stdio.h> +#include <stdlib.h> + +/** + * A program to control the backlight brightness. + * + * @author: Hendrik Werner + */ + +#define MIN_BRIGHTNESS 1 + +#define MAX(a, b) ((a > b) ? a : b) +#define MIN(a, b) ((a < b) ? a : b) + +void print_usage(char *name) { + printf( + "Usage: %1$s [+|-]<value>\n" + "\n" + "Examples:\n" + "\t%1$s +10\n" + "\t%1$s -10\n" + "\t%1$s 50\n", + name + ); +} + +FILE *open_file(char *name) { + FILE *file; + if (!(file = fopen(name, "r+"))) { + fprintf(stderr, "failed to open %s\n", name); + exit(EXIT_FAILURE); + } + return file; +} + +int main(int argc, char **argv) { + if (argc != 2) { + print_usage(argv[0]); + return EXIT_FAILURE; + } + int value = strtol(argv[1], NULL, 10); + FILE *brightness = open_file(BRIGHTNESS_FILE); + int brightness_value = MIN_BRIGHTNESS; + switch (argv[1][0]) { + case '+': + case '-': + fscanf(brightness, "%d", &brightness_value); + brightness_value += MAX_BRIGHTNESS * value / 100; + break; + default: + brightness_value = MAX_BRIGHTNESS * value / 100; + } + brightness_value = MIN(brightness_value, MAX_BRIGHTNESS); + brightness_value = MAX(brightness_value, MIN_BRIGHTNESS); + fprintf(brightness, "%d", brightness_value); + fclose(brightness); + return EXIT_SUCCESS; +}