aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarius Gripsgard <mariogrip@debian.org>2023-09-18 01:11:26 +0200
committerMarius Gripsgard <mariogrip@debian.org>2023-09-18 01:11:26 +0200
commitb794ebd02031baa6c9b1cffa8e298c41ad24416f (patch)
tree94bfc3ba78af597d56fe910aac950e41d44d4e26 /src
parent2aefd8473fd942c7efb65a2cd691925c0d7a35e3 (diff)
downloadayatana-indicator-power-b794ebd02031baa6c9b1cffa8e298c41ad24416f.tar.gz
ayatana-indicator-power-b794ebd02031baa6c9b1cffa8e298c41ad24416f.tar.bz2
ayatana-indicator-power-b794ebd02031baa6c9b1cffa8e298c41ad24416f.zip
dbus: Add power percentage and is dischargingpersonal/mariogrip/dbus-updates
This exposes power percentage and is discharging to the dbus interface.
Diffstat (limited to 'src')
-rw-r--r--src/notifier.c18
1 files changed, 18 insertions, 0 deletions
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;
}