Blob Blame History Raw
From f9c12c90d84a3b79321e983d90e40e01ce54e3fa Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Wed, 6 Nov 2013 17:54:53 +0100
Subject: [PATCH 3/3] media-keys: Allow the power key in more places

We allow using the power key pretty much everywhere now, but
we also ensure that we never show interactive dialogues on the
lock screen (something that was possible with other suspend/power
buttons already if more than more than one user was logged in,
or an interactive shutdown was configured).

See https://bugzilla.redhat.com/show_bug.cgi?id=980692

https://bugzilla.gnome.org/show_bug.cgi?id=707095
---
 plugins/media-keys/gsd-media-keys-manager.c | 37 ++++++++++++++++++++---------
 plugins/media-keys/shortcuts-list.h         | 23 ++++++++++++++----
 2 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index cab4aa2..6609165 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -1767,11 +1767,12 @@ do_toggle_contrast_action (GsdMediaKeysManager *manager)
 
 static void
 power_action (GsdMediaKeysManager *manager,
-              const char          *action)
+              const char          *action,
+              gboolean             allow_interaction)
 {
         g_dbus_proxy_call (manager->priv->logind_proxy,
                            action,
-                           g_variant_new ("(b)", TRUE),
+                           g_variant_new ("(b)", allow_interaction),
                            G_DBUS_CALL_FLAGS_NONE,
                            G_MAXINT,
                            manager->priv->bus_cancellable,
@@ -1780,7 +1781,8 @@ power_action (GsdMediaKeysManager *manager,
 
 static void
 do_config_power_action (GsdMediaKeysManager *manager,
-                        const gchar *config_key)
+                        const gchar *config_key,
+                        gboolean in_lock_screen)
 {
         GsdPowerActionType action_type;
 
@@ -1788,16 +1790,17 @@ do_config_power_action (GsdMediaKeysManager *manager,
                                            config_key);
         switch (action_type) {
         case GSD_POWER_ACTION_SUSPEND:
-                power_action (manager, "Suspend");
+                power_action (manager, "Suspend", !in_lock_screen);
                 break;
         case GSD_POWER_ACTION_INTERACTIVE:
-                gnome_session_shutdown (manager);
+                if (!in_lock_screen)
+                        gnome_session_shutdown (manager);
                 break;
         case GSD_POWER_ACTION_SHUTDOWN:
-                power_action (manager, "PowerOff");
+                power_action (manager, "PowerOff", !in_lock_screen);
                 break;
         case GSD_POWER_ACTION_HIBERNATE:
-                power_action (manager, "Hibernate");
+                power_action (manager, "Hibernate", !in_lock_screen);
                 break;
         case GSD_POWER_ACTION_BLANK:
         case GSD_POWER_ACTION_NOTHING:
@@ -2064,16 +2067,28 @@ do_action (GsdMediaKeysManager *manager,
 		do_toggle_contrast_action (manager);
 		break;
         case POWER_KEY:
-                do_config_power_action (manager, "button-power");
+                do_config_power_action (manager, "button-power", FALSE);
                 break;
         case SLEEP_KEY:
-                do_config_power_action (manager, "button-sleep");
+                do_config_power_action (manager, "button-sleep", FALSE);
                 break;
         case SUSPEND_KEY:
-                do_config_power_action (manager, "button-suspend");
+                do_config_power_action (manager, "button-suspend", FALSE);
                 break;
         case HIBERNATE_KEY:
-                do_config_power_action (manager, "button-hibernate");
+                do_config_power_action (manager, "button-hibernate", FALSE);
+                break;
+        case POWER_KEY_NO_DIALOG:
+                do_config_power_action (manager, "button-power", TRUE);
+                break;
+        case SLEEP_KEY_NO_DIALOG:
+                do_config_power_action (manager, "button-sleep", TRUE);
+                break;
+        case SUSPEND_KEY_NO_DIALOG:
+                do_config_power_action (manager, "button-suspend", TRUE);
+                break;
+        case HIBERNATE_KEY_NO_DIALOG:
+                do_config_power_action (manager, "button-hibernate", TRUE);
                 break;
         case SCREEN_BRIGHTNESS_UP_KEY:
         case SCREEN_BRIGHTNESS_DOWN_KEY:
diff --git a/plugins/media-keys/shortcuts-list.h b/plugins/media-keys/shortcuts-list.h
index 1ac0798..a2e6638 100644
--- a/plugins/media-keys/shortcuts-list.h
+++ b/plugins/media-keys/shortcuts-list.h
@@ -75,6 +75,10 @@ typedef enum {
         SLEEP_KEY,
         SUSPEND_KEY,
         HIBERNATE_KEY,
+        POWER_KEY_NO_DIALOG,
+        SLEEP_KEY_NO_DIALOG,
+        SUSPEND_KEY_NO_DIALOG,
+        HIBERNATE_KEY_NO_DIALOG,
         SCREEN_BRIGHTNESS_UP_KEY,
         SCREEN_BRIGHTNESS_DOWN_KEY,
         KEYBOARD_BRIGHTNESS_UP_KEY,
@@ -88,6 +92,11 @@ typedef enum {
 #define GSD_KEYBINDING_MODE_LAUNCHER (SHELL_KEYBINDING_MODE_NORMAL | \
                                       SHELL_KEYBINDING_MODE_OVERVIEW)
 #define SCREENSAVER_MODE SHELL_KEYBINDING_MODE_ALL & ~SHELL_KEYBINDING_MODE_UNLOCK_SCREEN
+#define POWER_KEYS_MODE (SHELL_KEYBINDING_MODE_NORMAL | \
+			 SHELL_KEYBINDING_MODE_OVERVIEW | \
+			 SHELL_KEYBINDING_MODE_LOGIN_SCREEN)
+#define POWER_KEYS_MODE_NO_DIALOG (SHELL_KEYBINDING_MODE_LOCK_SCREEN | \
+				   SHELL_KEYBINDING_MODE_UNLOCK_SCREEN)
 
 static struct {
         MediaKeyType key_type;
@@ -145,12 +154,18 @@ static struct {
         { TOGGLE_CONTRAST_KEY, "toggle-contrast", NULL, NULL, SHELL_KEYBINDING_MODE_ALL },
         { MAGNIFIER_ZOOM_IN_KEY, "magnifier-zoom-in", NULL, NULL, SHELL_KEYBINDING_MODE_ALL },
         { MAGNIFIER_ZOOM_OUT_KEY, "magnifier-zoom-out", NULL, NULL, SHELL_KEYBINDING_MODE_ALL },
-        { POWER_KEY, NULL, N_("Power Off"), "XF86PowerOff", GSD_KEYBINDING_MODE_LAUNCHER },
+        { POWER_KEY, NULL, N_("Power Off"), "XF86PowerOff", POWER_KEYS_MODE },
         /* the kernel / Xorg names really are like this... */
         /* translators: "Sleep" means putting the machine to sleep, either through hibernate or suspend */
-        { SLEEP_KEY, NULL, N_("Sleep"), "XF86Suspend", SHELL_KEYBINDING_MODE_ALL },
-        { SUSPEND_KEY, NULL, N_("Suspend"), "XF86Sleep", SHELL_KEYBINDING_MODE_ALL },
-        { HIBERNATE_KEY, NULL, N_("Hibernate"), "XF86Hibernate", SHELL_KEYBINDING_MODE_ALL },
+        { SLEEP_KEY, NULL, N_("Sleep"), "XF86Suspend", POWER_KEYS_MODE },
+        { SUSPEND_KEY, NULL, N_("Suspend"), "XF86Sleep", POWER_KEYS_MODE },
+        { HIBERNATE_KEY, NULL, N_("Hibernate"), "XF86Hibernate", POWER_KEYS_MODE },
+        { POWER_KEY_NO_DIALOG, NULL, N_("Power Off"), "XF86PowerOff", POWER_KEYS_MODE_NO_DIALOG },
+        /* the kernel / Xorg names really are like this... */
+        /* translators: "Sleep" means putting the machine to sleep, either through hibernate or suspend */
+        { SLEEP_KEY_NO_DIALOG, NULL, N_("Sleep"), "XF86Suspend", POWER_KEYS_MODE_NO_DIALOG },
+        { SUSPEND_KEY_NO_DIALOG, NULL, N_("Suspend"), "XF86Sleep", POWER_KEYS_MODE_NO_DIALOG },
+        { HIBERNATE_KEY_NO_DIALOG, NULL, N_("Hibernate"), "XF86Hibernate", POWER_KEYS_MODE_NO_DIALOG },
         { SCREEN_BRIGHTNESS_UP_KEY, NULL, N_("Brightness Up"), "XF86MonBrightnessUp", SHELL_KEYBINDING_MODE_ALL },
         { SCREEN_BRIGHTNESS_DOWN_KEY, NULL, N_("Brightness Down"), "XF86MonBrightnessDown", SHELL_KEYBINDING_MODE_ALL },
         { KEYBOARD_BRIGHTNESS_UP_KEY, NULL, N_("Keyboard Brightness Up"), "XF86KbdBrightnessUp", SHELL_KEYBINDING_MODE_ALL },
-- 
1.8.4.2