aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2023-10-02 23:18:52 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2023-10-02 23:18:52 +0200
commit2e602b9f5b865d45dcd9f2503cca765e447d5b03 (patch)
tree94bfc3ba78af597d56fe910aac950e41d44d4e26
parent2aefd8473fd942c7efb65a2cd691925c0d7a35e3 (diff)
parentb794ebd02031baa6c9b1cffa8e298c41ad24416f (diff)
downloadayatana-indicator-power-2e602b9f5b865d45dcd9f2503cca765e447d5b03.tar.gz
ayatana-indicator-power-2e602b9f5b865d45dcd9f2503cca765e447d5b03.tar.bz2
ayatana-indicator-power-2e602b9f5b865d45dcd9f2503cca765e447d5b03.zip
Merge branch 'personal/mariogrip/dbus-updates'
Attributes GH PR #87: https://github.com/AyatanaIndicators/ayatana-indicator-power/pull/87
-rw-r--r--data/org.ayatana.indicator.power.Battery.xml16
-rw-r--r--src/notifier.c18
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;
}