diff options
author | Bastien Nocera <hadess@hadess.net> | 2017-04-04 18:20:27 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2017-04-06 16:33:38 +0200 |
commit | 499d05b8370324f319933558bac590e98ad55927 (patch) | |
tree | fa8b7fdbd6f829d06ae695405976ce84fe8e2976 /libupower-glib | |
parent | 4f9230900bdf2ff4fc22373a3a84f10146b9c1a8 (diff) |
all: Add BatteryLevel property
Export approximate battery levels that devices can use, exported by
the kernel as POWER_SUPPLY_CAPACITY_LEVEL_* values.
This avoids bizarrely accurate values showing up in UIs when we only
have ok/warning levels of accuracy in some cases.
https://bugs.freedesktop.org/show_bug.cgi?id=100359
Diffstat (limited to 'libupower-glib')
-rw-r--r-- | libupower-glib/up-device.c | 25 | ||||
-rw-r--r-- | libupower-glib/up-types.h | 3 |
2 files changed, 27 insertions, 1 deletions
diff --git a/libupower-glib/up-device.c b/libupower-glib/up-device.c index 7bce4e0..63ebe12 100644 --- a/libupower-glib/up-device.c +++ b/libupower-glib/up-device.c @@ -90,6 +90,7 @@ enum { PROP_PERCENTAGE, PROP_TEMPERATURE, PROP_WARNING_LEVEL, + PROP_BATTERY_LEVEL, PROP_ICON_NAME, PROP_LAST }; @@ -315,6 +316,8 @@ up_device_to_text (UpDevice *device) kind == UP_DEVICE_KIND_UPS) g_string_append_printf (string, " state: %s\n", up_device_state_to_string (up_exported_device_get_state (priv->proxy_device))); g_string_append_printf (string, " warning-level: %s\n", up_device_level_to_string (up_exported_device_get_warning_level (priv->proxy_device))); + if (up_exported_device_get_battery_level (priv->proxy_device) != UP_DEVICE_LEVEL_NONE) + g_string_append_printf (string, " battery-level: %s\n", up_device_level_to_string (up_exported_device_get_battery_level (priv->proxy_device))); if (kind == UP_DEVICE_KIND_BATTERY) { g_string_append_printf (string, " energy: %g Wh\n", up_exported_device_get_energy (priv->proxy_device)); if (!is_display) @@ -665,6 +668,9 @@ up_device_set_property (GObject *object, guint prop_id, const GValue *value, GPa case PROP_WARNING_LEVEL: up_exported_device_set_warning_level (device->priv->proxy_device, g_value_get_uint (value)); break; + case PROP_BATTERY_LEVEL: + up_exported_device_set_battery_level (device->priv->proxy_device, g_value_get_uint (value)); + break; case PROP_ICON_NAME: up_exported_device_set_icon_name (device->priv->proxy_device, g_value_get_string (value)); break; @@ -776,6 +782,9 @@ up_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe case PROP_WARNING_LEVEL: g_value_set_uint (value, up_exported_device_get_warning_level (device->priv->proxy_device)); break; + case PROP_BATTERY_LEVEL: + g_value_set_uint (value, up_exported_device_get_battery_level (device->priv->proxy_device)); + break; case PROP_ICON_NAME: g_value_set_string (value, up_exported_device_get_icon_name (device->priv->proxy_device)); break; @@ -1150,6 +1159,22 @@ up_device_class_init (UpDeviceClass *klass) G_PARAM_READWRITE)); /** + * UpDevice:battery-level: + * + * The battery level. + * + * Since: 1.0 + **/ + g_object_class_install_property (object_class, + PROP_BATTERY_LEVEL, + g_param_spec_uint ("battery-level", + NULL, NULL, + UP_DEVICE_LEVEL_UNKNOWN, + UP_DEVICE_LEVEL_LAST, + UP_DEVICE_LEVEL_NONE, + G_PARAM_READWRITE)); + + /** * UpDevice:icon-name: * * The icon name, following the Icon Naming Speficiation diff --git a/libupower-glib/up-types.h b/libupower-glib/up-types.h index 3509537..6d34970 100644 --- a/libupower-glib/up-types.h +++ b/libupower-glib/up-types.h @@ -86,7 +86,8 @@ typedef enum { /** * UpDeviceLevel: * - * The level of a battery. + * The level of a battery. Some values are only relevant to the WarningLevel + * property, some others to the BatteryLevel property. **/ typedef enum { UP_DEVICE_LEVEL_UNKNOWN, |