diff options
-rw-r--r-- | data/org.ayatana.indicator.power.Battery.xml | 16 | ||||
-rw-r--r-- | src/notifier.c | 18 |
2 files changed, 34 insertions, 0 deletions
diff --git a/data/org.ayatana.indicator.power.Battery.xml b/data/org.ayatana.indicator.power.Battery.xml index 3bf6959..f8d20c5 100644 --- a/data/org.ayatana.indicator.power.Battery.xml +++ b/data/org.ayatana.indicator.power.Battery.xml @@ -11,6 +11,14 @@ </doc:doc> </property> + <property name="PowerPercentage" type="i" access="read"> + <doc:doc> + <doc:description> + <doc:para>The battery's power level in percentage.</doc:para> + </doc:description> + </doc:doc> + </property> + <property name="IsWarning" type="b" access="read"> <doc:doc> <doc:description> @@ -19,5 +27,13 @@ </doc:doc> </property> + <property name="IsDischarging" type="b" access="read"> + <doc:doc> + <doc:description> + <doc:para>Whether or not the battery is discharging</doc:para> + </doc:description> + </doc:doc> + </property> + </interface> </node> diff --git a/src/notifier.c b/src/notifier.c index 8362eb6..07c5efa 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -147,6 +147,19 @@ get_battery_power_level (IndicatorPowerDevice * battery) return ret; } +static gdouble +get_battery_power_percentage (IndicatorPowerDevice * battery) +{ + gdouble ret; + + g_return_val_if_fail(battery != NULL, 0); + g_return_val_if_fail(indicator_power_device_get_kind(battery) == UP_DEVICE_KIND_BATTERY, 0); + + ret = indicator_power_device_get_percentage(battery); + + return ret; +} + /*** **** Sounds ***/ @@ -366,6 +379,7 @@ on_battery_property_changed (IndicatorPowerNotifier * self) PowerLevel new_power_level; gboolean old_discharging; gboolean new_discharging; + gdouble new_percentage; g_return_if_fail(INDICATOR_IS_POWER_NOTIFIER(self)); p = get_priv (self); @@ -377,6 +391,8 @@ on_battery_property_changed (IndicatorPowerNotifier * self) old_discharging = p->discharging; new_discharging = indicator_power_device_get_state(p->battery) == UP_DEVICE_STATE_DISCHARGING; + new_percentage = get_battery_power_percentage (p->battery); + /* pop up a 'low battery' notification if either: a) it's already discharging, and its PowerLevel worsens, OR b) it's already got a bad PowerLevel and its state becomes 'discharging */ @@ -391,6 +407,8 @@ on_battery_property_changed (IndicatorPowerNotifier * self) } dbus_battery_set_power_level (p->dbus_battery, power_level_to_dbus_string (new_power_level)); + dbus_battery_set_power_percentage (p->dbus_battery, new_percentage); + dbus_battery_set_is_discharging (p->dbus_battery, new_discharging); p->power_level = new_power_level; p->discharging = new_discharging; } |