diff -Naur a/src/gpm-brightness.c b/src/gpm-brightness.c --- a/src/gpm-brightness.c 2008-09-04 12:05:15.000000000 +0200 +++ b/src/gpm-brightness.c 2009-04-24 21:11:31.489612633 +0200 @@ -81,6 +81,34 @@ } /** + * gpm_brightness_get_guarded_up: + * @min: Minimum value (inclusive) + * @cur: Current value + * @max: Maximum value (inclusive) + * Return value: the minimum of (cur + step (min, max)) and max + **/ +guint +gpm_brightness_get_guarded_up (guint min, guint cur, guint max) +{ + guint step = (max - min) / GPM_BRIGHTNESS_DIM_LEVELS; + return cur + step > max ? max : cur + step; +} + +/** + * gpm_brightness_get_guarded_down: + * @min: Minimum value (inclusive) + * @cur: Current value + * @max: Maximum value (inclusive) + * Return value: the maximum of (cur - step (min, max)) and min + **/ +guint +gpm_brightness_get_guarded_down (guint min, guint cur, guint max) +{ + guint step = (max - min) / GPM_BRIGHTNESS_DIM_LEVELS; + return min + step > cur ? min : cur - step; +} + +/** * gpm_brightness_trust_cache: * @brightness: This brightness class instance * Return value: if we can trust the cache diff -Naur a/src/gpm-brightness.h b/src/gpm-brightness.h --- a/src/gpm-brightness.h 2008-09-04 12:05:15.000000000 +0200 +++ b/src/gpm-brightness.h 2009-04-24 21:11:40.432985322 +0200 @@ -34,6 +34,7 @@ #define GPM_BRIGHTNESS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPM_TYPE_BRIGHTNESS, GpmBrightnessClass)) #define GPM_BRIGHTNESS_DIM_INTERVAL 5 /* ms */ +#define GPM_BRIGHTNESS_DIM_LEVELS 12 typedef struct GpmBrightnessPrivate GpmBrightnessPrivate; @@ -66,6 +67,12 @@ /* not designed to be used outside of gpm-brightness-*.c */ guint gpm_brightness_get_step (guint levels); +guint gpm_brightness_get_guarded_up (guint min, + guint cur, + guint max); +guint gpm_brightness_get_guarded_down(guint min, + guint cur, + guint max); G_END_DECLS