Merge lp:~rsalveti/powerd/display_on_charging_discharging into lp:powerd

Proposed by Ricardo Salveti
Status: Merged
Approved by: Ricardo Mendoza
Approved revision: 149
Merged at revision: 153
Proposed branch: lp:~rsalveti/powerd/display_on_charging_discharging
Merge into: lp:powerd
Diff against target: 89 lines (+56/-0)
1 file modified
src/power-source.c (+56/-0)
To merge this branch: bzr merge lp:~rsalveti/powerd/display_on_charging_discharging
Reviewer Review Type Date Requested Status
Ricardo Mendoza (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+246668@code.launchpad.net

Commit message

upower: turning display on when charging cable gets connected/disconnected

Description of the change

upower: turning display on when charging cable gets connected/disconnected

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Mendoza (ricmm) wrote :

Works great!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/power-source.c'
2--- src/power-source.c 2014-10-31 09:45:03 +0000
3+++ src/power-source.c 2015-01-16 02:35:13 +0000
4@@ -28,6 +28,7 @@
5 static double shutdown_temp = 68.0f;
6 static double battery_log_level = 4.0f;
7 static gboolean stats_logged;
8+static GHashTable *battery_state_hash;
9
10 static void up_device_changed_cb(UpClient *client,
11 #if UP_CHECK_VERSION(0,99,0)
12@@ -60,10 +61,36 @@
13 NULL);
14 if (kind == UP_DEVICE_KIND_BATTERY && is_present) {
15 double percentage, temp;
16+ guint state;
17+ guint prev_state;
18+ gchar *native_path;
19 g_object_get(device,
20 "percentage", &percentage,
21 "temperature", &temp,
22+ "state", &state,
23+ "native-path", &native_path,
24 NULL);
25+ gpointer hvalue = g_hash_table_lookup(battery_state_hash,
26+ native_path);
27+ if (hvalue == NULL)
28+ g_hash_table_insert(battery_state_hash,
29+ g_strdup(native_path), GUINT_TO_POINTER(state));
30+ else {
31+ prev_state = GPOINTER_TO_UINT(hvalue);
32+ if (prev_state != state) {
33+ if (state == UP_DEVICE_STATE_DISCHARGING ||
34+ (prev_state == UP_DEVICE_STATE_DISCHARGING && (
35+ state == UP_DEVICE_STATE_CHARGING ||
36+ state == UP_DEVICE_STATE_FULLY_CHARGED))) {
37+ powerd_debug("Turning screen on, battery state changes");
38+ turn_display_on(TRUE, UNITY_SCREEN_REASON_NORMAL);
39+ }
40+ g_hash_table_replace(battery_state_hash,
41+ g_strdup(native_path),
42+ GUINT_TO_POINTER(state));
43+ }
44+ }
45+ g_free(native_path);
46
47 /*
48 * Log battery stats a little before emergency
49@@ -124,6 +151,30 @@
50 return -ENODEV;
51 }
52
53+ /* Hash to track the state for the battery devices */
54+ battery_state_hash = g_hash_table_new(g_str_hash, g_str_equal);
55+ GPtrArray *devices;
56+ int i;
57+ devices = up_client_get_devices(up_client);
58+ for (i = 0; i < devices->len; i++) {
59+ UpDevice *device = g_ptr_array_index(devices, i);
60+ UpDeviceKind kind;
61+ gboolean is_present;
62+ guint state;
63+ gchar *native_path;
64+ g_object_get(device,
65+ "kind", &kind,
66+ "is-present", &is_present,
67+ "state", &state,
68+ "native-path", &native_path,
69+ NULL);
70+ if (kind == UP_DEVICE_KIND_BATTERY && is_present) {
71+ g_hash_table_insert(battery_state_hash,
72+ g_strdup(native_path), GUINT_TO_POINTER(state));
73+ }
74+ g_free(native_path);
75+ }
76+
77 #if UP_CHECK_VERSION(0,99,0)
78 g_signal_connect(up_client, "notify",
79 G_CALLBACK(up_device_changed_cb), NULL);
80@@ -142,4 +193,9 @@
81 {
82 if (up_client)
83 g_object_unref(up_client);
84+
85+ if (battery_state_hash) {
86+ g_hash_table_destroy(battery_state_hash);
87+ battery_state_hash = NULL;
88+ }
89 }

Subscribers

People subscribed via source and target branches