aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2015-05-20 10:34:26 -0500
committerCharles Kerr <charles.kerr@canonical.com>2015-05-20 10:34:26 -0500
commit108a1e2314ac61595cf2d1727cf42d2508d59ae8 (patch)
tree91de8aa70076088ec46305b6358950442c1bc88f /src
parent05d07c82954637215f05ea8c707b8d917f3acef6 (diff)
downloadayatana-indicator-power-108a1e2314ac61595cf2d1727cf42d2508d59ae8.tar.gz
ayatana-indicator-power-108a1e2314ac61595cf2d1727cf42d2508d59ae8.tar.bz2
ayatana-indicator-power-108a1e2314ac61595cf2d1727cf42d2508d59ae8.zip
in brightness.c, add a powerd proxy and listen to it for brightness property changes.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/brightness.c128
-rw-r--r--src/com.canonical.powerd.xml84
3 files changed, 170 insertions, 46 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6f4bfaf..8748484 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -17,6 +17,10 @@ set(SERVICE_MANUAL_SOURCES
# generated sources
include(GdbusCodegen)
set(SERVICE_GENERATED_SOURCES)
+add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-powerd
+ com.canonical
+ Dbus
+ ${CMAKE_SOURCE_DIR}/src/com.canonical.powerd.xml)
add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-battery
com.canonical.indicator.power
Dbus
diff --git a/src/brightness.c b/src/brightness.c
index 5e7c5e5..076610b 100644
--- a/src/brightness.c
+++ b/src/brightness.c
@@ -45,7 +45,8 @@ typedef struct
GSettings * settings;
- guint powerd_name_tag;
+ DbusPowerd * powerd_proxy;
+ char * powerd_name_owner;
double percentage;
@@ -136,14 +137,15 @@ my_dispose(GObject * o)
g_clear_object(&p->cancellable);
}
- if (p->powerd_name_tag)
+ if (p->powerd_proxy != NULL)
{
- g_bus_unwatch_name(p->powerd_name_tag);
- p->powerd_name_tag = 0;
+ g_signal_handlers_disconnect_by_data(p->powerd_proxy, o);
+ g_clear_object(&p->powerd_proxy);
}
g_clear_object(&p->settings);
g_clear_object(&p->system_bus);
+ g_clear_pointer(&p->powerd_name_owner, g_free);
G_OBJECT_CLASS(indicator_power_brightness_parent_class)->dispose(o);
}
@@ -204,28 +206,23 @@ percentage_to_brightness(IndicatorPowerBrightness * self, double percentage)
static void set_brightness_global(IndicatorPowerBrightness*, int);
static void
-on_powerd_brightness_params_ready(GObject * source,
+on_powerd_brightness_params_ready(DbusPowerd * dbus_proxy,
GAsyncResult * res,
gpointer gself)
{
GError * error;
GVariant * v;
+ v = NULL;
error = NULL;
- v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &error);
- if (v == NULL)
- {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_warning("Unable to get system bus: %s", error->message);
-
- g_error_free(error);
- }
- else
+ if (dbus_powerd_call_get_brightness_params_finish (dbus_proxy, &v, res, &error))
{
IndicatorPowerBrightness * self = INDICATOR_POWER_BRIGHTNESS(gself);
priv_t * p = get_priv(self);
const gboolean old_ab_supported = p->powerd_ab_supported;
+ g_message("%s", g_variant_print(v, TRUE));
+
p->have_powerd_params = TRUE;
g_variant_get(v, "((iiiib))", &p->powerd_dim,
&p->powerd_min,
@@ -262,52 +259,83 @@ on_powerd_brightness_params_ready(GObject * source,
/* cleanup */
g_variant_unref(v);
}
+ else if (error != NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning("Unable to get system bus: %s", error->message);
+
+ g_error_free(error);
+ }
}
static void
-call_powerd_get_brightness_params(IndicatorPowerBrightness * self)
+on_powerd_name_owner_changed(GDBusProxy * powerd_proxy,
+ GParamSpec * pspec G_GNUC_UNUSED,
+ gpointer gself)
{
- priv_t * p = get_priv(self);
+ priv_t * p = get_priv(INDICATOR_POWER_BRIGHTNESS(gself));
+ gchar * owner = g_dbus_proxy_get_name_owner(powerd_proxy);
- g_dbus_connection_call(p->system_bus,
- "com.canonical.powerd",
- "/com/canonical/powerd",
- "com.canonical.powerd",
- "getBrightnessParams",
- NULL,
- G_VARIANT_TYPE("((iiiib))"),
- G_DBUS_CALL_FLAGS_NONE,
- -1, /* default timeout */
- p->cancellable,
- on_powerd_brightness_params_ready,
- self);
+ if (g_strcmp0(p->powerd_name_owner, owner))
+ {
+ p->have_powerd_params = FALSE;
+
+ if (owner != NULL)
+ {
+ dbus_powerd_call_get_brightness_params(powerd_proxy,
+ p->cancellable,
+ on_powerd_brightness_params_ready,
+ gself);
+ }
+
+ g_free(p->powerd_name_owner);
+ p->powerd_name_owner = owner;
+ }
}
static void
-on_powerd_appeared(GDBusConnection * connection,
- const gchar * bus_name G_GNUC_UNUSED,
- const gchar * name_owner G_GNUC_UNUSED,
- gpointer gself)
+on_powerd_brightness_changed(DbusPowerd * powerd_proxy,
+ GParamSpec * pspec G_GNUC_UNUSED,
+ gpointer gself)
{
- IndicatorPowerBrightness * self = INDICATOR_POWER_BRIGHTNESS(gself);
- priv_t * p = get_priv(self);
-
- /* keep a handle to the system bus */
- g_clear_object(&p->system_bus);
- p->system_bus = g_object_ref(connection);
-
- /* update our cache of powerd's brightness params */
- call_powerd_get_brightness_params(self);
+ set_brightness_local(gself, dbus_powerd_get_brightness(powerd_proxy));
}
static void
-on_powerd_vanished(GDBusConnection * connection G_GNUC_UNUSED,
- const gchar * bus_name G_GNUC_UNUSED,
- gpointer gself)
+on_powerd_proxy_ready(GObject * source_object G_GNUC_UNUSED,
+ GAsyncResult * res,
+ gpointer gself)
{
- priv_t * p = get_priv(INDICATOR_POWER_BRIGHTNESS(gself));
+ GError * error;
+ DbusPowerd * powerd_proxy;
- p->have_powerd_params = FALSE;
+ error = NULL;
+ powerd_proxy = dbus_powerd_proxy_new_for_bus_finish(res, &error);
+
+ if (powerd_proxy != NULL)
+ {
+ priv_t * p;
+
+ /* keep a handle to the system bus */
+ g_clear_object(&p->system_bus);
+ p->system_bus = g_object_ref(g_dbus_proxy_get_connection(powerd_proxy));
+
+ /* keep the proxy and listen to owner changes */
+ p = get_priv(INDICATOR_POWER_BRIGHTNESS(gself));
+ p->powerd_proxy = powerd_proxy;
+ g_signal_connect(p->powerd_proxy, "notify::g-name-owner",
+ G_CALLBACK(on_powerd_name_owner_changed), gself);
+ g_signal_connect(p->powerd_proxy, "brightness",
+ G_CALLBACK(on_powerd_brightness_changed), gself);
+ on_powerd_name_owner_changed(powerd_proxy, NULL, gself);
+ }
+ else if (error != NULL)
+ {
+ if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning("Unable to get powerd proxy: %s", error->message);
+
+ g_error_free(error);
+ }
}
/**
@@ -433,6 +461,14 @@ indicator_power_brightness_init(IndicatorPowerBrightness * self)
g_settings_schema_unref(schema);
}
+ dbus_powerd_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
+ "com.canonical.powerd",
+ "/com/canonical/powerd",
+ p->cancellable,
+ on_powerd_proxy_ready,
+ self);
+
p->powerd_name_tag = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
"com.canonical.powerd",
G_BUS_NAME_WATCHER_FLAGS_NONE,
diff --git a/src/com.canonical.powerd.xml b/src/com.canonical.powerd.xml
new file mode 100644
index 0000000..b5b4ac4
--- /dev/null
+++ b/src/com.canonical.powerd.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<node name="/">
+ <interface name="com.canonical.powerd">
+ <!-- Properties -->
+
+ <property name="brightness" type="i" access="readwrite">
+ </property>
+
+
+ <!-- Functions -->
+ <method name="requestSysState">
+ <arg type="s" name="name" direction="in" />
+ <arg type="i" name="state" direction="in" />
+ <arg type="s" name="cookie" direction="out" />
+ </method>
+
+ <method name="clearSysState">
+ <arg type="s" name="cookie" direction="in" />
+ </method>
+
+ <method name="requestWakeup">
+ <arg type="s" name="name" direction="in" />
+ <arg type="t" name="time" direction="in" />
+ <arg type="s" name="cookie" direction="out" />
+ </method>
+
+ <method name="enableProximityHandling">
+ <arg type="s" name="name" direction="in" />
+ </method>
+
+ <method name="disableProximityHandling">
+ <arg type="s" name="name" direction="in" />
+ </method>
+
+ <method name="clearWakeup">
+ <arg type="s" name="cookie" direction="in" />
+ </method>
+
+ <method name="registerClient">
+ <arg type="s" name="name" direction="in" />
+ </method>
+
+ <method name="unregisterClient">
+ <arg type="s" name="name" direction="in" />
+ </method>
+
+ <method name="ackStateChange">
+ <arg type="i" name="state" direction="in" />
+ </method>
+
+ <!-- User settings -->
+ <method name="userAutobrightnessEnable">
+ <arg type="b" name="enable" direction="in" />
+ </method>
+
+ <method name="getBrightnessParams">
+ <!-- Returns min, max, and default brighness and whether or not
+ autobrightness is supported, in that order -->
+ <arg type="(iiiib)" name="params" direction="out" />
+ </method>
+
+ <method name="setUserBrightness">
+ <arg type="i" name="brightness" direction="in" />
+ </method>
+
+ <!-- for debug/testing -->
+ <method name="listSysRequests">
+ <arg type="a(ssi)" name="requestList" direction="out" />
+ </method>
+
+ <method name="getSysRequestStats">
+ <arg type="a(ssuttt)" name="requestStats" direction="out" />
+ </method>
+
+ <!-- Signals -->
+ <signal name="SysPowerStateChange">
+ <arg type="i" name="sysState" direction="out" />
+ </signal>
+
+ <signal name="Wakeup">
+ </signal>
+
+ </interface>
+</node>