aboutsummaryrefslogtreecommitdiff
path: root/src/service.c
diff options
context:
space:
mode:
authorY.C cheng <yc.cheng@canonical.com>2014-03-26 18:50:37 +0000
committerCI bot <ps-jenkins@lists.canonical.com>2014-03-26 18:50:37 +0000
commitebf3030f140c1a47a3e7e579a759d2dd04c9c862 (patch)
treec3a8b3f3a4561ea3c8af7308dc6c8f460784794b /src/service.c
parent6b9e3d4fb5e11d5d09bc376aa2a56db6a02b55ee (diff)
parent20aa7e18cac91520469a3cd3fb431e6d44a6622d (diff)
downloadayatana-indicator-power-ebf3030f140c1a47a3e7e579a759d2dd04c9c862.tar.gz
ayatana-indicator-power-ebf3030f140c1a47a3e7e579a759d2dd04c9c862.tar.bz2
ayatana-indicator-power-ebf3030f140c1a47a3e7e579a759d2dd04c9c862.zip
Set brightness via powerd if it exist (using dbus) Fixes: 1287599
Diffstat (limited to 'src/service.c')
-rw-r--r--src/service.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/src/service.c b/src/service.c
index 1d8ba3e..d3e143e 100644
--- a/src/service.c
+++ b/src/service.c
@@ -27,6 +27,7 @@
#include "device.h"
#include "device-provider.h"
#include "ib-brightness-control.h"
+#include "ib-brightness-powerd-control.h"
#include "service.h"
#define BUS_NAME "com.canonical.indicator.power"
@@ -104,6 +105,7 @@ struct _IndicatorPowerServicePrivate
GSettings * settings;
IbBrightnessControl * brightness_control;
+ IbBrightnessPowerdControl * brightness_powerd_control;
guint own_id;
guint actions_export_id;
@@ -457,7 +459,16 @@ create_phone_devices_section (IndicatorPowerService * self G_GNUC_UNUSED)
static void
get_brightness_range (IndicatorPowerService * self, gint * low, gint * high)
{
- const int max = ib_brightness_control_get_max_value (self->priv->brightness_control);
+ priv_t * p = self->priv;
+ int max = 0;
+ if (p->brightness_control)
+ {
+ max = ib_brightness_control_get_max_value (self->priv->brightness_control);
+ }
+ else if (p->brightness_powerd_control)
+ {
+ max = ib_brightness_powerd_control_get_max_value (self->priv->brightness_powerd_control);
+ }
*low = max * 0.05; /* 5% minimum -- don't let the screen go completely dark */
*high = max;
}
@@ -500,7 +511,15 @@ static GVariant *
action_state_for_brightness (IndicatorPowerService * self)
{
priv_t * p = self->priv;
- const gint brightness = ib_brightness_control_get_value (p->brightness_control);
+ gint brightness = 0;
+ if (p->brightness_control)
+ {
+ brightness = ib_brightness_control_get_value (p->brightness_control);
+ }
+ else if (p->brightness_powerd_control)
+ {
+ brightness = ib_brightness_powerd_control_get_value (p->brightness_powerd_control);
+ }
return g_variant_new_double (brightness_to_percentage (self, brightness));
}
@@ -519,7 +538,16 @@ on_brightness_change_requested (GSimpleAction * action G_GNUC_UNUSED,
IndicatorPowerService * self = INDICATOR_POWER_SERVICE (gself);
const gdouble percentage = g_variant_get_double (parameter);
const int brightness = percentage_to_brightness (self, percentage);
- ib_brightness_control_set_value (self->priv->brightness_control, brightness);
+
+ if (self->priv->brightness_control)
+ {
+ ib_brightness_control_set_value (self->priv->brightness_control, brightness);
+ }
+ else if (self->priv->brightness_powerd_control)
+ {
+ ib_brightness_powerd_control_set_value (self->priv->brightness_powerd_control, brightness);
+ }
+
update_brightness_action_state (self);
}
@@ -1016,7 +1044,9 @@ my_dispose (GObject * o)
g_clear_object (&p->conn);
+ // g_clear_pointer has NULL check inside.
g_clear_pointer (&p->brightness_control, ib_brightness_control_free);
+ g_clear_pointer (&p->brightness_powerd_control, ib_brightness_powerd_control_free);
indicator_power_service_set_device_provider (self, NULL);
@@ -1030,6 +1060,8 @@ my_dispose (GObject * o)
static void
indicator_power_service_init (IndicatorPowerService * self)
{
+ GDBusProxy *powerd_proxy;
+ brightness_params_t powerd_brightness_params;
priv_t * p = G_TYPE_INSTANCE_GET_PRIVATE (self,
INDICATOR_TYPE_POWER_SERVICE,
IndicatorPowerServicePrivate);
@@ -1039,7 +1071,15 @@ indicator_power_service_init (IndicatorPowerService * self)
p->settings = g_settings_new ("com.canonical.indicator.power");
- p->brightness_control = ib_brightness_control_new ();
+ powerd_proxy = powerd_get_proxy(&powerd_brightness_params);
+ if (powerd_proxy != NULL)
+ {
+ p->brightness_powerd_control = ib_brightness_powerd_control_new(powerd_proxy, powerd_brightness_params);
+ }
+ else
+ {
+ p->brightness_control = ib_brightness_control_new ();
+ }
init_gactions (self);