aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Deslauriers <marc.deslauriers@canonical.com>2015-04-02 20:30:59 +0000
committerCI Train Bot <ci-train-bot@canonical.com>2015-04-02 20:30:59 +0000
commita3cf49905933a81937a02bea714f589cf5a533e5 (patch)
tree735710f386821a5a4a5775454835fdfb40f8e126
parente332c6b358df2e47e329b8465c30f184516f1e80 (diff)
parent31f83e84d9bbe67a2e53a54217399909d6dc4ed3 (diff)
downloadayatana-indicator-power-a3cf49905933a81937a02bea714f589cf5a533e5.tar.gz
ayatana-indicator-power-a3cf49905933a81937a02bea714f589cf5a533e5.tar.bz2
ayatana-indicator-power-a3cf49905933a81937a02bea714f589cf5a533e5.zip
Change sort order to prefer items with known time remaining
Approved by: Charles Kerr, PS Jenkins bot
-rw-r--r--src/service.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/service.c b/src/service.c
index 602caba..dad6dc8 100644
--- a/src/service.c
+++ b/src/service.c
@@ -161,9 +161,9 @@ get_device_kind_weight (const IndicatorPowerDevice * device)
/* sort devices from most interesting to least interesting on this criteria:
1. discharging items from least time remaining until most time remaining
- 2. discharging items with an unknown time remaining
- 3. charging items from most time left to charge to least time left to charge
- 4. charging items with an unknown time remaining
+ 2. charging items from most time left to charge to least time left to charge
+ 3. charging items with an unknown time remaining
+ 4. discharging items with an unknown time remaining
5. batteries, then non-line power, then line-power */
static gint
device_compare_func (gconstpointer ga, gconstpointer gb)
@@ -182,7 +182,8 @@ device_compare_func (gconstpointer ga, gconstpointer gb)
ret = 0;
state = UP_DEVICE_STATE_DISCHARGING;
- if (!ret && ((a_state == state) || (b_state == state)))
+ if (!ret && (((a_state == state) && a_time) ||
+ ((b_state == state) && b_time)))
{
if (a_state != state) /* b is discharging */
{
@@ -204,8 +205,7 @@ device_compare_func (gconstpointer ga, gconstpointer gb)
}
state = UP_DEVICE_STATE_CHARGING;
- if (!ret && (((a_state == state) && a_time) ||
- ((b_state == state) && b_time)))
+ if (!ret && ((a_state == state) || (b_state == state)))
{
if (a_state != state) /* b is charging */
{
@@ -226,6 +226,23 @@ device_compare_func (gconstpointer ga, gconstpointer gb)
}
}
+ state = UP_DEVICE_STATE_DISCHARGING;
+ if (!ret && ((a_state == state) || (b_state == state)))
+ {
+ if (a_state != state) /* b is discharging */
+ {
+ ret = 1;
+ }
+ else if (b_state != state) /* a is discharging */
+ {
+ ret = -1;
+ }
+ else /* both are discharging; use percentage */
+ {
+ ret = a_percentage < b_percentage ? -1 : 1;
+ }
+ }
+
if (!ret) /* neither device is charging nor discharging... */
{
const int weight_a = get_device_kind_weight (a);