Add downstream default suspend setting for servers

When running "Server with GUI" we want the suspend behavior to not
collide with the desired behavior for laptops and other chassis
types.

A "server" is defined by systemd-hostnamed chassis.

Related: RHEL-30294
This commit is contained in:
Felipe Borges 2024-08-08 14:38:49 +02:00
parent d38b35f673
commit 128bc8a4e3
2 changed files with 108 additions and 0 deletions

View File

@ -25,6 +25,9 @@ License: GPL-2.0-or-later AND LGPL-2.1-or-later
URL: https://gitlab.gnome.org/GNOME/gnome-settings-daemon URL: https://gitlab.gnome.org/GNOME/gnome-settings-daemon
Source0: https://download.gnome.org/sources/%{name}/%{major_version}/%{name}-%{tarball_version}.tar.xz Source0: https://download.gnome.org/sources/%{name}/%{major_version}/%{name}-%{tarball_version}.tar.xz
# https://issues.redhat.com/browse/RHEL-30294
Patch0: power-server-sleep-type-default.patch
BuildRequires: gcc BuildRequires: gcc
BuildRequires: gettext BuildRequires: gettext
BuildRequires: meson >= 0.49.0 BuildRequires: meson >= 0.49.0

View File

@ -0,0 +1,105 @@
From 394cbc30d8093808ddba69c6c709e20f38d9f280 Mon Sep 17 00:00:00 2001
From: Felipe Borges <felipeborges@gnome.org>
Date: Tue, 6 Aug 2024 15:49:21 +0200
Subject: [PATCH] power: Add "sleep-inactive-ac-type-server" as a side
setting for servers
This avoids servers having the defaults from other chassis types.
A "server" is determined by hostnamed chassis-type server.
---
...ttings-daemon.plugins.power.gschema.xml.in | 5 +++++
plugins/power/gsd-power-manager.c | 19 ++++++++++++++-----
2 files changed, 19 insertions(+), 5 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 051bcf70..438cd62b 100644
--- a/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
+++ b/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
@@ -21,6 +21,11 @@
<summary>Whether to hibernate, suspend or do nothing when inactive</summary>
<description>The type of sleeping that should be performed when the computer is inactive.</description>
</key>
+ <key name="sleep-inactive-ac-type-server" enum="org.gnome.settings-daemon.GsdPowerActionType">
+ <default>'nothing'</default>
+ <summary>Whether to hibernate, suspend or do nothing when inactive</summary>
+ <description>The type of sleeping that should be performed when a server is inactive. A server is defined by hostnamed chassis-type.</description>
+ </key>
<key name="sleep-inactive-battery-timeout" type="i">
<default>900</default>
<summary>Sleep timeout computer when on battery</summary>
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 268a46cc..2c2d5f8f 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -223,6 +223,9 @@ struct _GsdPowerManager
/* Device Properties */
gboolean show_sleep_warnings;
+
+ /* hostnamed chassis-type */
+ gchar *chassis_type;
};
enum {
@@ -1915,6 +1918,7 @@ idle_configure (GsdPowerManager *manager)
guint timeout_sleep;
guint timeout_dim;
gboolean on_battery;
+ gboolean on_server = FALSE;
if (!idle_is_session_inhibited (manager,
GSM_INHIBITOR_FLAG_IDLE,
@@ -1961,8 +1965,11 @@ idle_configure (GsdPowerManager *manager)
/* only do the sleep timeout when the session is idle
* and we aren't inhibited from sleeping (or logging out, etc.) */
on_battery = up_client_get_on_battery (manager->up_client);
- action_type = g_settings_get_enum (manager->settings, on_battery ?
- "sleep-inactive-battery-type" : "sleep-inactive-ac-type");
+ on_server = g_strcmp0 (manager->chassis_type, "server") == 0;
+ action_type = g_settings_get_enum (manager->settings,
+ /* Read from "sleep-inactive-ac-type-server when hostnamed chassis-type = "server" */
+ on_server ? "sleep-inactive-ac-type-server" :
+ on_battery ? "sleep-inactive-battery-type" : "sleep-inactive-ac-type");
timeout_sleep = 0;
if (!is_action_inhibited (manager, action_type)) {
gint timeout_sleep_;
@@ -3059,7 +3066,6 @@ gboolean
gsd_power_manager_start (GsdPowerManager *manager,
GError **error)
{
- g_autofree char *chassis_type = NULL;
g_debug ("Starting power manager");
gnome_settings_profile_start (NULL);
@@ -3087,8 +3093,7 @@ gsd_power_manager_start (GsdPowerManager *manager,
return FALSE;
}
- chassis_type = gnome_settings_get_chassis_type ();
- if (g_strcmp0 (chassis_type, "tablet") == 0 || g_strcmp0 (chassis_type, "handset") == 0) {
+ if (g_strcmp0 (manager->chassis_type, "tablet") == 0 || g_strcmp0 (manager->chassis_type, "handset") == 0) {
manager->show_sleep_warnings = FALSE;
} else {
manager->show_sleep_warnings = TRUE;
@@ -3182,6 +3187,8 @@ gsd_power_manager_stop (GsdPowerManager *manager)
g_source_remove (manager->xscreensaver_watchdog_timer_id);
manager->xscreensaver_watchdog_timer_id = 0;
}
+
+ g_clear_pointer (&manager->chassis_type, g_free);
}
static void
@@ -3190,6 +3197,8 @@ gsd_power_manager_init (GsdPowerManager *manager)
manager->inhibit_lid_switch_fd = -1;
manager->inhibit_suspend_fd = -1;
manager->cancellable = g_cancellable_new ();
+
+ manager->chassis_type = gnome_settings_get_chassis_type ();
}
/* returns new level */
--
2.45.2