aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ib-brightness-powerd-control.c57
-rw-r--r--src/ib-brightness-powerd-control.h12
-rw-r--r--src/service.c5
3 files changed, 43 insertions, 31 deletions
diff --git a/src/ib-brightness-powerd-control.c b/src/ib-brightness-powerd-control.c
index e7d4e0e..461bb54 100644
--- a/src/ib-brightness-powerd-control.c
+++ b/src/ib-brightness-powerd-control.c
@@ -26,10 +26,18 @@
#include "ib-brightness-powerd-control.h"
+static gboolean getBrightnessParams(GDBusProxy* powerd_proxy, int *min, int *max,
+ int *dflt, gboolean *ab_supported);
+
GDBusProxy*
-powerd_get_proxy(void)
+powerd_get_proxy(brightness_params_t *params)
{
GError *error = NULL;
+ gboolean ret;
+
+ if (params == NULL)
+ return NULL;
+
GDBusProxy* powerd_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
@@ -39,11 +47,23 @@ powerd_get_proxy(void)
NULL,
&error);
- if (error != NULL) {
+ if (error != NULL)
+ {
g_debug ("could not connect to powerd: %s", error->message);
g_error_free (error);
return NULL;
}
+
+ ret = getBrightnessParams(powerd_proxy, &(params->min), &(params->max),
+ &(params->dflt), &(params->ab_supported));
+
+ if (! ret)
+ {
+ g_debug ("can't get brightness parameters from powerd");
+ g_object_unref (powerd_proxy);
+ return NULL;
+ }
+
return powerd_proxy;
}
@@ -58,7 +78,7 @@ getBrightnessParams(GDBusProxy* powerd_proxy, int *min, int *max, int *dflt, gbo
"getBrightnessParams",
NULL,
G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
+ 400, NULL, &error); // timeout: 400 ms
if (!ret) {
g_warning("getBrightnessParams failed: %s", error->message);
g_error_free(error);
@@ -92,8 +112,6 @@ static gboolean setUserBrightness(GDBusProxy* powerd_proxy, int brightness)
struct _IbBrightnessPowerdControl
{
- gboolean inited;
-
GDBusProxy *powerd_proxy;
int min;
@@ -104,29 +122,20 @@ struct _IbBrightnessPowerdControl
int current;
};
-
-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;
-
- control->inited = TRUE;
-
- ib_brightness_powerd_control_set_value(control, control->max * 8 / 10);
-}
-
IbBrightnessPowerdControl*
-ib_brightness_powerd_control_new (GDBusProxy* powerd_proxy)
+ib_brightness_powerd_control_new (GDBusProxy* powerd_proxy, brightness_params_t params)
{
IbBrightnessPowerdControl *control;
control = g_new0 (IbBrightnessPowerdControl, 1);
- control->inited = FALSE;
control->powerd_proxy = powerd_proxy;
- ib_brightness_init(control);
+ control->min = params.min;
+ control->max = params.max;
+ control->dflt = params.dflt;
+ control->ab_supported = params.ab_supported;
+
+ ib_brightness_powerd_control_set_value(control, control->max * 8 / 10);
return control;
}
@@ -135,8 +144,6 @@ void
ib_brightness_powerd_control_set_value (IbBrightnessPowerdControl* self, gint value)
{
gboolean ret;
- if (! self->inited)
- return;
if (value > self->max)
{
value = self->max;
@@ -155,16 +162,12 @@ ib_brightness_powerd_control_set_value (IbBrightnessPowerdControl* self, gint va
gint
ib_brightness_powerd_control_get_value (IbBrightnessPowerdControl* self)
{
- if (! self->inited)
- return 0;
return self->current;
}
gint
ib_brightness_powerd_control_get_max_value (IbBrightnessPowerdControl* self)
{
- if (! self->inited)
- return 0;
return self->max;
}
diff --git a/src/ib-brightness-powerd-control.h b/src/ib-brightness-powerd-control.h
index 77e44cb..77f6c8d 100644
--- a/src/ib-brightness-powerd-control.h
+++ b/src/ib-brightness-powerd-control.h
@@ -21,11 +21,19 @@
#define __IB_BRIGHTNESS_POWERD_CONTROL_H__
#include <gio/gio.h>
-GDBusProxy* powerd_get_proxy();
+
+typedef struct {
+ int max;
+ int min;
+ int dflt;
+ gboolean ab_supported;
+} brightness_params_t;
+
+GDBusProxy* powerd_get_proxy(brightness_params_t *);
typedef struct _IbBrightnessPowerdControl IbBrightnessPowerdControl;
-IbBrightnessPowerdControl* ib_brightness_powerd_control_new (GDBusProxy* powerd_proxy);
+IbBrightnessPowerdControl* ib_brightness_powerd_control_new (GDBusProxy* powerd_proxy, brightness_params_t params);
void ib_brightness_powerd_control_set_value (IbBrightnessPowerdControl* self, gint value);
gint ib_brightness_powerd_control_get_value (IbBrightnessPowerdControl* self);
gint ib_brightness_powerd_control_get_max_value (IbBrightnessPowerdControl* self);
diff --git a/src/service.c b/src/service.c
index 959e316..9be5eca 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1044,6 +1044,7 @@ static void
indicator_power_service_init (IndicatorPowerService * self)
{
GDBusProxy *powerd_proxy = NULL;
+ brightness_params_t powerd_brigtness_params;
priv_t * p = G_TYPE_INSTANCE_GET_PRIVATE (self,
INDICATOR_TYPE_POWER_SERVICE,
IndicatorPowerServicePrivate);
@@ -1053,10 +1054,10 @@ indicator_power_service_init (IndicatorPowerService * self)
p->settings = g_settings_new ("com.canonical.indicator.power");
- powerd_proxy = powerd_get_proxy();
+ powerd_proxy = powerd_get_proxy(&powerd_brigtness_params);
if (powerd_proxy != NULL)
{
- p->brightness_powerd_control = ib_brightness_powerd_control_new(powerd_proxy);
+ p->brightness_powerd_control = ib_brightness_powerd_control_new(powerd_proxy, powerd_brigtness_params);
}
else
{