From 7cd378de95a8a92ee1b87eb5ea0d575c1a51d7a0 Mon Sep 17 00:00:00 2001 From: Jason Andryuk Date: Tue, 3 May 2022 13:39:41 -0400 Subject: [PATCH] xcpmd: Send battery changed when the percent changes xcpmd polls the battery every 4 seconds. When running on battery, *something* will have changed in that time. Even on AC, the values have typically changes such that xcpmd is sending the DBus notification. However, the only thing that the UI cares about is the battery percentage. So check the percentage and only send it if has changed. This avoids xcpmd sending a message, but it also removes multiple DBus queries by the UI for more information. It's a little bit of a micro optimization, but it is also easy. Signed-off-by: Jason Andryuk --- xcpmd/src/battery.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/xcpmd/src/battery.c b/xcpmd/src/battery.c index d08987ba..20e03d37 100644 --- a/xcpmd/src/battery.c +++ b/xcpmd/src/battery.c @@ -911,9 +911,16 @@ void update_batteries(void) { } if ((old_array_size != new_array_size) || (memcmp(old_status, last_status, new_array_size * sizeof(struct battery_status)))) { - //Here for compatibility--should eventually be removed - xenstore_write("1", XS_BATTERY_STATUS_CHANGE_EVENT_PATH); - notify_com_citrix_xenclient_xcpmd_battery_status_changed(xcdbus_conn, XCPMD_SERVICE, XCPMD_PATH, get_overall_battery_percentage()); + static int previous_percent; + int current_percent = get_overall_battery_percentage(); + + if (current_percent != previous_percent) { + previous_percent = current_percent; + //Here for compatibility--should eventually be removed + xenstore_write("1", XS_BATTERY_STATUS_CHANGE_EVENT_PATH); + notify_com_citrix_xenclient_xcpmd_battery_status_changed( + xcdbus_conn, XCPMD_SERVICE, XCPMD_PATH, current_percent); + } } if (present_batteries_changed) {