aboutsummaryrefslogtreecommitdiff
path: root/src/service.c
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2017-05-15 15:01:23 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2017-05-15 15:01:50 +0200
commitbd1a508aeb9e498dd782678da420d5baf639b4c0 (patch)
tree1b76d4f9435d12a34ab7241535bd673b082cc03f /src/service.c
parentdbfed3a9b70091667233b884d5a7fa3098f4d104 (diff)
downloadayatana-indicator-power-bd1a508aeb9e498dd782678da420d5baf639b4c0.tar.gz
ayatana-indicator-power-bd1a508aeb9e498dd782678da420d5baf639b4c0.tar.bz2
ayatana-indicator-power-bd1a508aeb9e498dd782678da420d5baf639b4c0.zip
Make device with power supply has higher sorting priority. (LP: #1100546)
Diffstat (limited to 'src/service.c')
-rw-r--r--src/service.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/service.c b/src/service.c
index 76a0db9..5072765 100644
--- a/src/service.c
+++ b/src/service.c
@@ -160,11 +160,12 @@ 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. 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 */
+ 1. device that supplied the power to the system
+ 2. discharging items from least time remaining until most 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
+ 5. discharging items with an unknown time remaining
+ 6. batteries, then non-line power, then line-power */
static gint
device_compare_func (gconstpointer ga, gconstpointer gb)
{
@@ -172,6 +173,8 @@ device_compare_func (gconstpointer ga, gconstpointer gb)
int state;
const IndicatorPowerDevice * a = ga;
const IndicatorPowerDevice * b = gb;
+ const gboolean a_power_supply = indicator_power_device_get_power_supply (a);
+ const gboolean b_power_supply = indicator_power_device_get_power_supply (b);
const int a_state = indicator_power_device_get_state (a);
const int b_state = indicator_power_device_get_state (b);
const gdouble a_percentage = indicator_power_device_get_percentage (a);
@@ -181,6 +184,18 @@ device_compare_func (gconstpointer ga, gconstpointer gb)
ret = 0;
+ if (!ret && (a_power_supply != b_power_supply))
+ {
+ if (a_power_supply) /* a provides power to the system */
+ {
+ ret = -1;
+ }
+ else /* b provides power to the system */
+ {
+ ret = 1;
+ }
+ }
+
state = UP_DEVICE_STATE_DISCHARGING;
if (!ret && (((a_state == state) && a_time) ||
((b_state == state) && b_time)))
@@ -1380,7 +1395,8 @@ create_totalled_battery_device (const GList * devices)
UP_DEVICE_KIND_BATTERY,
percent,
state,
- time_left);
+ time_left,
+ TRUE);
}
return device;