[gnome-settings-daemon/benzea/interactive-power-action-fallback] media-keys: always do something when power button is pressed...



commit 0a1105fb8bc21ede955b5a936cac0dd1b908c01a
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Fri Sep 9 17:09:28 2016 -0500

    media-keys: always do something when power button is pressed...
    
    ...unless the power button action is actually set to NOTHING.
    
    By default, it's set to suspend, but the user's computer might not
    support suspend. Instead of doing nothing at all, fall back to
    displaying the interactive shutdown dialog instead.
    
    This doesn't require any UI changes, because the control-center option
    for power button action is now only displayed for computers that do
    support suspend (since GNOME #764508).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=771552

 plugins/media-keys/gsd-media-keys-manager.c | 61 +++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 4 deletions(-)
---
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index 539158cc..1576b61c 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -2023,11 +2023,59 @@ do_config_power_action (GsdMediaKeysManager *manager,
         }
 }
 
+static gboolean
+supports_power_action (GsdMediaKeysManager *manager,
+                       GsdPowerActionType   action_type)
+{
+        const char *method_name = NULL;
+        g_autoptr(GVariant) variant = NULL;
+        const char *reply;
+        gboolean result = FALSE;
+
+        switch (action_type) {
+        case GSD_POWER_ACTION_SUSPEND:
+                method_name = "CanSuspend";
+                break;
+        case GSD_POWER_ACTION_SHUTDOWN:
+                method_name = "CanPowerOff";
+                break;
+        case GSD_POWER_ACTION_HIBERNATE:
+                method_name = "CanHibernate";
+                break;
+        case GSD_POWER_ACTION_INTERACTIVE:
+        case GSD_POWER_ACTION_BLANK:
+        case GSD_POWER_ACTION_LOGOUT:
+        case GSD_POWER_ACTION_NOTHING:
+                break;
+        }
+
+        if (method_name == NULL)
+                return FALSE;
+
+        variant = g_dbus_proxy_call_sync (manager->priv->logind_proxy,
+                                          method_name,
+                                          NULL,
+                                          G_DBUS_CALL_FLAGS_NONE,
+                                          -1,
+                                          manager->priv->bus_cancellable,
+                                          NULL);
+
+        if (variant == NULL)
+                return FALSE;
+
+        g_variant_get (variant, "(&s)", &reply);
+        if (g_strcmp0 (reply, "yes") == 0)
+                result = TRUE;
+
+        return result;
+}
+
 static void
 do_config_power_button_action (GsdMediaKeysManager *manager,
                                gboolean             in_lock_screen)
 {
         GsdPowerButtonActionType action_type;
+        GsdPowerActionType action;
 
         if (manager->priv->power_button_disabled)
                 return;
@@ -2047,18 +2095,23 @@ do_config_power_button_action (GsdMediaKeysManager *manager,
         action_type = g_settings_get_enum (manager->priv->power_settings, "power-button-action");
         switch (action_type) {
         case GSD_POWER_BUTTON_ACTION_SUSPEND:
-                do_config_power_action (manager, GSD_POWER_ACTION_SUSPEND, in_lock_screen);
+                action = GSD_POWER_ACTION_SUSPEND;
                 break;
         case GSD_POWER_BUTTON_ACTION_HIBERNATE:
-                do_config_power_action (manager, GSD_POWER_ACTION_HIBERNATE, in_lock_screen);
+                action = GSD_POWER_ACTION_HIBERNATE;
                 break;
         case GSD_POWER_BUTTON_ACTION_INTERACTIVE:
-                do_config_power_action (manager, GSD_POWER_ACTION_INTERACTIVE, in_lock_screen);
+                action = GSD_POWER_ACTION_INTERACTIVE;
                 break;
         case GSD_POWER_BUTTON_ACTION_NOTHING:
                 /* do nothing */
-                break;
+                return;
         }
+
+        if (action != GSD_POWER_ACTION_INTERACTIVE && !supports_power_action (manager, action))
+                action = GSD_POWER_ACTION_INTERACTIVE;
+
+        do_config_power_action (manager, action, in_lock_screen);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]