summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Borges <felipeborges@gnome.org>2023-01-04 13:41:31 +0100
committerFelipe Borges <felipeborges@gnome.org>2023-01-17 11:55:32 +0100
commitf71fb47c3f783f3405bd910e1e170dc5e1f10e7c (patch)
tree9e1da2f45a8849c9192f84ea0e5dabc522c42f29
parent0ad4e34c54d848481adeabb46ff8c78789daf1b9 (diff)
downloadgnome-settings-daemon-power-respect-nothing-power-button-action-for-vms.tar.gz
power: Respect the "nothing" power-button-action for VMspower-respect-nothing-power-button-action-for-vms
There are use-cases when one wants to forcefully make the guest ignore poweroff requests from the hypervisor. See https://bugzilla.redhat.com/2062051 See also https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/issues/46
-rw-r--r--data/org.gnome.settings-daemon.plugins.power.gschema.xml.in2
-rw-r--r--plugins/media-keys/gsd-media-keys-manager.c10
2 files changed, 8 insertions, 4 deletions
diff --git a/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in b/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
index 04b287bd..e1a8787b 100644
--- a/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
+++ b/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
@@ -39,7 +39,7 @@
<key name="power-button-action" enum="org.gnome.settings-daemon.GsdPowerButtonActionType">
<default>'suspend'</default>
<summary>Power button action</summary>
- <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>
+ <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>
</key>
<key name="power-saver-profile-on-low-battery" type="b">
<default>true</default>
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index 15e96e0e..60ff2ced 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -2041,13 +2041,17 @@ do_config_power_button_action (GsdMediaKeysManager *manager,
if (priv->power_button_disabled)
return;
- /* Always power off VMs when power off is pressed in the menus */
+ action_type = g_settings_get_enum (priv->power_settings, "power-button-action");
+ /* Always power off VMs, except when power-button-action is "nothing" */
if (g_strcmp0 (priv->chassis_type, "vm") == 0) {
- power_action (manager, "PowerOff", !in_lock_screen);
+ g_warning_once ("Virtual machines only honor the 'nothing' power-button-action, and will shutdown otherwise");
+
+ if (action_type != GSD_POWER_BUTTON_ACTION_NOTHING)
+ power_action (manager, "PowerOff", FALSE);
+
return;
}
- action_type = g_settings_get_enum (priv->power_settings, "power-button-action");
switch (action_type) {
case GSD_POWER_BUTTON_ACTION_SUSPEND:
action = GSD_POWER_ACTION_SUSPEND;