[gnome-settings-daemon/wip/hadess/force-screensaver-power-saver: 2/4] 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: 2/4] power: Dim screen faster if power saver mode is on
- Date: Mon, 9 Aug 2021 16:03:10 +0000 (UTC)
commit 61e2027e9f7b0db62c4d904becf5db3e5a1fdbcb
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.
The same aggressive screen dim will be used if the battery is low and
power-profiles-daemon is not available. If it is available, then it
fixes a screen dim happening when the battery was low which might
have been unwanted.
See https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/232
Prior art:
https://support.apple.com/en-us/HT205234
plugins/power/gsd-power-manager.c | 52 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
---
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 1f125a6f..5f5b0dd8 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;
@@ -1780,6 +1781,19 @@ clear_idle_watch (GnomeIdleMonitor *monitor,
*id = 0;
}
+static gboolean
+should_dim_hard (GsdPowerManager *manager)
+{
+ if (!manager->power_profiles_proxy) {
+ /* When power-profiles-daemon isn't available,
+ * dim hard when low on battery */
+ return manager->battery_is_low;
+ }
+
+ /* dim hard in power-saver mode */
+ return manager->power_saver_enabled;
+}
+
static void
idle_configure (GsdPowerManager *manager)
{
@@ -1903,7 +1917,7 @@ 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 (should_dim_hard (manager)) {
/* Aggressively blank when battery is low */
timeout_dim = SCREENSAVER_TIMEOUT_BLANK;
} else {
@@ -2165,6 +2179,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 +2224,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]