diff options
author | Arwed Meyer <[email protected]> | 2024-10-03 14:49:09 +0200 |
---|---|---|
committer | Victor Kareh <[email protected]> | 2025-09-26 15:50:40 +0000 |
commit | 55cd3c20158f71067a60c75c534df42760a8f762 (patch) | |
tree | dafc062a61928af14976ca40ad9600fb83c004fd | |
parent | c8c63217d6244b62ddc68157b5f0bda1a35da110 (diff) | |
download | mate-power-manager-55cd3c20158f71067a60c75c534df42760a8f762.tar.bz2 mate-power-manager-55cd3c20158f71067a60c75c534df42760a8f762.tar.xz |
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.
-rw-r--r-- | src/gpm-kbd-backlight.c | 20 |
1 files 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 */ |