aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2017-05-15 14:54:40 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2017-05-15 14:54:40 +0200
commitf223d5a98db5fc1505ffcd04941093856ba0b3fb (patch)
tree095af07e858cfc07600cc79bf1fb62bed2f5f935 /src
parentc2b69b84d7f698a5f4cc4aec29d6b131aba86ada (diff)
downloadayatana-indicator-power-f223d5a98db5fc1505ffcd04941093856ba0b3fb.tar.gz
ayatana-indicator-power-f223d5a98db5fc1505ffcd04941093856ba0b3fb.tar.bz2
ayatana-indicator-power-f223d5a98db5fc1505ffcd04941093856ba0b3fb.zip
Fix bug that chose the wrong header icon if a connected device has a charge but its charging/discharging state is unknown. (LP: #1470080).
Diffstat (limited to 'src')
-rw-r--r--src/device.c3
-rw-r--r--src/service.c20
2 files changed, 21 insertions, 2 deletions
diff --git a/src/device.c b/src/device.c
index bcb99db..aa5bcee 100644
--- a/src/device.c
+++ b/src/device.c
@@ -434,11 +434,12 @@ indicator_power_device_get_icon_names (const IndicatorPowerDevice * device)
}
g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging-symbolic", kind_str, suffix_str));
g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging", kind_str, suffix_str));
- break;
+ // NB: fallthrough to use foo-bar as a fallback for foo-bar-charging
case UP_DEVICE_STATE_PENDING_CHARGE:
case UP_DEVICE_STATE_DISCHARGING:
case UP_DEVICE_STATE_PENDING_DISCHARGE:
+ case UP_DEVICE_STATE_UNKNOWN: /* http://pad.lv/1470080 */
suffix_str = get_device_icon_suffix (percentage);
index_str = get_closest_10_percent_percentage (percentage);
g_ptr_array_add (names, g_strdup_printf ("%s-%s", kind_str, index_str));
diff --git a/src/service.c b/src/service.c
index 679dc5e..76a0db9 100644
--- a/src/service.c
+++ b/src/service.c
@@ -243,7 +243,25 @@ device_compare_func (gconstpointer ga, gconstpointer gb)
}
}
- if (!ret) /* neither device is charging nor discharging... */
+ /* neither device is charging nor discharging... */
+
+ /* unless there's no other option,
+ don't choose a device with an unknown state.
+ https://bugs.launchpad.net/ubuntu/+source/indicator-power/+bug/1470080 */
+ state = UP_DEVICE_STATE_UNKNOWN;
+ if (!ret && ((a_state == state) || (b_state == state)))
+ {
+ if (a_state != state) /* b is unknown */
+ {
+ ret = -1;
+ }
+ else if (b_state != state) /* a is unknown */
+ {
+ ret = 1;
+ }
+ }
+
+ if (!ret)
{
const int weight_a = get_device_kind_weight (a);
const int weight_b = get_device_kind_weight (b);