diff options
author | Stefano Karapetsas <[email protected]> | 2012-11-14 07:41:30 -0800 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2012-11-14 07:41:30 -0800 |
commit | abf46d226f006c5b6843ccac2010469ae838d68b (patch) | |
tree | 88bdba96755c2af731cbddbf8c5cd8825f39c270 /src/gpm-common.c | |
parent | fbf40ff748a675bdba451168c30aab7abeb5afa2 (diff) | |
parent | 1ea3233503f84366afd4e0a76e47afa258d17d04 (diff) | |
download | mate-power-manager-abf46d226f006c5b6843ccac2010469ae838d68b.tar.bz2 mate-power-manager-abf46d226f006c5b6843ccac2010469ae838d68b.tar.xz |
Merge pull request #25 from Firstyear/master
keyboard backlight, with basic controls.
Diffstat (limited to 'src/gpm-common.c')
-rw-r--r-- | src/gpm-common.c | 46 |
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 **/ |