aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Markus Schneider <markus@icet-clan.de>2017-08-25 16:47:08 +0200
committerGravatar Hummer12007 <hilobakho@gmail.com>2017-08-26 04:21:06 +0300
commit30c94ef6af70d34314bcebfd238363f519192bb5 (patch)
treed52eaab170c37344285cbf1a29951987dfa8be11
parentd0200a1576c5f0bf2cf29eb83432570441478daa (diff)
Fix rounding errors when using percentages
-rw-r--r--Makefile2
-rw-r--r--brightnessctl.c3
2 files changed, 3 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 63cdcc4..b3986fb 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
VERSION = 0.2
DESTDIR ?= /usr/local
-CFLAGS += -std=c99 -g -Wall -Wextra -DVERSION=\"${VERSION}\" -D_POSIX_C_SOURCE=200809L
+CFLAGS += -std=c99 -g -Wall -Wextra -DVERSION=\"${VERSION}\" -D_POSIX_C_SOURCE=200809L -lm
MODE ?= 4711
all: brightnessctl
diff --git a/brightnessctl.c b/brightnessctl.c
index f169608..71321c4 100644
--- a/brightnessctl.c
+++ b/brightnessctl.c
@@ -10,6 +10,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
+#include <math.h>
static char *path = "/sys/class";
static char *classes[] = { "backlight", "leds", NULL };
@@ -292,7 +293,7 @@ int print_device(struct device *dev) {
void apply_value(struct device *d, struct value *val) {
long new, mod = val->v_type == ABSOLUTE ?
- val->val : val->val / 100.0 * d->max_brightness;
+ val->val : ceil(val->val / 100.0 * d->max_brightness);
if (val->d_type == DIRECT) {
new = mod > d->max_brightness ? d->max_brightness : mod;
goto apply;