daemon: Add small hack for keyboards and mice

Imported from gnome-settings-daemon, itself from
gnome-power-manager.
This commit is contained in:
Bastien Nocera 2013-10-11 16:05:16 +02:00
parent 0da46209f3
commit 87709f709a
3 changed files with 20 additions and 4 deletions

View file

@ -447,13 +447,27 @@ up_daemon_set_warning_level (UpDaemon *daemon, UpDeviceLevel warning_level)
}
UpDeviceLevel
up_daemon_compute_warning_level(UpDaemon *daemon,
gboolean power_supply,
gdouble percentage,
gint64 time_to_empty)
up_daemon_compute_warning_level (UpDaemon *daemon,
UpDeviceKind kind,
gboolean power_supply,
gdouble percentage,
gint64 time_to_empty)
{
gboolean use_percentage = TRUE;
/* Keyboard and mice usually have a coarser
* battery level, so this avoids falling directly
* into critical (or off) before any warnings */
if (kind == UP_DEVICE_KIND_MOUSE ||
kind == UP_DEVICE_KIND_KEYBOARD) {
if (percentage < 13.0f)
return UP_DEVICE_LEVEL_CRITICAL;
else if (percentage < 26.0f)
return UP_DEVICE_LEVEL_LOW;
else
return UP_DEVICE_LEVEL_NONE;
}
if (!power_supply || !daemon->priv->use_percentage_for_policy)
use_percentage = FALSE;

View file

@ -84,6 +84,7 @@ void up_daemon_set_on_battery (UpDaemon *daemon,
void up_daemon_set_warning_level (UpDaemon *daemon,
UpDeviceLevel warning_level);
UpDeviceLevel up_daemon_compute_warning_level(UpDaemon *daemon,
UpDeviceKind kind,
gboolean power_supply,
gdouble percentage,
gint64 time_to_empty);

View file

@ -182,6 +182,7 @@ update_warning_level (UpDevice *device)
warning_level = UP_DEVICE_LEVEL_NONE;
else
warning_level = up_daemon_compute_warning_level (device->priv->daemon,
device->priv->type,
device->priv->power_supply,
device->priv->percentage,
device->priv->time_to_empty);