From 4be4ac3e289fe4c555877841fa76d7b514625e1f Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 27 Feb 2022 10:05:38 +0100 Subject: ddcutil support --- brightness.c | 76 ------------------------------------------------------------ 1 file changed, 76 deletions(-) delete mode 100644 brightness.c (limited to 'brightness.c') diff --git a/brightness.c b/brightness.c deleted file mode 100644 index feee058..0000000 --- a/brightness.c +++ /dev/null @@ -1,76 +0,0 @@ -// By Tom Smeding (2016) -// modified for new laptop (2017) - -#include -#include -#include -#include -#include -#include - -#define INCREMENT 100 - -__attribute__((noreturn)) -__attribute__((format (printf, 1, 2))) -void die(const char *format,...){ - va_list ap; - va_start(ap,format); - vprintf(format,ap); - va_end(ap); - putchar('\n'); - exit(1); -} - -int get_max_brightness(void){ - FILE *f=fopen("/sys/class/backlight/intel_backlight/max_brightness","r"); - if(!f)die("Could not open max_brightness file"); - int n; - fscanf(f,"%d",&n); - fclose(f); - return n; -} - -int get_brightness(void){ - FILE *f=fopen("/sys/class/backlight/intel_backlight/brightness","r"); - if(!f)die("Could not open brightness file"); - int n; - fscanf(f,"%d",&n); - fclose(f); - return n; -} - -void set_brightness(int n){ - FILE *f=fopen("/sys/class/backlight/intel_backlight/brightness","w"); - if(!f)die("Could not open brightness file"); - fprintf(f,"%d",n); - fflush(f); - fclose(f); -} - -int main(int argc,char **argv){ - uid_t uid=geteuid(); - if(uid!=0){ - printf("brightness will only work with root.\n"); - return 1; - } - - if(argc==1){ - printf("max: %d\n",get_max_brightness()); - printf("current: %d\n",get_brightness()); - } else if(argc==2){ - int n; - if(strcmp(argv[1],"-")==0){ - n=get_brightness()-INCREMENT; - if(n<0)n=0; - } else if(strcmp(argv[1],"+")==0){ - n=get_brightness()+INCREMENT; - int mx=get_max_brightness(); - if(n>mx)n=mx; - } else { - char *endp; - n=strtol(argv[1],&endp,10); - if(argv[1][0]=='\0'||*endp!='\0')die("Invalid number '%s'",argv[1]); - } - set_brightness(n); - } -} -- cgit v1.2.3-70-g09d2