[gnome-settings-daemon] power: Make PERCENTAGE_TO_ABS round to the nearest value
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] power: Make PERCENTAGE_TO_ABS round to the nearest value
- Date: Mon, 30 Jan 2017 11:21:03 +0000 (UTC)
commit 74693ebe39e14081e258f8603605706cde6da941
Author: Hans de Goede <hdegoede redhat com>
Date: Thu Jan 26 08:27:59 2017 +0100
power: Make PERCENTAGE_TO_ABS round to the nearest value
When a (keyboard) backlight has few steps then PERCENTAGE_TO_ABS would
show a clear preference for lower values. E.g. with keyboard backlights
there are typically only 2 steps and PERCENTAGE_TO_ABS would require
the user to click or drag the slider in the control-panel power pane
all the way to the right to get to the maximum setting of 2.
This fixes this by adding rounding, so that now if the user drags
the slider past 75% he gets the maximum setting.
https://bugzilla.gnome.org/show_bug.cgi?id=773402
plugins/power/gpm-common.c | 19 +++++++++++++++++++
plugins/power/gpm-common.h | 3 ++-
2 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/plugins/power/gpm-common.c b/plugins/power/gpm-common.c
index 7ccf0be..97b104a 100644
--- a/plugins/power/gpm-common.c
+++ b/plugins/power/gpm-common.c
@@ -61,6 +61,25 @@ gsd_power_backlight_abs_to_percentage (int min, int max, int value)
return (((value - min) * 100) / (max - min));
}
+/* take a percentage and convert to a discrete value with offset */
+int
+gsd_power_backlight_percentage_to_abs (int min, int max, int value)
+{
+ int steps, step_size;
+
+ g_return_val_if_fail (max > min, -1);
+ g_return_val_if_fail (value >= 0, -1);
+ g_return_val_if_fail (value <= 100, -1);
+
+ steps = max - min;
+ step_size = 100 / steps;
+
+ /* Round for better precision when steps is small */
+ value += step_size / 2;
+
+ return min + (steps * value) / 100;
+}
+
#define GPM_UP_TIME_PRECISION 5*60
#define GPM_UP_TEXT_MIN_TIME 120
diff --git a/plugins/power/gpm-common.h b/plugins/power/gpm-common.h
index 381e7dd..251cd31 100644
--- a/plugins/power/gpm-common.h
+++ b/plugins/power/gpm-common.h
@@ -42,9 +42,10 @@ void reset_idletime (void);
#define BRIGHTNESS_STEP_AMOUNT(max) ((max) < 20 ? 1 : (max) / 20)
#define ABS_TO_PERCENTAGE(min, max, value) gsd_power_backlight_abs_to_percentage(min, max, value)
-#define PERCENTAGE_TO_ABS(min, max, value) (min + (((max - min) * value) / 100))
+#define PERCENTAGE_TO_ABS(min, max, value) gsd_power_backlight_percentage_to_abs(min, max, value)
int gsd_power_backlight_abs_to_percentage (int min, int max, int value);
+int gsd_power_backlight_percentage_to_abs (int min, int max, int value);
gboolean backlight_available (GnomeRRScreen *rr_screen);
int backlight_get_output_id (GnomeRRScreen *rr_screen);
int backlight_get_abs (GnomeRRScreen *rr_screen, GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]