The order is dictated by src/indicator-power.c. All power devices are assigned a weighting, with batteries assigned weight 2, in function:
static int
get_device_kind_weight(const IndicatorPowerDevice * device) {...}
A function sorts all power devices in a list according to this criteria:
/* 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
5. batteries, then non-line power, then line-power */
static gint
device_compare_func (gconstpointer ga, gconstpointer gb) {...}
Finally, the primary device is selected as the first in the sorted list:
Examining /sys/class/power_supply/*/ it looks as if the sort function could take into account the 'capacity' node of all batteries since it looks to be the only common value shared across laptop and external device batteries. I've not yet discovered the unit of measure so far though, so it might not be the most suitable value.
$ for n in /sys/class/power_supply/*/capacity; do echo "$n $(cat $n)"; done
/sys/class/power_supply/BAT0/capacity 116
/sys/class/power_supply/hid-00:12:a1:63:a8:50-battery/capacity 63
The key thing is to be able to recognise and differentiate the treatment of internal laptop batteries (of which there can be more than one) from external device batteries (mice, keyboard, headphones, etc.).
It may be that the simplest most flexible solution would be to add an option to the Power Settings GUI that allows the user to make an intelligent decision as to which battery/batteries they wish to be considered as the primaries for purposes of the indicator icon.
The order is dictated by src/indicator- power.c. All power devices are assigned a weighting, with batteries assigned weight 2, in function:
static int kind_weight( const IndicatorPowerD evice * device) {...}
get_device_
A function sorts all power devices in a list according to this criteria:
/* 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
5. batteries, then non-line power, then line-power */
static gint
device_compare_func (gconstpointer ga, gconstpointer gb) {...}
Finally, the primary device is selected as the first in the sorted list:
IndicatorPowerD evice * power_choose_ primary_ device (GSList * devices) { compare_ func);
indicator_
...
tmp = g_slist_sort (tmp, device_
primary = g_object_ref (tmp->data);
...
return primary;
}
Examining /sys/class/ power_supply/ */ it looks as if the sort function could take into account the 'capacity' node of all batteries since it looks to be the only common value shared across laptop and external device batteries. I've not yet discovered the unit of measure so far though, so it might not be the most suitable value.
$ for n in /sys/class/ power_supply/ */capacity; do echo "$n $(cat $n)"; done power_supply/ BAT0/capacity 116 power_supply/ hid-00: 12:a1:63: a8:50-battery/ capacity 63
/sys/class/
/sys/class/
The key thing is to be able to recognise and differentiate the treatment of internal laptop batteries (of which there can be more than one) from external device batteries (mice, keyboard, headphones, etc.).
It may be that the simplest most flexible solution would be to add an option to the Power Settings GUI that allows the user to make an intelligent decision as to which battery/batteries they wish to be considered as the primaries for purposes of the indicator icon.