diff options
author | Y.C cheng <yc.cheng@canonical.com> | 2014-03-06 11:27:12 +0800 |
---|---|---|
committer | Y.C cheng <yc.cheng@canonical.com> | 2014-03-06 11:27:12 +0800 |
commit | a67018fec5c2d6ffa54cff364c513223844559f3 (patch) | |
tree | 1ca6a0a5adfcec03bbaac9111610ef3d325a7104 /src/ib-brightness-powerd-control.c | |
parent | a046fce39f86760337af2666bd8a883e42dc4fcf (diff) | |
download | ayatana-indicator-power-a67018fec5c2d6ffa54cff364c513223844559f3.tar.gz ayatana-indicator-power-a67018fec5c2d6ffa54cff364c513223844559f3.tar.bz2 ayatana-indicator-power-a67018fec5c2d6ffa54cff364c513223844559f3.zip |
refine and use default value as initial brightness value
Diffstat (limited to 'src/ib-brightness-powerd-control.c')
-rw-r--r-- | src/ib-brightness-powerd-control.c | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/src/ib-brightness-powerd-control.c b/src/ib-brightness-powerd-control.c index 96afe7d..2136fcd 100644 --- a/src/ib-brightness-powerd-control.c +++ b/src/ib-brightness-powerd-control.c @@ -17,13 +17,6 @@ * Yuan-Chen Cheng <yc.cheng@canonical.com> */ -#include <gudev/gudev.h> - -#include <errno.h> -#include <stdlib.h> -#include <fcntl.h> -#include <string.h> - #include "ib-brightness-powerd-control.h" static gboolean getBrightnessParams(GDBusProxy* powerd_proxy, int *min, int *max, @@ -35,8 +28,7 @@ powerd_get_proxy(brightness_params_t *params) GError *error = NULL; gboolean ret; - if (params == NULL) - return NULL; + g_return_val_if_fail (params != NULL, NULL); GDBusProxy* powerd_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, @@ -79,9 +71,16 @@ getBrightnessParams(GDBusProxy* powerd_proxy, int *min, int *max, int *dflt, gbo NULL, G_DBUS_CALL_FLAGS_NONE, 400, NULL, &error); // timeout: 400 ms - if (!ret) { - g_warning("getBrightnessParams failed: %s", error->message); - g_error_free(error); + if (!ret) + { + if (error != NULL) + { + if (!g_error_matches(error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) + { + g_warning("getBrightnessParams from powerd failed: %s", error->message); + } + g_error_free(error); + } return FALSE; } @@ -101,7 +100,7 @@ static gboolean setUserBrightness(GDBusProxy* powerd_proxy, GCancellable *gcance G_DBUS_CALL_FLAGS_NONE, -1, gcancel, &error); if (!ret) { - g_warning("setUserBrightness failed: %s", error->message); + g_warning("setUserBrightness via powerd failed: %s", error->message); g_error_free(error); return FALSE; } else { @@ -117,7 +116,7 @@ struct _IbBrightnessPowerdControl int min; int max; - int dflt; + int dflt; // defalut value gboolean ab_supported; int current; @@ -137,7 +136,11 @@ ib_brightness_powerd_control_new (GDBusProxy* powerd_proxy, brightness_params_t control->dflt = params.dflt; control->ab_supported = params.ab_supported; - ib_brightness_powerd_control_set_value(control, control->max * 8 / 10); + // XXX: set the brightness value is the only way to sync the brightness value with + // powerd, and we should set the user prefered / last set brightness value upon startup. + // Before we have code to store last set brightness value or other mechanism, we set + // it to default brightness that powerd proposed. + ib_brightness_powerd_control_set_value(control, control->dflt); return control; } @@ -146,14 +149,8 @@ void ib_brightness_powerd_control_set_value (IbBrightnessPowerdControl* self, gint value) { gboolean ret; - if (value > self->max) - { - value = self->max; - } - else if (value < self->min) - { - value = self->min; - } + + value = CLAMP(value, self->min, self->max); ret = setUserBrightness(self->powerd_proxy, self->gcancel, value); if (ret) { |