[gnome-settings-daemon] media-keys: Allow the power key in more places



commit b7827c13d823c9ac82d8187e09c4c043e72755d2
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Nov 6 17:54:53 2013 +0100

    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 05e5c9b..bb0ca5e 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -1808,11 +1808,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,
@@ -1821,7 +1822,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;
 
@@ -1829,16 +1831,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_LOGOUT:
@@ -2154,16 +2157,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 943f12b..ab906a6 100644
--- a/plugins/media-keys/shortcuts-list.h
+++ b/plugins/media-keys/shortcuts-list.h
@@ -77,6 +77,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,
@@ -90,6 +94,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;
@@ -150,12 +159,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 },


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