From f11feba4fb749e3d9ec7e8f004522823da54595e Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Wed, 2 Dec 2026 23:06:27 +0000 Subject: [PATCH] fwk: keyboard: never skip a media key's release in hotkey_F1_F12 hotkey_F1_F12() decides whether to translate a top-row key from the current Fn and Fn-lock state alone. If a top-row key goes down as a media key and Fn is pressed before it is released (with Fn-lock off), the release takes the "Fn held, pass through" early return: - the host gets the F-key break code instead of the media break code, so the media key is never released on the host side, and - the key's bit stays set in fn_key_table_media. With Fn-lock on, plain F-keys are only passed through while fn_key_table_media is empty, so the leftover bit makes every top-row key send its media function and Fn-lock appears to do nothing. fn_key_table_media is not cleared on shutdown or startup, so this survives reboots until the EC itself resets. Only take the early returns for presses, or for releases while no key is translated. Any other release goes through the switch, where fn_table_media_set() clears and translates a key that went down as a media key and leaves the rest untouched. Presses follow Fn / Fn-lock only, so a key held as a media key no longer makes the other keys ignore Fn-lock. Typematic repeats are unaffected: keyboard_8042 resends the already translated make code without calling the callback. Repro on a Laptop 13 Pro (sakura), BIOS 3.04: 1. With Fn-lock off: press F2, press Fn, release F2, release Fn. 2. Press Fn+Esc to turn Fn-lock on. 3. Press F1: it sends Mute instead of F1. Checked with a host-side model of the old and new logic; not yet built or flashed. Affects every board using keyboard_customization_13.c (marigold, sakura). --- .../framework/src/keyboard_customization_13.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/zephyr/program/framework/src/keyboard_customization_13.c b/zephyr/program/framework/src/keyboard_customization_13.c index 3299572534..4e20308503 100644 --- a/zephyr/program/framework/src/keyboard_customization_13.c +++ b/zephyr/program/framework/src/keyboard_customization_13.c @@ -263,15 +263,15 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t fn, int8_t pressed) { const uint16_t prss_key = *key_code; - if (!(Fn_key & FN_LOCKED) && - (fn & FN_PRESSED)) - return EC_SUCCESS; - else if (Fn_key & FN_LOCKED && - !(fn & FN_PRESSED) && - !fn_key_table_media) - return EC_SUCCESS; - else if (!fn_key_table_media && !pressed) - return EC_SUCCESS; + /* While a key is translated, releases go to the switch to match it. */ + if (pressed || !fn_key_table_media) { + if (!(Fn_key & FN_LOCKED) && (fn & FN_PRESSED)) + return EC_SUCCESS; + if ((Fn_key & FN_LOCKED) && !(fn & FN_PRESSED)) + return EC_SUCCESS; + if (!pressed) + return EC_SUCCESS; + } switch (prss_key) { case SCANCODE_F1: /* SPEAKER_MUTE */