Add buffer to header file, print new brightness on command and add install target to makefile

This commit is contained in:
Ethanell 2019-12-19 11:56:37 +01:00
parent c72ac6ec5f
commit 40b3de27aa
3 changed files with 16 additions and 8 deletions

View file

@ -7,6 +7,10 @@ OBJ=$(SRC:.c=.o)
HEADER=xbrightness.h HEADER=xbrightness.h
install: all
cp $(NAME) /usr/local/bin/
@make clean
all: $(NAME) all: $(NAME)
$(NAME): $(OBJ) $(HEADER) $(NAME): $(OBJ) $(HEADER)

View file

@ -13,23 +13,23 @@ void cmd(char *command, char *output) {
} }
float current() { float current() {
char out[1028]; char out[BUFFER];
cmd("xrandr --verbose | grep Brightness: | cut -f2 -d\" \"", out); cmd("xrandr --verbose | grep Brightness: | cut -f2 -d\" \"", out); //TODO: Check when 0 screen connected and two or more connected and catch output error
return strtof(out, NULL); return strtof(out, NULL); //TODO: Return NULL when convert fail
} }
void set(float brightness) { void set(float brightness) {
char screen[1028]; char screen[BUFFER]; //TODO: Better buffer
char command[1028] = "xrandr --output "; char command[BUFFER] = "xrandr --output ";
char command2[] = " --brightness "; char command2[] = " --brightness ";
char b[3]; char b[3];
cmd("xrandr | grep \" connected\" | cut -f1 -d\" \"", screen); cmd("xrandr | grep \" connected\" | cut -f1 -d\" \"", screen); //TODO: Check when 0 screen connected and two or more connected and catch output error
screen[strlen(screen)-1] = 0; screen[strlen(screen)-1] = 0;
strcat(command, screen); strcat(command, screen);
strcat(command, command2); strcat(command, command2);
gcvt(brightness, 3, b); gcvt(brightness, 3, b);
strcat(command, b); strcat(command, b);
cmd(command, NULL); cmd(command, NULL); //TODO: Catch output error
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -48,10 +48,12 @@ int main(int argc, char **argv) {
return 1; return 1;
} else { } else {
if (argv[1][0] == '+' ||argv[1][0] == '-') { if (argv[1][0] == '+' ||argv[1][0] == '-') {
set(current()+b); b = current()+b;
set(b);
} else { } else {
set(b); set(b);
} }
printf("Brightness set to %.2f\n", b);
} }
return 0; return 0;
} }

View file

@ -1,6 +1,8 @@
#ifndef XBRIGHTNESS_H #ifndef XBRIGHTNESS_H
#define XBRIGHTNESS_H #define XBRIGHTNESS_H
#define BUFFER 1028
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>