From 55cd3c20158f71067a60c75c534df42760a8f762 Mon Sep 17 00:00:00 2001 From: Arwed Meyer Date: Thu, 3 Oct 2024 14:49:09 +0200 Subject: Refactor: kbd_backlight: Backlight toggling This improves the fix for backlight toggling from "Keyboard backlight handling improvements". Now saved_brightness is initilized to 0 and only gets set to current brightness when "toggling off" - which is the only place where setting saved_brightness to current brightness makes any sense, logically. In all other cases it's not needed. I adapted the code that would crank up the brightness to 100 if we "toggle on" to 0 although the "arbitrary" special handling introduced by that is what I personally would consider broken. --- src/gpm-kbd-backlight.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/gpm-kbd-backlight.c b/src/gpm-kbd-backlight.c index 7adf0a8..02ded74 100644 --- a/src/gpm-kbd-backlight.c +++ b/src/gpm-kbd-backlight.c @@ -440,19 +440,9 @@ gpm_kbd_backlight_button_pressed_cb (GpmButton *button, const gchar *type, GpmKbdBacklight *backlight) { - static guint saved_brightness = ~0u; + static guint saved_brightness; gboolean ret; - if (saved_brightness == ~0u) { - saved_brightness = backlight->priv->brightness_percent; - /* If the initial value is 0, which probably means we saved on_ac=0, we - * try and restore some arbitrary value for the toggle not to seem - * broken */ - if (saved_brightness == 0) { - saved_brightness = 100u; - } - } - if (g_strcmp0 (type, GPM_BUTTON_KBD_BRIGHT_UP) == 0) { ret = gpm_kbd_backlight_brightness_up (backlight); @@ -475,7 +465,13 @@ gpm_kbd_backlight_button_pressed_cb (GpmButton *button, } else if (g_strcmp0 (type, GPM_BUTTON_KBD_BRIGHT_TOGGLE) == 0) { if (backlight->priv->brightness_percent == 0) { - /* backlight is off turn it back on */ + /* backlight is off turn it back on. + * If the initial value is 0, which probably means we saved on_ac=0, we + * try and restore some arbitrary value for the toggle not to seem + * broken. */ + if (saved_brightness == 0) { + saved_brightness = 100u; + } gpm_kbd_backlight_set (backlight, saved_brightness, TRUE); } else { /* backlight is on, turn it off and save current value */ -- cgit v1.2.1