up-daemon: Propagate charge-threshold-enabled to display device

The property indicates that a device is plugged-in but not charging
because of the charging threshold. Desktops may want to indicate
that state, but the property is currently only exposed on actual
devices, not the virtual display device that is usually exposed
in the interface.

To address this, propagate the property to the display device
if at least one device has charge thresholds enabled.

Related: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5228
This commit is contained in:
Florian Müllner 2025-08-20 21:35:23 +02:00
parent 4d6da1bb0f
commit ff605e51c1
No known key found for this signature in database

View file

@ -61,6 +61,7 @@ struct UpDaemonPrivate
gint64 time_to_empty;
gint64 time_to_full;
gboolean charge_threshold_enabled;
gboolean state_all_discharging;
/* WarningLevel configuration */
@ -149,6 +150,7 @@ up_daemon_update_display_battery (UpDaemon *daemon)
gint64 time_to_empty_total = 0;
gint64 time_to_full_total = 0;
gboolean is_present_total = FALSE;
gboolean charge_threshold_enabled_total = FALSE;
guint num_batteries = 0;
gboolean state_all_discharging = TRUE;
@ -169,6 +171,7 @@ up_daemon_update_display_battery (UpDaemon *daemon)
gint64 time_to_empty = 0;
gint64 time_to_full = 0;
gboolean power_supply = FALSE;
gboolean charge_threshold_enabled = FALSE;
device = g_ptr_array_index (array, i);
g_object_get (device,
@ -182,6 +185,7 @@ up_daemon_update_display_battery (UpDaemon *daemon)
"time-to-empty", &time_to_empty,
"time-to-full", &time_to_full,
"power-supply", &power_supply,
"charge-threshold-enabled", &charge_threshold_enabled,
NULL);
if (!present)
@ -244,6 +248,9 @@ up_daemon_update_display_battery (UpDaemon *daemon)
} else if (state == UP_DEVICE_STATE_DISCHARGING)
state_any_discharging = TRUE;
/* If at least one battery has charge thresholds enabled, propagate that. */
charge_threshold_enabled_total = charge_threshold_enabled_total || charge_threshold_enabled;
/* sum up composite */
kind_total = UP_DEVICE_KIND_BATTERY;
is_present_total = TRUE;
@ -318,6 +325,7 @@ out:
daemon->priv->time_to_empty == time_to_empty_total &&
daemon->priv->time_to_full == time_to_full_total &&
daemon->priv->percentage == percentage_total &&
daemon->priv->charge_threshold_enabled == charge_threshold_enabled_total &&
daemon->priv->state_all_discharging == state_all_discharging)
return FALSE;
@ -331,6 +339,7 @@ out:
daemon->priv->percentage = percentage_total;
daemon->priv->charge_threshold_enabled = charge_threshold_enabled_total;
daemon->priv->state_all_discharging = state_all_discharging;
g_object_set (daemon->priv->display_device,
@ -343,6 +352,7 @@ out:
"time-to-full", time_to_full_total,
"percentage", percentage_total,
"is-present", is_present_total,
"charge-threshold-enabled", charge_threshold_enabled_total,
"power-supply", TRUE,
"update-time", (guint64) g_get_real_time () / G_USEC_PER_SEC,
NULL);