aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Deslauriers <marc.deslauriers@canonical.com>2015-03-10 15:41:38 -0400
committerMarc Deslauriers <marc.deslauriers@canonical.com>2015-03-10 15:41:38 -0400
commit31f83e84d9bbe67a2e53a54217399909d6dc4ed3 (patch)
tree16af2d561482dc552759442807183668249d4941
parentae9a41c6876dc103d369a3565f5a92f76f8f23d8 (diff)
downloadayatana-indicator-power-31f83e84d9bbe67a2e53a54217399909d6dc4ed3.tar.gz
ayatana-indicator-power-31f83e84d9bbe67a2e53a54217399909d6dc4ed3.tar.bz2
ayatana-indicator-power-31f83e84d9bbe67a2e53a54217399909d6dc4ed3.zip
* Change sort order to prefer items with known time remaining
(LP: #1315434)
-rw-r--r--src/service.c29
1 files 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);