Skip to content

fwk: keyboard: never skip a media key's release in hotkey_F1_F12 - #108

Open
mdibaiee wants to merge 1 commit into
FrameworkComputer:fwk-sakura-20260429from
mdibaiee:fwk-sakura-fn-lock-stuck-media-key
Open

mdibaiee wants to merge 1 commit into
FrameworkComputer:fwk-sakura-20260429from
mdibaiee:fwk-sakura-fn-lock-stuck-media-key

Conversation

@mdibaiee

@mdibaiee mdibaiee commented Dec 3, 2026 •

Copy link
Copy Markdown

On my Laptop 13 Pro (Core Ultra Series 3, BIOS 3.04), Fn Lock stopped working: after Fn+Esc, plain F1 still sent Mute. Fn itself worked (Fn+Space, Fn+F1), and rebooting didn't help. This PR fixes the cause in hotkey_F1_F12().

What the controller does today

Each top-row key has two meanings, for example F1 or Mute, and F2 or Volume Down. The controller picks one when the key goes down, and must send the matching release when it comes up.

To keep presses and releases matched, it keeps a list of keys currently held as media keys (fn_key_table_media). A key goes on the list when it's pressed as a media key, and should come off it when it's released.

What goes wrong

On a release, the controller checks Fn before looking at the list. With Fn Lock off and Fn held, it assumes the F-key meaning and skips the list entirely. So if you:

  1. press F2 (Volume Down starts),
  2. press Fn while still holding F2,
  3. release F2,

the controller sends "F2 released" instead of "Volume Down released", and Volume Down never comes off the list. That causes three problems:

  • The host never sees Volume Down released. It may treat the key as still held.
  • The key stays on the list until the controller itself resets. The list isn't cleared on shutdown or startup, so a normal reboot doesn't help.
  • Fn Lock stops working. With Fn Lock on, plain F-keys are only passed through while the list is empty. One stuck key makes every top-row key send its media function, so Fn Lock seems to do nothing.

A smaller version of the same problem: with Fn Lock on, holding any media key turns the other top-row keys into media keys too.

How this change fixes it

Key presses work exactly as before: the controller picks F-key or media from Fn and Fn Lock.

The difference is in releases while any key is on the list. They no longer take the Fn shortcut and go through the existing switch instead:

  • A key that went down as a media key gets its media release and comes off the list.
  • Any other key is released unchanged, because fn_table_media_set() leaves keys that aren't on the list alone. Non-top-row keys pass straight through.

Every release now matches its press, so a key can't get stuck on the list and Fn Lock keeps working. Key repeats are unaffected, because keyboard_8042 resends the already-translated make code without calling the callback.

Reproduce

  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. Before this change it sends Mute; after it, F1.

To recover on current firmware: with Fn Lock on, tap each top-row key once without Fn.

Testing

I checked this with a host-side model of the old and new hotkey_F1_F12() logic, covering the reproduction above, Fn+F-key with Fn Lock on and off, holding a media key while pressing other keys, and releasing keys in different orders. The old logic fails the reproduction; the new logic passes all cases.

I haven't built or flashed this firmware. A build and test on hardware by someone with the toolchain would be appreciated.

The change is in the shared keyboard_customization_13.c, so it affects every board that uses it (marigold and sakura). #87 (Fn-lock indicator on the Caps Lock LED) changes the same file on the same base branch. The two don't overlap, but may need a rebase.

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).
@JohnAZoidberg

Copy link
Copy Markdown
Member

Thanks, I can reproduce the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants