diff options
author | Mikhail Shevtsov <[email protected]> | 2015-07-28 03:35:05 +0300 |
---|---|---|
committer | Mikhail Shevtsov <[email protected]> | 2015-07-28 03:35:05 +0300 |
commit | 8352686d856b164432732668afed24f248c17323 (patch) | |
tree | a9373a2a0e4292ae35727ea8782050a504b5630e | |
parent | 56aea45e0a777c9c979dbc47b823e47a00ffb8ad (diff) | |
download | mate-power-manager-8352686d856b164432732668afed24f248c17323.tar.bz2 mate-power-manager-8352686d856b164432732668afed24f248c17323.tar.xz |
Unable to change keyboard back light #108
Fixed issue for laptops with levels less then 10;
-rw-r--r-- | src/gpm-common.c | 10 | ||||
-rw-r--r-- | src/gpm-kbd-backlight.c | 5 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/gpm-common.c b/src/gpm-common.c index f71aada..c0c3c94 100644 --- a/src/gpm-common.c +++ b/src/gpm-common.c @@ -91,6 +91,9 @@ gpm_get_timestring (guint time_secs) guint gpm_discrete_from_percent (guint percentage, guint levels) { + /* for levels < 10 min value is 0 */ + gint factor; + factor = levels < 10 ? 0 : 1; /* check we are in range */ if (percentage > 100) return levels; @@ -98,7 +101,7 @@ gpm_discrete_from_percent (guint percentage, guint levels) g_warning ("levels is 0!"); return 0; } - return (guint) ((((gfloat) percentage * (gfloat) (levels - 1)) / 100.0f) + 0.5f); + return (guint) ((((gfloat) percentage * (gfloat) (levels - factor)) / 100.0f) + 0.5f); } /** @@ -113,6 +116,9 @@ gpm_discrete_from_percent (guint percentage, guint levels) guint gpm_discrete_to_percent (guint discrete, guint levels) { + /* for levels < 10 min value is 0 */ + gint factor; + factor = levels < 10 ? 0 : 1; /* check we are in range */ if (discrete > levels) return 100; @@ -120,7 +126,7 @@ gpm_discrete_to_percent (guint discrete, guint levels) g_warning ("levels is 0!"); return 0; } - return (guint) (((gfloat) discrete * (100.0f / (gfloat) (levels - 1))) + 0.5f); + return (guint) (((gfloat) discrete * (100.0f / (gfloat) (levels - factor))) + 0.5f); } diff --git a/src/gpm-kbd-backlight.c b/src/gpm-kbd-backlight.c index b3091ac..4221004 100644 --- a/src/gpm-kbd-backlight.c +++ b/src/gpm-kbd-backlight.c @@ -121,6 +121,11 @@ gpm_kbd_backlight_set (GpmKbdBacklight *backlight, goal = gpm_discrete_from_percent (percentage, backlight->priv->max_brightness); scale = percentage > backlight->priv->brightness_percent ? 1 : -1; + /* if percentage change too small force next value */ + if (goal == backlight->priv->brightness) { + goal += percentage == backlight->priv->brightness_percent ? 0 : scale; + } + /* step loop down by 1 for a dimming effect */ while (backlight->priv->brightness != goal) { backlight->priv->brightness += scale; |