Blame SOURCES/0001-power-Respect-the-nothing-power-button-action-for-VM.patch

083d65
From f71fb47c3f783f3405bd910e1e170dc5e1f10e7c Mon Sep 17 00:00:00 2001
083d65
From: Felipe Borges <felipeborges@gnome.org>
083d65
Date: Wed, 4 Jan 2023 13:41:31 +0100
083d65
Subject: [PATCH] power: Respect the "nothing" power-button-action for VMs
083d65
083d65
There are use-cases when one wants to forcefully make the guest ignore
083d65
poweroff requests from the hypervisor.
083d65
083d65
See https://bugzilla.redhat.com/2062051
083d65
083d65
See also https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/issues/46
083d65
---
083d65
 ....gnome.settings-daemon.plugins.power.gschema.xml.in |  2 +-
083d65
 plugins/media-keys/gsd-media-keys-manager.c            | 10 +++++++---
083d65
 2 files changed, 8 insertions(+), 4 deletions(-)
083d65
083d65
diff --git a/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in b/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
083d65
index 04b287bd..e1a8787b 100644
083d65
--- a/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
083d65
+++ b/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
083d65
@@ -39,7 +39,7 @@
083d65
     <key name="power-button-action" enum="org.gnome.settings-daemon.GsdPowerButtonActionType">
083d65
       <default>'suspend'</default>
083d65
       <summary>Power button action</summary>
083d65
-      <description>The action to take when the system power button is pressed. This action is hard-coded (and the setting ignored) on virtual machines (power off) and tablets (suspend).</description>
083d65
+      <description>The action to take when the system power button is pressed. Virtual machines only honor the 'nothing' action, and will shutdown otherwise. Tablets always suspend, ignoring all the other action options.</description>
083d65
     </key>
083d65
     <key name="power-saver-profile-on-low-battery" type="b">
083d65
       <default>true</default>
083d65
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
083d65
index 15e96e0e..60ff2ced 100644
083d65
--- a/plugins/media-keys/gsd-media-keys-manager.c
083d65
+++ b/plugins/media-keys/gsd-media-keys-manager.c
083d65
@@ -2041,13 +2041,17 @@ do_config_power_button_action (GsdMediaKeysManager *manager,
083d65
         if (priv->power_button_disabled)
083d65
                 return;
083d65
 
083d65
-        /* Always power off VMs when power off is pressed in the menus */
083d65
+        action_type = g_settings_get_enum (priv->power_settings, "power-button-action");
083d65
+        /* Always power off VMs, except when power-button-action is "nothing" */
083d65
         if (g_strcmp0 (priv->chassis_type, "vm") == 0) {
083d65
-                power_action (manager, "PowerOff", !in_lock_screen);
083d65
+                g_warning_once ("Virtual machines only honor the 'nothing' power-button-action, and will shutdown otherwise");
083d65
+
083d65
+                if (action_type != GSD_POWER_BUTTON_ACTION_NOTHING)
083d65
+                        power_action (manager, "PowerOff", FALSE);
083d65
+
083d65
                 return;
083d65
         }
083d65
 
083d65
-        action_type = g_settings_get_enum (priv->power_settings, "power-button-action");
083d65
         switch (action_type) {
083d65
         case GSD_POWER_BUTTON_ACTION_SUSPEND:
083d65
                 action = GSD_POWER_ACTION_SUSPEND;
083d65
-- 
083d65
2.37.1
083d65