dotfiles

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

commit f85e066cddf0285e0eefc0d33f620d255497af04
parent cd06c3807e9fd9d64a8c5dc54f4b4673b0622271
Author: tongong <tongong@gmx.net>
Date:   Tue, 20 Jul 2021 14:41:53 +0200

integrated brightness control with dsblocks

Diffstat:
Msuckless/backlight-control/backlight-control.c | 6++++++
Asuckless/dsblocks/blocks/brightness.c | 41+++++++++++++++++++++++++++++++++++++++++
Asuckless/dsblocks/blocks/brightness.h | 2++
Msuckless/dsblocks/config.h | 2++
4 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/suckless/backlight-control/backlight-control.c b/suckless/backlight-control/backlight-control.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> /** * A program to control the backlight brightness. @@ -11,6 +12,9 @@ #define MIN_BRIGHTNESS 1 +/* is run after brightness change to update statusbar etc. */ +char *notify_cmd[]={"sigdsblocks", "9", NULL}; + #define MAX(a, b) ((a > b) ? a : b) #define MIN(a, b) ((a < b) ? a : b) @@ -73,5 +77,7 @@ int main(int argc, char **argv) { brightness_value = MAX(brightness_value, MIN_BRIGHTNESS); fprintf(brightness, "%d", brightness_value); fclose(brightness); + + execvp(notify_cmd[0],notify_cmd); return EXIT_SUCCESS; } diff --git a/suckless/dsblocks/blocks/brightness.c b/suckless/dsblocks/blocks/brightness.c @@ -0,0 +1,41 @@ +#include <stdio.h> +#include <string.h> +#include <time.h> +#include <unistd.h> + +#include "../util.h" +#include "brightness.h" + +#define ICON " " +#define OUTPUTLEN 5 + +size_t brightnessu(char *str, int sigval) +{ + char output[OUTPUTLEN]; + char output_prefixed[OUTPUTLEN] = "000"; + + getcmdout((char *[]){"backlight-control", "get", NULL}, output, OUTPUTLEN); + /* replace newline with \0 */ + for (int i = 0; i < OUTPUTLEN; i++) { + if (output[i] == '\n') { + output[i] = '\0'; + break; + } + } + + /* prefix string with zeros */ + strcpy(output_prefixed + 3 - strlen(output), output); + + + return SPRINTF(str, ICON "%s%%", output_prefixed); +} + +void brightnessc(int button) { + if (button == 1) { + execvp("backlight-control",(char *[]){"backlight-control", "-20", NULL}); + } + + if (button == 3) { + execvp("backlight-control",(char *[]){"backlight-control", "+20", NULL}); + } +} diff --git a/suckless/dsblocks/blocks/brightness.h b/suckless/dsblocks/blocks/brightness.h @@ -0,0 +1,2 @@ +size_t brightnessu(char *str, int sigval); +void brightnessc(int button); diff --git a/suckless/dsblocks/config.h b/suckless/dsblocks/config.h @@ -1,4 +1,5 @@ #include "blocks/battery.h" +#include "blocks/brightness.h" #include "blocks/calendar.h" #include "blocks/cpu.h" #include "blocks/mem.h" @@ -48,6 +49,7 @@ static Block blocks[] = { { tempu, tempc, 2, 6}, { memu, memc, 2, 4}, { cpuu, cpuc, 2, 3}, + { brightnessu, brightnessc, 600, 9}, { volumeu, volumec, 600, 5}, { batteryu, batteryc, 2, 8}, { calendaru, calendarc, 600, 2},