diff options
author | Alberto Aguirre <alberto.aguirre@canonical.com> | 2014-06-24 09:45:34 +0000 |
---|---|---|
committer | CI bot <ps-jenkins@lists.canonical.com> | 2014-06-24 09:45:34 +0000 |
commit | 049c09d4dbd3ff042c53b47a619388681a2fb2d6 (patch) | |
tree | 3295fed227c1a06fc5c1d7fe377f0f69bccecf86 | |
parent | 3982a33ab5d059f3a99f2ccde87270fd2a73d798 (diff) | |
parent | 0e5ceb9fafbbc06d3ecd066ad013dee69cd16af7 (diff) | |
download | ayatana-indicator-power-049c09d4dbd3ff042c53b47a619388681a2fb2d6.tar.gz ayatana-indicator-power-049c09d4dbd3ff042c53b47a619388681a2fb2d6.tar.bz2 ayatana-indicator-power-049c09d4dbd3ff042c53b47a619388681a2fb2d6.zip |
Changes to address setBrightness interface moving from powerd to unity-system-compositor
-rw-r--r-- | debian/control | 2 | ||||
-rw-r--r-- | m4/gcov.m4 | 2 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/ib-brightness-uscreen-control.c (renamed from src/ib-brightness-powerd-control.c) | 63 | ||||
-rw-r--r-- | src/ib-brightness-uscreen-control.h (renamed from src/ib-brightness-powerd-control.h) | 18 | ||||
-rw-r--r-- | src/service.c | 28 |
6 files changed, 69 insertions, 48 deletions
diff --git a/debian/control b/debian/control index 28ab3fd..f8e88b8 100644 --- a/debian/control +++ b/debian/control @@ -24,6 +24,8 @@ Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, upower, + powerd, + unity-system-compositor (>= 0.0.4), Recommends: unity-control-center | gnome-control-center (>= 3.1) | ubuntu-system-settings | xfce4-power-manager, indicator-applet (>= 0.2) | indicator-renderer, Description: Indicator showing power state. @@ -30,7 +30,7 @@ AC_DEFUN([AC_TDD_GCOV], AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.]) fi - lcov_version_list="1.6 1.7 1.8 1.9 1.10" + lcov_version_list="1.6 1.7 1.8 1.9 1.10 1.11" AC_CHECK_PROG(LCOV, lcov, lcov) AC_CHECK_PROG(GENHTML, genhtml, genhtml) diff --git a/src/Makefile.am b/src/Makefile.am index 2461592..3f71b60 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -46,8 +46,8 @@ libindciatorpower_upower_a_LDFLAGS = $(COVERAGE_LDFLAGS) libindicatorpower_service_a_SOURCES = \ ib-brightness-control.c \ ib-brightness-control.h \ - ib-brightness-powerd-control.c \ - ib-brightness-powerd-control.h \ + ib-brightness-uscreen-control.c \ + ib-brightness-uscreen-control.h \ device-provider.c \ device-provider.h \ device.c \ diff --git a/src/ib-brightness-powerd-control.c b/src/ib-brightness-uscreen-control.c index 9e8815b..ad2c155 100644 --- a/src/ib-brightness-powerd-control.c +++ b/src/ib-brightness-uscreen-control.c @@ -17,19 +17,20 @@ * Yuan-Chen Cheng <yc.cheng@canonical.com> */ -#include "ib-brightness-powerd-control.h" +#include "ib-brightness-uscreen-control.h" static gboolean getBrightnessParams(GDBusProxy* powerd_proxy, int *dim, int *min, int *max, int *dflt, gboolean *ab_supported); GDBusProxy* -powerd_get_proxy(brightness_params_t *params) +uscreen_get_proxy(brightness_params_t *params) { GError *error = NULL; gboolean ret; g_return_val_if_fail (params != NULL, NULL); + /* For now we still need to obtain the brigthness params from powerd */ GDBusProxy* powerd_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, @@ -55,8 +56,26 @@ powerd_get_proxy(brightness_params_t *params) g_object_unref (powerd_proxy); return NULL; } - - return powerd_proxy; + + g_clear_object (&powerd_proxy); + + GDBusProxy* uscreen_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "com.canonical.Unity.Screen", + "/com/canonical/Unity/Screen", + "com.canonical.Unity.Screen", + NULL, + &error); + + if (error != NULL) + { + g_debug ("could not connect to unity screen: %s", error->message); + g_error_free (error); + return NULL; + } + + return uscreen_proxy; } @@ -89,18 +108,18 @@ getBrightnessParams(GDBusProxy* powerd_proxy, int *dim, int *min, int *max, int return TRUE; } -static gboolean setUserBrightness(GDBusProxy* powerd_proxy, GCancellable *gcancel, int brightness) +static gboolean setUserBrightness(GDBusProxy* uscreen_proxy, GCancellable *gcancel, int brightness) { GVariant *ret = NULL; GError *error = NULL; - ret = g_dbus_proxy_call_sync(powerd_proxy, + ret = g_dbus_proxy_call_sync(uscreen_proxy, "setUserBrightness", g_variant_new("(i)", brightness), G_DBUS_CALL_FLAGS_NONE, -1, gcancel, &error); if (!ret) { - g_warning("setUserBrightness via powerd failed: %s", error->message); + g_warning("setUserBrightness via unity.screen failed: %s", error->message); g_error_free(error); return FALSE; } else { @@ -109,9 +128,9 @@ static gboolean setUserBrightness(GDBusProxy* powerd_proxy, GCancellable *gcance } } -struct _IbBrightnessPowerdControl +struct _IbBrightnessUScreenControl { - GDBusProxy *powerd_proxy; + GDBusProxy *uscreen_proxy; GCancellable *gcancel; int dim; @@ -123,13 +142,13 @@ struct _IbBrightnessPowerdControl int current; }; -IbBrightnessPowerdControl* -ib_brightness_powerd_control_new (GDBusProxy* powerd_proxy, brightness_params_t params) +IbBrightnessUscreenControl* +ib_brightness_uscreen_control_new (GDBusProxy* uscreen_proxy, brightness_params_t params) { - IbBrightnessPowerdControl *control; + IbBrightnessUscreenControl *control; - control = g_new0 (IbBrightnessPowerdControl, 1); - control->powerd_proxy = powerd_proxy; + control = g_new0 (IbBrightnessUscreenControl, 1); + control->uscreen_proxy = uscreen_proxy; control->gcancel = g_cancellable_new(); control->dim = params.dim; @@ -139,21 +158,21 @@ ib_brightness_powerd_control_new (GDBusProxy* powerd_proxy, brightness_params_t control->ab_supported = params.ab_supported; // 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. + // unity.screen, 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); + ib_brightness_uscreen_control_set_value(control, control->dflt); return control; } void -ib_brightness_powerd_control_set_value (IbBrightnessPowerdControl* self, gint value) +ib_brightness_uscreen_control_set_value (IbBrightnessUscreenControl* self, gint value) { gboolean ret; value = CLAMP(value, self->min, self->max); - ret = setUserBrightness(self->powerd_proxy, self->gcancel, value); + ret = setUserBrightness(self->uscreen_proxy, self->gcancel, value); if (ret) { self->current = value; @@ -161,23 +180,23 @@ ib_brightness_powerd_control_set_value (IbBrightnessPowerdControl* self, gint va } gint -ib_brightness_powerd_control_get_value (IbBrightnessPowerdControl* self) +ib_brightness_uscreen_control_get_value (IbBrightnessUscreenControl* self) { return self->current; } gint -ib_brightness_powerd_control_get_max_value (IbBrightnessPowerdControl* self) +ib_brightness_uscreen_control_get_max_value (IbBrightnessUscreenControl* self) { return self->max; } void -ib_brightness_powerd_control_free (IbBrightnessPowerdControl *self) +ib_brightness_uscreen_control_free (IbBrightnessUscreenControl *self) { g_cancellable_cancel (self->gcancel); g_object_unref (self->gcancel); - g_object_unref (self->powerd_proxy); + g_object_unref (self->uscreen_proxy); g_free (self); } diff --git a/src/ib-brightness-powerd-control.h b/src/ib-brightness-uscreen-control.h index 95de1f4..3d026a9 100644 --- a/src/ib-brightness-powerd-control.h +++ b/src/ib-brightness-uscreen-control.h @@ -17,8 +17,8 @@ * Y.C Cheng <yc.cheng@canonical.com> */ -#ifndef __IB_BRIGHTNESS_POWERD_CONTROL_H__ -#define __IB_BRIGHTNESS_POWERD_CONTROL_H__ +#ifndef __IB_BRIGHTNESS_USCREEN_CONTROL_H__ +#define __IB_BRIGHTNESS_USCREEN_CONTROL_H__ #include <gio/gio.h> @@ -30,14 +30,14 @@ typedef struct { gboolean ab_supported; } brightness_params_t; -GDBusProxy* powerd_get_proxy(brightness_params_t *); +GDBusProxy* uscreen_get_proxy(brightness_params_t *); -typedef struct _IbBrightnessPowerdControl IbBrightnessPowerdControl; +typedef struct _IbBrightnessUScreenControl IbBrightnessUscreenControl; -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); -void ib_brightness_powerd_control_free (IbBrightnessPowerdControl *self); +IbBrightnessUscreenControl* ib_brightness_uscreen_control_new (GDBusProxy* uscreen_proxy, brightness_params_t params); +void ib_brightness_uscreen_control_set_value (IbBrightnessUscreenControl* self, gint value); +gint ib_brightness_uscreen_control_get_value (IbBrightnessUscreenControl* self); +gint ib_brightness_uscreen_control_get_max_value (IbBrightnessUscreenControl* self); +void ib_brightness_uscreen_control_free (IbBrightnessUscreenControl *self); #endif diff --git a/src/service.c b/src/service.c index 46ad802..6438c9a 100644 --- a/src/service.c +++ b/src/service.c @@ -27,7 +27,7 @@ #include "device.h" #include "device-provider.h" #include "ib-brightness-control.h" -#include "ib-brightness-powerd-control.h" +#include "ib-brightness-uscreen-control.h" #include "service.h" #define BUS_NAME "com.canonical.indicator.power" @@ -105,7 +105,7 @@ struct _IndicatorPowerServicePrivate GSettings * settings; IbBrightnessControl * brightness_control; - IbBrightnessPowerdControl * brightness_powerd_control; + IbBrightnessUscreenControl * brightness_uscreen_control; guint own_id; guint actions_export_id; @@ -467,9 +467,9 @@ get_brightness_range (IndicatorPowerService * self, gint * low, gint * high) { max = ib_brightness_control_get_max_value (self->priv->brightness_control); } - else if (p->brightness_powerd_control) + else if (p->brightness_uscreen_control) { - max = ib_brightness_powerd_control_get_max_value (self->priv->brightness_powerd_control); + max = ib_brightness_uscreen_control_get_max_value (self->priv->brightness_uscreen_control); } *low = max * 0.05; /* 5% minimum -- don't let the screen go completely dark */ *high = max; @@ -500,9 +500,9 @@ action_state_for_brightness (IndicatorPowerService * self) { brightness = ib_brightness_control_get_value (p->brightness_control); } - else if (p->brightness_powerd_control) + else if (p->brightness_uscreen_control) { - brightness = ib_brightness_powerd_control_get_value (p->brightness_powerd_control); + brightness = ib_brightness_uscreen_control_get_value (p->brightness_uscreen_control); } return g_variant_new_double (brightness_to_percentage (self, brightness)); } @@ -527,9 +527,9 @@ on_brightness_change_requested (GSimpleAction * action G_GNUC_UNUSED, { ib_brightness_control_set_value (self->priv->brightness_control, brightness); } - else if (self->priv->brightness_powerd_control) + else if (self->priv->brightness_uscreen_control) { - ib_brightness_powerd_control_set_value (self->priv->brightness_powerd_control, brightness); + ib_brightness_uscreen_control_set_value (self->priv->brightness_uscreen_control, brightness); } update_brightness_action_state (self); @@ -1024,7 +1024,7 @@ my_dispose (GObject * o) // 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); + g_clear_pointer (&p->brightness_uscreen_control, ib_brightness_uscreen_control_free); indicator_power_service_set_device_provider (self, NULL); @@ -1038,8 +1038,8 @@ my_dispose (GObject * o) static void indicator_power_service_init (IndicatorPowerService * self) { - GDBusProxy *powerd_proxy; - brightness_params_t powerd_brightness_params; + GDBusProxy *uscreen_proxy; + brightness_params_t brightness_params; priv_t * p = G_TYPE_INSTANCE_GET_PRIVATE (self, INDICATOR_TYPE_POWER_SERVICE, IndicatorPowerServicePrivate); @@ -1049,10 +1049,10 @@ indicator_power_service_init (IndicatorPowerService * self) p->settings = g_settings_new ("com.canonical.indicator.power"); - powerd_proxy = powerd_get_proxy(&powerd_brightness_params); - if (powerd_proxy != NULL) + uscreen_proxy = uscreen_get_proxy(&brightness_params); + if (uscreen_proxy != NULL) { - p->brightness_powerd_control = ib_brightness_powerd_control_new(powerd_proxy, powerd_brightness_params); + p->brightness_uscreen_control = ib_brightness_uscreen_control_new(uscreen_proxy, brightness_params); } else { |