Skip to content

ukbd, hkbd, evdev: fix apple "magic" keys#1998

Open
tslight wants to merge 7 commits intofreebsd:mainfrom
tslight:fix/apple_fn_keys
Open

ukbd, hkbd, evdev: fix apple "magic" keys#1998
tslight wants to merge 7 commits intofreebsd:mainfrom
tslight:fix/apple_fn_keys

Conversation

@tslight
Copy link

@tslight tslight commented Jan 31, 2026

I recently acquired 3 old Macbooks (MBP 8,3, MBA 6,1, MBA 7,2) and the Fn, Eject & Multimedia keys did not show up in the output of kbdscan, evtest or xev or do anything but provide F1..F12 whether Fn was held or not.

This PR fixes that and adds sysctls for toggling whether or not holding Fn is required to access the Multimedia keys.

I'm curious why we're looking for the Apple vendor usage page at 0xFFFF rather than the locations Linux looks for it? I found it at 0x00FF on all 3 machines. I've left 0xFFFF in there as I'm assuming it was set to that for a good reason and works on Apple hardware that Linux no longer supports.

I've also added a sysctl for ukbd & hkbd to toggle the mode of the function keys similar to what's available on Linux, but would like to make a more convenient toggle via Fn+Esc at some point...

Finally, one of the main motivations for this work was to get extra keys to bind to my desires in userland which is why I've "unhidden" the Fn and Eject keys. I chose KEY_WAKEUP for Fn, as KEY_FN doesn't make it to X, and XF86WakeUp commonly shows up on the Fn key back in penguin land...

Signed-off-by: tslight <tslight@pm.com>
@github-actions
Copy link

github-actions bot commented Feb 1, 2026

Thank you for taking the time to contribute to FreeBSD!

All issues resolved.

Signed-off-by: tslight <tslight@pm.com>
@tslight tslight changed the title Fix handling of Apple FN/Multimedia keys in hid and evdev ukbd, hkbd, evdev: fix apple fn key handling Feb 1, 2026
@tslight tslight changed the title ukbd, hkbd, evdev: fix apple fn key handling ukbd, hkbd, evdev: fix apple "magic" keys Feb 1, 2026
tslight and others added 2 commits February 1, 2026 20:00
Signed-off-by: tslight <tslight@pm.com>
Signed-off-by: tslight <tslight@pm.com>
tslight and others added 2 commits February 4, 2026 13:38
Signed-off-by: tslight <tslight@pm.com>
Signed-off-by: Toby Slight <tslight@pm.me>
@tslight
Copy link
Author

tslight commented Feb 6, 2026

Hi there @wulf7 I saw some of your posts on the forums and looking at the history it seems you're the go to guy for this area of the tree - many thanks for all your hard work and contributions BTW!

I was wondering if you wouldn't mind sharing your thoughts on this PR when you have a mo' :-)

I'm very much a noob when it comes to FreeBSD & C so apologies if the approach is naive or totally wonky in some way... :-/

if (flags & HIO_VARIABLE)
sc->sc_flags |= HKBD_FLAG_APPLE_FN;
DPRINTFN(1, "Found Apple FN-key\n");
if (hw->idVendor == 0x05ac) { /* belt & braces! */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who is vendor 0x5ac? A comment would be good, better than belt and braces

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I did consider using the USB_VENDOR_APPLE macro we have in ukbd, but it felt wrong importing usb code into hid. I'll just update the comment like you suggested.

@bsdimp
Copy link
Member

bsdimp commented Feb 8, 2026

This generally looks good, but a comment about what 5ac is would be good. It's unfortunate that a lot of this is duplicated between ukbd and hkbd, but maybe that can't be helped.

@bsdimp bsdimp added the changes-required Cannot land as is, change requested of submitter label Feb 8, 2026
@tslight
Copy link
Author

tslight commented Feb 8, 2026

This generally looks good, but a comment about what 5ac is would be good. It's unfortunate that a lot of this is duplicated between ukbd and hkbd, but maybe that can't be helped.

I agree - it wasn't until I updated the Macbook 8,3 to current, discovered a bug in hid on that hardware, and had to revert to using ukbd, that I realised I needed to backport the changes to a legacy driver.

Happy to investigate ways in which we could DRY this up, if that's something the project deems important...

I'm currently playing around with a module for remapping keys that provides a hook to each driver through hid, so I'm already very much drinking from the fire-hose in this domain! ;-)

Anyway, many, many thanks for the feedback and I'll push that updated comment ASAP.

- Fn+K for ScrollLock as it's very useful to have ScrollLock on
FreeBSD's TTY and other vendors use Fn+K for this purpose.
- Fn+P for PrtSc/SysRq, as it's another very handy but sadly missing
key on Macbooks.

- Also, fix/make ukbd debug guard consistent with hkbd
- currently won't compile if using GENERIC-NODEBUG...

Signed-off-by: Toby Slight <tslight@pm.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changes-required Cannot land as is, change requested of submitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants