[gnome-settings-daemon/benzea/fix-brightness-rounding] power: Fix rounding of brightness value



commit 35ed3aa8d8d18ad6f088f2855a37e47ed5e50e8f
Author: Benjamin Berg <bberg redhat com>
Date:   Fri Aug 23 15:23:44 2019 +0200

    power: Fix rounding of brightness value
    
    We rounded properly for percentage to absolute value, but we always
    floored the other way around. Also round when converting the absolute
    value to percentage, this should prevent issues where the percentage
    changes becaues the calculated absolute value will be resolved to a
    different percentage than it was calculated from.

 plugins/power/gpm-common.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/plugins/power/gpm-common.c b/plugins/power/gpm-common.c
index 0934a205..c2e521f5 100644
--- a/plugins/power/gpm-common.c
+++ b/plugins/power/gpm-common.c
@@ -47,10 +47,15 @@
 int
 gsd_power_backlight_abs_to_percentage (int min, int max, int value)
 {
+        int steps;
+
         g_return_val_if_fail (max > min, -1);
         g_return_val_if_fail (value >= min, -1);
         g_return_val_if_fail (value <= max, -1);
-        return (((value - min) * 100) / (max - min));
+
+        steps = max - min;
+
+        return (((value - min) * 100 + steps / 2) / steps);
 }
 
 /* take a percentage and convert to a discrete value with offset */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]