Skip to content

Commit

Permalink
gpm-kbd-backlight: Rationalize handling of battery-reduce setting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cwendling committed Dec 4, 2024
1 parent 0890380 commit 8046643
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/gpm-kbd-backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8046643

Please sign in to comment.