From 6a577e1b2d6941af7eef77a7a6a8c4c064dcbcf4 Mon Sep 17 00:00:00 2001 From: "Y.C cheng" Date: Wed, 5 Mar 2014 13:32:26 +0800 Subject: clean up / wrong code fix --- src/ib-brightness-powerd-control.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/ib-brightness-powerd-control.c') diff --git a/src/ib-brightness-powerd-control.c b/src/ib-brightness-powerd-control.c index 3395bda..e7d4e0e 100644 --- a/src/ib-brightness-powerd-control.c +++ b/src/ib-brightness-powerd-control.c @@ -40,8 +40,8 @@ powerd_get_proxy(void) &error); if (error != NULL) { - g_error_free (error); g_debug ("could not connect to powerd: %s", error->message); + g_error_free (error); return NULL; } return powerd_proxy; @@ -109,11 +109,12 @@ static void ib_brightness_init(IbBrightnessPowerdControl *control) { gboolean ret = getBrightnessParams(control->powerd_proxy, &(control->min), &(control->max), &(control->dflt), &(control->ab_supported)); - if (! ret) return; - - ib_brightness_powerd_control_set_value(control, control->max); + if (! ret) + return; control->inited = TRUE; + + ib_brightness_powerd_control_set_value(control, control->max * 8 / 10); } IbBrightnessPowerdControl* @@ -134,8 +135,16 @@ void ib_brightness_powerd_control_set_value (IbBrightnessPowerdControl* self, gint value) { gboolean ret; - if (! self->inited) return; - if (value > self->max || value < self->min) return; + if (! self->inited) + return; + if (value > self->max) + { + value = self->max; + } + else if (value < self->min) + { + value = self->min; + } ret = setUserBrightness(self->powerd_proxy, value); if (ret) { @@ -146,14 +155,16 @@ ib_brightness_powerd_control_set_value (IbBrightnessPowerdControl* self, gint va gint ib_brightness_powerd_control_get_value (IbBrightnessPowerdControl* self) { - if (! self->inited) return 0; + if (! self->inited) + return 0; return self->current; } gint ib_brightness_powerd_control_get_max_value (IbBrightnessPowerdControl* self) { - if (! self->inited) return 0; + if (! self->inited) + return 0; return self->max; } -- cgit v1.2.3