From 80466432a003431c6c8319a3ad90a52b765fc082 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Wed, 4 Dec 2024 16:50:16 +0100 Subject: [PATCH] gpm-kbd-backlight: Rationalize handling of battery-reduce setting Handling of a disabled battery-reduce setting was too aggressive, which could reduce in not setting backlight value in unrelated cases, including initial startup and resume, as well as some cases of IDLE handling. Now the user choices are better followed, the whole special-casing could probably be removed as the internal state should always reflect the reality, but keep the specific check not to do anything on AC plug/unplug when this is disabled just in case, although the historical reasons why it was actually problematic should be gone now. --- src/gpm-kbd-backlight.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/gpm-kbd-backlight.c b/src/gpm-kbd-backlight.c index 426a987b..7adf0a8f 100644 --- a/src/gpm-kbd-backlight.c +++ b/src/gpm-kbd-backlight.c @@ -383,13 +383,9 @@ gpm_kbd_backlight_evaluate_power_source_and_set (GpmKbdBacklight *backlight) guint value; guint dim_by = 0; - if (up_client_get_on_battery (backlight->priv->client)) { - if (g_settings_get_boolean (backlight->priv->settings, GPM_SETTINGS_KBD_BACKLIGHT_BATT_REDUCE)) { - dim_by = g_settings_get_int (backlight->priv->settings, GPM_SETTINGS_KBD_BRIGHTNESS_DIM_BY_ON_BATT); - } else { - // do not change keyboard backlight - return TRUE; - } + if (up_client_get_on_battery (backlight->priv->client) && + g_settings_get_boolean (backlight->priv->settings, GPM_SETTINGS_KBD_BACKLIGHT_BATT_REDUCE)) { + dim_by = g_settings_get_int (backlight->priv->settings, GPM_SETTINGS_KBD_BRIGHTNESS_DIM_BY_ON_BATT); } value = gpm_kbd_backlight_get_ac_percentage_dimmed (backlight, dim_by); @@ -428,7 +424,9 @@ gpm_kbd_backlight_client_changed_cb (UpClient *client, GParamSpec *pspec, GpmKbdBacklight *backlight) { - gpm_kbd_backlight_evaluate_power_source_and_set (backlight); + if (g_settings_get_boolean (backlight->priv->settings, GPM_SETTINGS_KBD_BACKLIGHT_BATT_REDUCE)) { + gpm_kbd_backlight_evaluate_power_source_and_set (backlight); + } } /** @@ -513,7 +511,6 @@ gpm_kbd_backlight_idle_changed_cb (GpmIdle *idle, enable_action = up_client_get_on_battery (backlight->priv->client) ? g_settings_get_boolean (backlight->priv->settings, GPM_SETTINGS_IDLE_DIM_BATT) - && g_settings_get_boolean (backlight->priv->settings, GPM_SETTINGS_KBD_BACKLIGHT_BATT_REDUCE) : g_settings_get_boolean (backlight->priv->settings, GPM_SETTINGS_IDLE_DIM_AC); if (!enable_action)