Merge lp:~charlesk/indicator-power/lp-1370791-15.10-adjust-slider-when-brightness-is-changed-by-powerd into lp:indicator-power/15.10

Proposed by Charles Kerr
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 287
Merged at revision: 287
Proposed branch: lp:~charlesk/indicator-power/lp-1370791-15.10-adjust-slider-when-brightness-is-changed-by-powerd
Merge into: lp:indicator-power/15.10
Diff against target: 339 lines (+186/-70)
3 files modified
src/CMakeLists.txt (+4/-0)
src/brightness.c (+98/-70)
src/com.canonical.powerd.xml (+84/-0)
To merge this branch: bzr merge lp:~charlesk/indicator-power/lp-1370791-15.10-adjust-slider-when-brightness-is-changed-by-powerd
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
Review via email: mp+259963@code.launchpad.net

Commit message

When powerd updates the backlight brightness, update the indicator slider to show the new value.

Description of the change

This branch is to keep Wily up-to-date with the slider fix that landed in Vivid earlier today.

Vivid MP: https://code.launchpad.net/~unity-api-team/indicator-power/lp-1370791-15.05-adjust-slider-when-brightness-is-changed-by-powerd/+merge/259676

To post a comment you must log in.
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Looks good. I've only tested this on vivid, will test the debs after jenkins build them.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2014-10-14 19:09:32 +0000
+++ src/CMakeLists.txt 2015-05-22 17:38:39 +0000
@@ -17,6 +17,10 @@
17# generated sources17# generated sources
18include(GdbusCodegen)18include(GdbusCodegen)
19set(SERVICE_GENERATED_SOURCES)19set(SERVICE_GENERATED_SOURCES)
20add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-powerd
21 com.canonical
22 Dbus
23 ${CMAKE_SOURCE_DIR}/src/com.canonical.powerd.xml)
20add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-battery24add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-battery
21 com.canonical.indicator.power25 com.canonical.indicator.power
22 Dbus26 Dbus
2327
=== modified file 'src/brightness.c'
--- src/brightness.c 2014-09-12 16:37:02 +0000
+++ src/brightness.c 2015-05-22 17:38:39 +0000
@@ -18,6 +18,7 @@
18 */18 */
1919
20#include "brightness.h"20#include "brightness.h"
21#include "dbus-powerd.h"
2122
22#include <gio/gio.h>23#include <gio/gio.h>
2324
@@ -45,7 +46,8 @@
4546
46 GSettings * settings;47 GSettings * settings;
4748
48 guint powerd_name_tag;49 DbusPowerd * powerd_proxy;
50 char * powerd_name_owner;
4951
50 double percentage;52 double percentage;
5153
@@ -136,14 +138,15 @@
136 g_clear_object(&p->cancellable);138 g_clear_object(&p->cancellable);
137 }139 }
138140
139 if (p->powerd_name_tag)141 if (p->powerd_proxy != NULL)
140 {142 {
141 g_bus_unwatch_name(p->powerd_name_tag);143 g_signal_handlers_disconnect_by_data(p->powerd_proxy, o);
142 p->powerd_name_tag = 0;144 g_clear_object(&p->powerd_proxy);
143 }145 }
144146
145 g_clear_object(&p->settings);147 g_clear_object(&p->settings);
146 g_clear_object(&p->system_bus);148 g_clear_object(&p->system_bus);
149 g_clear_pointer(&p->powerd_name_owner, g_free);
147150
148 G_OBJECT_CLASS(indicator_power_brightness_parent_class)->dispose(o);151 G_OBJECT_CLASS(indicator_power_brightness_parent_class)->dispose(o);
149}152}
@@ -202,36 +205,30 @@
202 */205 */
203206
204static void set_brightness_global(IndicatorPowerBrightness*, int);207static void set_brightness_global(IndicatorPowerBrightness*, int);
208static void set_brightness_local(IndicatorPowerBrightness*, int);
205209
206static void210static void
207on_powerd_brightness_params_ready(GObject * source,211on_powerd_brightness_params_ready(GObject * oproxy,
208 GAsyncResult * res,212 GAsyncResult * res,
209 gpointer gself)213 gpointer gself)
210{214{
211 GError * error;215 GError * error;
212 GVariant * v;216 GVariant * v;
213217
218 v = NULL;
214 error = NULL;219 error = NULL;
215 v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &error);220 if (dbus_powerd_call_get_brightness_params_finish(DBUS_POWERD(oproxy), &v, res, &error))
216 if (v == NULL)
217 {
218 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
219 g_warning("Unable to get system bus: %s", error->message);
220
221 g_error_free(error);
222 }
223 else
224 {221 {
225 IndicatorPowerBrightness * self = INDICATOR_POWER_BRIGHTNESS(gself);222 IndicatorPowerBrightness * self = INDICATOR_POWER_BRIGHTNESS(gself);
226 priv_t * p = get_priv(self);223 priv_t * p = get_priv(self);
227 const gboolean old_ab_supported = p->powerd_ab_supported;224 const gboolean old_ab_supported = p->powerd_ab_supported;
228225
229 p->have_powerd_params = TRUE;226 p->have_powerd_params = TRUE;
230 g_variant_get(v, "((iiiib))", &p->powerd_dim,227 g_variant_get(v, "(iiiib)", &p->powerd_dim,
231 &p->powerd_min,228 &p->powerd_min,
232 &p->powerd_max,229 &p->powerd_max,
233 &p->powerd_default_value,230 &p->powerd_default_value,
234 &p->powerd_ab_supported);231 &p->powerd_ab_supported);
235 g_debug("powerd brightness settings: dim=%d, min=%d, max=%d, default=%d, ab_supported=%d",232 g_debug("powerd brightness settings: dim=%d, min=%d, max=%d, default=%d, ab_supported=%d",
236 p->powerd_dim,233 p->powerd_dim,
237 p->powerd_min,234 p->powerd_min,
@@ -262,52 +259,83 @@
262 /* cleanup */259 /* cleanup */
263 g_variant_unref(v);260 g_variant_unref(v);
264 }261 }
265}262 else if (error != NULL)
266263 {
267static void264 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
268call_powerd_get_brightness_params(IndicatorPowerBrightness * self)265 g_warning("Unable to get system bus: %s", error->message);
269{266
270 priv_t * p = get_priv(self);267 g_error_free(error);
271268 }
272 g_dbus_connection_call(p->system_bus,269}
273 "com.canonical.powerd",270
274 "/com/canonical/powerd",271static void
275 "com.canonical.powerd",272on_powerd_name_owner_changed(GDBusProxy * powerd_proxy,
276 "getBrightnessParams",273 GParamSpec * pspec G_GNUC_UNUSED,
277 NULL,274 gpointer gself)
278 G_VARIANT_TYPE("((iiiib))"),
279 G_DBUS_CALL_FLAGS_NONE,
280 -1, /* default timeout */
281 p->cancellable,
282 on_powerd_brightness_params_ready,
283 self);
284}
285
286static void
287on_powerd_appeared(GDBusConnection * connection,
288 const gchar * bus_name G_GNUC_UNUSED,
289 const gchar * name_owner G_GNUC_UNUSED,
290 gpointer gself)
291{
292 IndicatorPowerBrightness * self = INDICATOR_POWER_BRIGHTNESS(gself);
293 priv_t * p = get_priv(self);
294
295 /* keep a handle to the system bus */
296 g_clear_object(&p->system_bus);
297 p->system_bus = g_object_ref(connection);
298
299 /* update our cache of powerd's brightness params */
300 call_powerd_get_brightness_params(self);
301}
302
303static void
304on_powerd_vanished(GDBusConnection * connection G_GNUC_UNUSED,
305 const gchar * bus_name G_GNUC_UNUSED,
306 gpointer gself)
307{275{
308 priv_t * p = get_priv(INDICATOR_POWER_BRIGHTNESS(gself));276 priv_t * p = get_priv(INDICATOR_POWER_BRIGHTNESS(gself));
309277 gchar * owner = g_dbus_proxy_get_name_owner(powerd_proxy);
310 p->have_powerd_params = FALSE;278
279 if (g_strcmp0(p->powerd_name_owner, owner))
280 {
281 p->have_powerd_params = FALSE;
282
283 if (owner != NULL)
284 {
285 dbus_powerd_call_get_brightness_params(DBUS_POWERD(powerd_proxy),
286 p->cancellable,
287 on_powerd_brightness_params_ready,
288 gself);
289 }
290
291 g_free(p->powerd_name_owner);
292 p->powerd_name_owner = owner;
293 }
294}
295
296static void
297on_powerd_brightness_changed(DbusPowerd * powerd_proxy,
298 GParamSpec * pspec G_GNUC_UNUSED,
299 gpointer gself)
300{
301 set_brightness_local(gself, dbus_powerd_get_brightness(powerd_proxy));
302}
303
304static void
305on_powerd_proxy_ready(GObject * source_object G_GNUC_UNUSED,
306 GAsyncResult * res,
307 gpointer gself)
308{
309 GError * error;
310 DbusPowerd * powerd_proxy;
311
312 error = NULL;
313 powerd_proxy = dbus_powerd_proxy_new_for_bus_finish(res, &error);
314
315 if (powerd_proxy != NULL)
316 {
317 priv_t * p;
318 p = get_priv(INDICATOR_POWER_BRIGHTNESS(gself));
319
320 /* keep a handle to the system bus */
321 g_clear_object(&p->system_bus);
322 p->system_bus = g_object_ref(g_dbus_proxy_get_connection(G_DBUS_PROXY(powerd_proxy)));
323
324 /* keep the proxy and listen to owner changes */
325 p->powerd_proxy = powerd_proxy;
326 g_signal_connect(p->powerd_proxy, "notify::g-name-owner",
327 G_CALLBACK(on_powerd_name_owner_changed), gself);
328 g_signal_connect(p->powerd_proxy, "notify::brightness",
329 G_CALLBACK(on_powerd_brightness_changed), gself);
330 on_powerd_name_owner_changed(G_DBUS_PROXY(powerd_proxy), NULL, gself);
331 }
332 else if (error != NULL)
333 {
334 if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
335 g_warning("Unable to get powerd proxy: %s", error->message);
336
337 g_error_free(error);
338 }
311}339}
312340
313/**341/**
@@ -433,13 +461,13 @@
433 g_settings_schema_unref(schema);461 g_settings_schema_unref(schema);
434 }462 }
435463
436 p->powerd_name_tag = g_bus_watch_name(G_BUS_TYPE_SYSTEM,464 dbus_powerd_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
437 "com.canonical.powerd",465 G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
438 G_BUS_NAME_WATCHER_FLAGS_NONE,466 "com.canonical.powerd",
439 on_powerd_appeared,467 "/com/canonical/powerd",
440 on_powerd_vanished,468 p->cancellable,
441 self,469 on_powerd_proxy_ready,
442 NULL);470 self);
443}471}
444472
445static void473static void
446474
=== added file 'src/com.canonical.powerd.xml'
--- src/com.canonical.powerd.xml 1970-01-01 00:00:00 +0000
+++ src/com.canonical.powerd.xml 2015-05-22 17:38:39 +0000
@@ -0,0 +1,84 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<node name="/">
3 <interface name="com.canonical.powerd">
4 <!-- Properties -->
5
6 <property name="brightness" type="i" access="readwrite">
7 </property>
8
9
10 <!-- Functions -->
11 <method name="requestSysState">
12 <arg type="s" name="name" direction="in" />
13 <arg type="i" name="state" direction="in" />
14 <arg type="s" name="cookie" direction="out" />
15 </method>
16
17 <method name="clearSysState">
18 <arg type="s" name="cookie" direction="in" />
19 </method>
20
21 <method name="requestWakeup">
22 <arg type="s" name="name" direction="in" />
23 <arg type="t" name="time" direction="in" />
24 <arg type="s" name="cookie" direction="out" />
25 </method>
26
27 <method name="enableProximityHandling">
28 <arg type="s" name="name" direction="in" />
29 </method>
30
31 <method name="disableProximityHandling">
32 <arg type="s" name="name" direction="in" />
33 </method>
34
35 <method name="clearWakeup">
36 <arg type="s" name="cookie" direction="in" />
37 </method>
38
39 <method name="registerClient">
40 <arg type="s" name="name" direction="in" />
41 </method>
42
43 <method name="unregisterClient">
44 <arg type="s" name="name" direction="in" />
45 </method>
46
47 <method name="ackStateChange">
48 <arg type="i" name="state" direction="in" />
49 </method>
50
51 <!-- User settings -->
52 <method name="userAutobrightnessEnable">
53 <arg type="b" name="enable" direction="in" />
54 </method>
55
56 <method name="getBrightnessParams">
57 <!-- Returns min, max, and default brighness and whether or not
58 autobrightness is supported, in that order -->
59 <arg type="(iiiib)" name="params" direction="out" />
60 </method>
61
62 <method name="setUserBrightness">
63 <arg type="i" name="brightness" direction="in" />
64 </method>
65
66 <!-- for debug/testing -->
67 <method name="listSysRequests">
68 <arg type="a(ssi)" name="requestList" direction="out" />
69 </method>
70
71 <method name="getSysRequestStats">
72 <arg type="a(ssuttt)" name="requestStats" direction="out" />
73 </method>
74
75 <!-- Signals -->
76 <signal name="SysPowerStateChange">
77 <arg type="i" name="sysState" direction="out" />
78 </signal>
79
80 <signal name="Wakeup">
81 </signal>
82
83 </interface>
84</node>

Subscribers

People subscribed via source and target branches