module/alsa+backlight: round() percentage values

Closes #10
This commit is contained in:
Daniel Eklöf 2020-09-24 13:55:17 +02:00
parent 85ae4cca37
commit db53cf9245
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 7 additions and 4 deletions

View file

@ -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')

View file

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <alsa/asoundlib.h>
@ -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);

View file

@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <unistd.h>
#include <poll.h>
@ -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 *[]){

View file

@ -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]],