From 31f83e84d9bbe67a2e53a54217399909d6dc4ed3 Mon Sep 17 00:00:00 2001 From: Marc Deslauriers Date: Tue, 10 Mar 2015 15:41:38 -0400 Subject: * Change sort order to prefer items with known time remaining (LP: #1315434) --- src/service.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/service.c b/src/service.c index fc07619..0ff818c 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); -- cgit v1.2.3