From 30c94ef6af70d34314bcebfd238363f519192bb5 Mon Sep 17 00:00:00 2001 From: Markus Schneider Date: Fri, 25 Aug 2017 16:47:08 +0200 Subject: Fix rounding errors when using percentages --- Makefile | 2 +- brightnessctl.c | 3 ++- 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 #include #include +#include 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; -- cgit v1.2.3