From 35ac14a0ea7cbaef00ce09e66196ee30d7f58940 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Sat, 19 Oct 2024 11:22:25 +0200 Subject: [PATCH] fixed indentation issues --- .editorconfig | 13 +++++++++++++ .gitignore | 1 + ambientd.c | 29 ++++++++++++++--------------- 3 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..cd6cc7b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +[*.{c,cpp,cxx,h,hh}] +indent_style = tab +indent_size = 8 +trim_trailing_whitespace = true + +[Makefile] +indent_style = tab +indent_size = 8 +trim_trailing_whitespace = true + +[*.py] +indent_style = space +indent_size = 4 diff --git a/.gitignore b/.gitignore index 24bee75..88e943d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ ambientd +.ccls-cache diff --git a/ambientd.c b/ambientd.c index 740e47b..c350a41 100644 --- a/ambientd.c +++ b/ambientd.c @@ -40,7 +40,7 @@ int get_luminance_raw (void) } // read a string from a file and convert it to int, should only be used for -// positive numbers since negative numbers mean an error +// positive numbers since negative numbers mean an error int read_int(FILE *fp) { freopen(NULL, "r", fp); @@ -52,7 +52,7 @@ int read_int(FILE *fp) if (r == LONG_MIN || r == LONG_MAX) { return -1; } - return r; + return r; } // TODO: add some command line options like: @@ -128,17 +128,17 @@ int main (void) brightness_old = brightness_target; brightness_target = MAX((int)(luminance_percent * max_brightness), min_brightness); brightness_delta = ABS((float)(brightness_target - brightness_old)/brightness_old); - + // if the brightness changes by more than 10% reduce the user offset, scaling - // with the delta, this accounts for large changes in brightness no longer - // corresponding to the adjustments that the user made to the brightness - if (brightness_delta > 0.1) { - user_offset = user_offset * MAX(MIN(1-(brightness_delta*1.2), 1), 0); + // with the delta, this accounts for large changes in brightness no longer + // corresponding to the adjustments that the user made to the brightness + if (brightness_delta > 0.1) { + user_offset = user_offset * MAX(MIN(1-(brightness_delta*1.2), 1), 0); } - brightness_adjusted = MIN(MAX(brightness_target + user_offset, min_brightness), max_brightness); + brightness_adjusted = MIN(MAX(brightness_target + user_offset, min_brightness), max_brightness); // TODO: put this in write_int() function - x = snprintf(STR_BUFFER, sizeof(STR_BUFFER), "%d", brightness_adjusted); + x = snprintf(STR_BUFFER, sizeof(STR_BUFFER), "%d", brightness_adjusted); if (x <= 0) { fprintf(stderr, "Error in snprintf(): %s\n", strerror(errno)); } @@ -159,14 +159,13 @@ int main (void) } off = actual_brightness - brightness_target; - if (brightness_target != max_brightness || off < 0){ - user_offset = off; - } + if (brightness_target != max_brightness || off < 0){ + user_offset = off; + } // TODO: option to turn off logging - printf("brightness target: %d; user offset: %d; brightness adjusted: %d\n", brightness_target, user_offset, brightness_adjusted); - + printf("brightness target: %d; user offset: %d; brightness adjusted: %d\n", brightness_target, user_offset, brightness_adjusted); } - + return 0; }