aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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);