brightness.c (947B)
1 #include <stdio.h> 2 #include <string.h> 3 #include <time.h> 4 #include <unistd.h> 5 6 #include "../util.h" 7 #include "brightness.h" 8 9 #define ICON " " 10 #define OUTPUTLEN 5 11 12 size_t brightnessu(char *str, int sigval) 13 { 14 char output[OUTPUTLEN]; 15 char output_prefixed[OUTPUTLEN] = "000"; 16 17 getcmdout((char *[]){"backlight-control", "get", NULL}, output, OUTPUTLEN); 18 /* replace newline with \0 */ 19 for (int i = 0; i < OUTPUTLEN; i++) { 20 if (output[i] == '\n') { 21 output[i] = '\0'; 22 break; 23 } 24 } 25 26 /* prefix string with zeros */ 27 strcpy(output_prefixed + 3 - strlen(output), output); 28 29 30 return SPRINTF(str, ICON "%s%%", output_prefixed); 31 } 32 33 void brightnessc(int button) { 34 if (button == 1) { 35 execvp("backlight-control",(char *[]){"backlight-control", "-20", NULL}); 36 } 37 38 if (button == 3) { 39 execvp("backlight-control",(char *[]){"backlight-control", "+20", NULL}); 40 } 41 }