From db53cf924556ca1cb7e5ca1ad630b1daa6827817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 24 Sep 2020 13:55:17 +0200 Subject: [PATCH] module/alsa+backlight: round() percentage values Closes #10 --- meson.build | 1 + modules/alsa.c | 3 ++- modules/backlight.c | 3 ++- modules/meson.build | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index db6a7c2..2209469 100644 --- a/meson.build +++ b/meson.build @@ -42,6 +42,7 @@ endif # Common dependencies dl = cc.find_library('dl') +m = cc.find_library('m') threads = dependency('threads') pixman = dependency('pixman-1') yaml = dependency('yaml-0.1') diff --git a/modules/alsa.c b/modules/alsa.c index 6933fe5..9e410df 100644 --- a/modules/alsa.c +++ b/modules/alsa.c @@ -1,5 +1,6 @@ #include #include +#include #include @@ -44,7 +45,7 @@ content(struct module *mod) struct private *m = mod->private; int percent = m->vol_max - m->vol_min > 0 - ? 100 * m->vol_cur / (m->vol_max - m->vol_min) + ? round(100. * m->vol_cur / (m->vol_max - m->vol_min)) : 0; mtx_lock(&mod->lock); diff --git a/modules/backlight.c b/modules/backlight.c index 1c65d38..053a998 100644 --- a/modules/backlight.c +++ b/modules/backlight.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,7 @@ content(struct module *mod) const long current = m->current_brightness; const long max = m->max_brightness; - const long percent = max > 0 ? 100 * current / max : 0; + const long percent = max > 0 ? round(100. * current / max) : 0; struct tag_set tags = { .tags = (struct tag *[]){ diff --git a/modules/meson.build b/modules/meson.build index a42828e..3efcc9e 100644 --- a/modules/meson.build +++ b/modules/meson.build @@ -10,8 +10,8 @@ xcb_xkb = dependency('xcb-xkb', required: get_option('backend-x11')) # Module name -> (source-list, dep-list) deps = { - 'alsa': [[], [alsa]], - 'backlight': [[], [udev]], + 'alsa': [[], [m, alsa]], + 'backlight': [[], [m, udev]], 'battery': [[], [udev]], 'clock': [[], []], 'i3': [['i3-common.c', 'i3-common.h'], [dynlist, json]],