[gnome-settings-daemon/wip/hadess/force-screensaver-power-saver: 1/2] power: Dim screen faster if power saver mode is on
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/wip/hadess/force-screensaver-power-saver: 1/2] power: Dim screen faster if power saver mode is on
- Date: Thu, 29 Jul 2021 10:46:21 +0000 (UTC)
commit 10c71868cf824bfe8e33b59413693c2870fbaed6
Author: Bastien Nocera <hadess hadess net>
Date: Wed Jul 28 16:40:24 2021 +0200
power: Dim screen faster if power saver mode is on
As done on other platforms, aggressively dim the screen after a
short period when the user has selected to enter power saver mode.
Idle inhibitions are obviously still respected.
Prior art:
https://support.apple.com/en-us/HT205234
plugins/power/gsd-power-manager.c | 40 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
---
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 1f125a6f..f0ed511e 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -192,6 +192,7 @@ struct _GsdPowerManager
/* Power Profiles */
GDBusProxy *power_profiles_proxy;
guint32 power_saver_cookie;
+ gboolean power_saver_enabled;
/* Sound */
guint32 critical_alert_timeout_id;
@@ -1903,7 +1904,8 @@ idle_configure (GsdPowerManager *manager)
/* Don't dim when the screen lock is active */
} else if (!on_battery) {
/* Don't dim when charging */
- } else if (manager->battery_is_low) {
+ } else if (manager->battery_is_low ||
+ manager->power_saver_enabled) {
/* Aggressively blank when battery is low */
timeout_dim = SCREENSAVER_TIMEOUT_BLANK;
} else {
@@ -2165,6 +2167,37 @@ power_profiles_proxy_signal_cb (GDBusProxy *proxy,
manager->power_saver_cookie = 0;
}
+static void
+update_active_power_profile (GsdPowerManager *manager)
+{
+ g_autoptr(GVariant) v = NULL;
+ const char *active_profile;
+ gboolean power_saver_enabled;
+
+ v = g_dbus_proxy_get_cached_property (manager->power_profiles_proxy, "ActiveProfile");
+ if (!v)
+ return;
+ active_profile = g_variant_get_string (v, NULL);
+ power_saver_enabled = g_strcmp0 (active_profile, "power-saver") == 0;
+ if (power_saver_enabled != manager->power_saver_enabled) {
+ manager->power_saver_enabled = power_saver_enabled;
+ idle_configure (manager);
+ }
+}
+
+static void
+power_profiles_proxy_properties_changed_cb (GDBusProxy *proxy,
+ GVariant *changed_properties,
+ GStrv invalidated_properties,
+ gpointer user_data)
+{
+ GsdPowerManager *manager = user_data;
+
+ if (!changed_properties)
+ return;
+ update_active_power_profile (manager);
+}
+
static void
power_profiles_proxy_ready_cb (GObject *source_object,
GAsyncResult *res,
@@ -2179,9 +2212,14 @@ power_profiles_proxy_ready_cb (GObject *source_object,
return;
}
+ g_signal_connect (manager->power_profiles_proxy, "g-properties-changed",
+ G_CALLBACK (power_profiles_proxy_properties_changed_cb),
+ manager);
g_signal_connect (manager->power_profiles_proxy, "g-signal",
G_CALLBACK (power_profiles_proxy_signal_cb),
manager);
+
+ update_active_power_profile (manager);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]