Skip to content

Commit 8165fc6

Browse files
authored
csd-power-manager.c: Sent property updates when the percentage (#438)
changes, not just an icon. Commit c2c7609 removed the Tooltip property from csd-power. We weren't making use of that property anywhere in Cinnamon, but it was doing the work of triggering updates there whenever the battery percentage changed, keeping the applet up-to-date in between actual icon changes. There's no point in reverting everything - most is string handling that we still don't need. Instead, implement a simple percentage monitor and dbus Property to trigger updates for clients. Fixes linuxmint/cinnamon#13324.
1 parent 7e9a980 commit 8165fc6

2 files changed

Lines changed: 54 additions & 4 deletions

File tree

plugins/power/csd-power-manager.c

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ struct CsdPowerManagerPrivate
156156
GnomeRRScreen *x11_screen;
157157
gboolean use_time_primary;
158158
GIcon *previous_icon;
159+
guint previous_percentage;
159160
GpmPhone *phone;
160161
GPtrArray *devices_array;
161162
guint action_percentage;
@@ -379,7 +380,8 @@ typedef enum {
379380

380381
static void
381382
engine_emit_changed (CsdPowerManager *manager,
382-
gboolean icon_changed)
383+
gboolean icon_changed,
384+
gboolean percentage_changed)
383385
{
384386
/* not yet connected to the bus */
385387
if (manager->priv->power_iface == NULL)
@@ -401,6 +403,12 @@ engine_emit_changed (CsdPowerManager *manager,
401403
g_object_unref (gicon);
402404
}
403405

406+
if (percentage_changed) {
407+
csd_power_set_percentage (manager->priv->power_iface,
408+
manager->priv->previous_percentage);
409+
need_flush = TRUE;
410+
}
411+
404412
if (need_flush) {
405413
g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (manager->priv->power_iface));
406414
}
@@ -685,16 +693,56 @@ engine_recalculate_state_icon (CsdPowerManager *manager)
685693
return FALSE;
686694
}
687695

696+
static gboolean
697+
engine_recalculate_state_percentage (CsdPowerManager *manager)
698+
{
699+
guint i;
700+
UpDevice *device;
701+
UpDeviceKind kind;
702+
gboolean is_present;
703+
gdouble percentage;
704+
guint percentage_uint;
705+
GPtrArray *array;
706+
707+
array = manager->priv->devices_array;
708+
for (i = 0; i < array->len; i++) {
709+
device = g_ptr_array_index (array, i);
710+
g_object_get (device,
711+
"kind", &kind,
712+
"is-present", &is_present,
713+
"percentage", &percentage,
714+
NULL);
715+
716+
if (!is_present)
717+
continue;
718+
719+
if (kind == UP_DEVICE_KIND_BATTERY)
720+
device = engine_get_composite_device (manager, device);
721+
722+
g_object_get (device, "percentage", &percentage, NULL);
723+
percentage_uint = (guint) CLAMP (percentage, 0.0, 100.0);
724+
725+
if (manager->priv->previous_percentage != percentage_uint) {
726+
manager->priv->previous_percentage = percentage_uint;
727+
return TRUE;
728+
}
729+
}
730+
731+
return FALSE;
732+
}
733+
688734
static void
689735
engine_recalculate_state (CsdPowerManager *manager)
690736
{
691737
gboolean icon_changed = FALSE;
738+
gboolean percentage_changed = FALSE;
692739

693740
icon_changed = engine_recalculate_state_icon (manager);
741+
percentage_changed = engine_recalculate_state_percentage (manager);
694742

695-
/* only emit if the icon has changed */
696-
if (icon_changed)
697-
engine_emit_changed (manager, icon_changed);
743+
/* emit if the icon or percentage has changed */
744+
if (icon_changed || percentage_changed)
745+
engine_emit_changed (manager, icon_changed, percentage_changed);
698746
}
699747

700748
static UpDevice *

plugins/power/org.cinnamon.SettingsDaemon.Power.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<interface name='org.cinnamon.SettingsDaemon.Power'>
77
<property name='Icon' type='s' access='read'>
88
</property>
9+
<property name='Percentage' type='u' access='read'>
10+
</property>
911
<method name='GetPrimaryDevice'>
1012
<arg name='device' type='(sssusduut)' direction='out' />
1113
</method>

0 commit comments

Comments
 (0)