summaryrefslogtreecommitdiff
path: root/src/gpm-common.c
diff options
context:
space:
mode:
authorWilliam Brown <[email protected]>2012-11-11 20:02:11 +1030
committerWilliam Brown <[email protected]>2012-11-11 20:02:11 +1030
commit9361bbfbb5f7fda96f147310125fc709f4da2200 (patch)
tree7b096d440129278db391c2611133caad51c43f39 /src/gpm-common.c
parentfbf40ff748a675bdba451168c30aab7abeb5afa2 (diff)
downloadmate-power-manager-9361bbfbb5f7fda96f147310125fc709f4da2200.tar.bz2
mate-power-manager-9361bbfbb5f7fda96f147310125fc709f4da2200.tar.xz
Keyboard backlight patches, tested as working against 1.5.0 on F18
Diffstat (limited to 'src/gpm-common.c')
-rw-r--r--src/gpm-common.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/gpm-common.c b/src/gpm-common.c
index 861837a..e7d1d66 100644
--- a/src/gpm-common.c
+++ b/src/gpm-common.c
@@ -79,6 +79,52 @@ gpm_get_timestring (guint time_secs)
}
/**
+ * gpm_discrete_from_percent:
+ * @percentage: The percentage to convert
+ * @levels: The number of discrete levels
+ *
+ * We have to be carefull when converting from %->discrete as precision is very
+ * important if we want the highest value.
+ *
+ * Return value: The discrete value for this percentage.
+ **/
+guint
+gpm_discrete_from_percent (guint percentage, guint levels)
+{
+ /* check we are in range */
+ if (percentage > 100)
+ return levels;
+ if (levels == 0) {
+ g_warning ("levels is 0!");
+ return 0;
+ }
+ return (guint) ((((gfloat) percentage * (gfloat) (levels - 1)) / 100.0f) + 0.5f);
+}
+
+/**
+ * gpm_discrete_to_percent:
+ * @hw: The discrete level
+ * @levels: The number of discrete levels
+ *
+ * We have to be carefull when converting from discrete->%.
+ *
+ * Return value: The percentage for this discrete value.
+ **/
+guint
+gpm_discrete_to_percent (guint discrete, guint levels)
+{
+ /* check we are in range */
+ if (discrete > levels)
+ return 100;
+ if (levels == 0) {
+ g_warning ("levels is 0!");
+ return 0;
+ }
+ return (guint) (((gfloat) discrete * (100.0f / (gfloat) (levels - 1))) + 0.5f);
+}
+
+
+/**
* gpm_help_display:
* @link_id: Subsection of mate-power-manager help section
**/