Skip to content

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

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

ukbd, hkbd, evdev: fix apple "magic" keys#1998
tslight wants to merge 11 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...

@github-actions
Copy link

github-actions bot commented Feb 1, 2026

Thank you for taking the time to contribute to FreeBSD!

All issues resolved.

@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
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... :-/

@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 <[email protected]>
@tslight
Copy link
Author

tslight commented Mar 6, 2026

@bsdimp @wulf7 Recently added a MBP 11,4 to my collection and this patch works great on there too. Would love to get this over the line so that the next time I rescue some old Apple hardware, I don't need to recompile :-)

@wulf7
Copy link
Contributor

wulf7 commented Mar 6, 2026

I ll try to test your patches on MacBook 8,1 at the end of next week and commit after than if all OK

@tslight
Copy link
Author

tslight commented Mar 7, 2026

Fabulous - thanks so much @wulf7

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.

3 participants