ukbd - Different approach for key swap on Apple keyboards

From: Frank Hilgendorf <frank.hilgendorf_at_posteo.de>
Date: Wed, 24 Jan 2024 16:40:26 UTC
Hi,

I am struggling  bit with the keyboard setup on an old Apple notebook and would like to propose a change in ukbd.c

The ukbd keyboard driver contains a swap function for the [<>] and [°^] keys on Apple keyboards. 
The decision to activate the key swap is based on the presence of the [Eject] key in the keyboard HID table.

On my old MacbookPro 3,1 with german keyboard, swapping is not activated although it would be necessary.
This is because the [Eject] key is located in a separate HID table.

Looking into the git log and into the archives of this mailing list, I found that this theme has been addressed early 2010.
A patch had been added that enabled the swap key logic also on the presence of the [FN] key. After a short time this patch has been reverted. 
The back and forth in the patches indicates that the implemented logic to activate key swap does not work precisely enough.

Approach 1)
The driver should not only check whether it is an Apple keyboard or not, but should as well check whether it is an ANSI / ISO / JIS keyboard.
The ISO keyboard has the left [SHIFT] key split into [SHIFT] and [<>] keys. My assumption is, that key swap is necessary for ISO keyboards (as mine is), but not for ANSI keyboards. (I don't know nothing about the japanese JIS keyboards).
This can be accomplished using the USB vendor-ID and product-ID. Apple ANSI, ISO and JIS keyboards have different product IDs.
This could simply be a static table with [product ID / swap flag] in the driver (similar to the one in the atp trackpad driver). 
As a disadvantage, this table would have to updated each time Apple releases a new keyboard type.

Approach 2)
Simpler: don't let the driver try to figure out whether to swap or not. Just add a sysctl variable and let the user decide.

What do you think would be the best solution?

Regards, Frank