diff options
Diffstat (limited to 'plugins/power/gsd-power-manager.c')
-rw-r--r-- | plugins/power/gsd-power-manager.c | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c index fde90eff..346bd9fb 100644 --- a/plugins/power/gsd-power-manager.c +++ b/plugins/power/gsd-power-manager.c @@ -27,7 +27,6 @@ #include <string.h> #include <glib/gi18n.h> #include <gtk/gtk.h> -#define UPOWER_ENABLE_DEPRECATED 1 #include <libupower-glib/upower.h> #include <libnotify/notify.h> #include <canberra-gtk.h> @@ -1164,18 +1163,37 @@ static GsdPowerActionType manager_critical_action_get (GsdPowerManager *manager, gboolean is_ups) { - GsdPowerActionType policy; + GsdPowerActionType policy = GSD_POWER_ACTION_SHUTDOWN; + GVariant *result = NULL; policy = g_settings_get_enum (manager->priv->settings, "critical-battery-action"); + if (policy == GSD_POWER_ACTION_SUSPEND) { - if (is_ups == FALSE && - up_client_get_can_suspend (manager->priv->up_client)) - return policy; - return GSD_POWER_ACTION_SHUTDOWN; + if (is_ups == FALSE) { + result = g_dbus_proxy_call_sync (manager->priv->logind_proxy, + "CanSuspend", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL); + } } else if (policy == GSD_POWER_ACTION_HIBERNATE) { - if (up_client_get_can_hibernate (manager->priv->up_client)) - return policy; - return GSD_POWER_ACTION_SHUTDOWN; + result = g_dbus_proxy_call_sync (manager->priv->logind_proxy, + "CanHibernate", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL); + } else { + /* Other actions need no check */ + return policy; + } + + if (result) { + const char *s; + + g_variant_get (result, "(s)", &s); + if (g_strcmp0 (s, "yes") != 0) + policy = GSD_POWER_ACTION_SHUTDOWN; + g_variant_unref (result); } return policy; |