hkbd/ukbd: sysctls to swap macbook kbd modifiers

Many applications, desktop environments, window managers & text editors
favor the usage of Alt or Ctrl over Super (Cmd). On a Macbook it is
quite annoying that the Super (Cmd) key gets pride of place by the spacebar.

The standard MacBook Cmd key location only really makes sense for macOS
or maybe in some tiling wm if Mod4/Super is your main modifier.
For most mainstream desktops and window managers, having Alt or Ctrl
in that location makes much much more sense.

This patch adds two sysctls for swapping either Opt(Alt) or Ctrl with Cmd(Super).

Linux has similar sysctls to this; allowing a user to make an Apple
keyboard more "orthodox"/useful at a level that takes effect independent
of typing context - ie) tty, Xorg and/or wayland.

Having a sysctl to do these swaps means that a user doesn't have to faff
about with both creating a custom vt keymap AND figure out which magic
setxkbmap incantation one needs to make one's keyboard behave as desired
across environments.

Signed-off-by: ~Not Toby <0x2b@0xff.art>

Reviewed by:	wulf
MFC after:	1 week
Pull Request:	https://github.com/freebsd/freebsd-src/pull/2141
This commit is contained in:
~Not Toby
2026-04-23 08:10:05 +03:00
committed by Vladimir Kondratyev
parent 8d680381c8
commit c0e26f7b29
4 changed files with 102 additions and 2 deletions
+13 -1
View File
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 12, 2020
.Dd April 23, 2026
.Dt HKBD 4
.Os
.Sh NAME
@@ -151,6 +151,18 @@ tunables:
Debug output level, where 0 is debugging disabled and larger values increase
debug message verbosity.
Default is 0.
.It Va hw.hid.hkbd.apple_swap_cmd_opt
Swap the Command & Option keys on Apple keyboards if set to 1.
Default is 0.
.It Va hw.hid.hkbd.apple_swap_cmd_ctl
Swap the Command & Control keys on Apple keyboards if set to 1.
Default is 0.
.It Va hw.hid.hkbd.apple_fn_mode
Direct access to media keys without holding Fn if set to 1.
Default is 0.
.It Va hw.hid.hkbd.no_leds
Disables setting of keyboard LEDs if set to 1.
Default is 0.
.El
.Sh FILES
.Bl -tag -width ".Pa /dev/input/event*" -compact
+13 -1
View File
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd April 24, 2018
.Dd April 23, 2026
.Dt UKBD 4
.Os
.Sh NAME
@@ -156,6 +156,18 @@ tunables:
Debug output level, where 0 is debugging disabled and larger values increase
debug message verbosity.
Default is 0.
.It Va hw.usb.ukbd.apple_swap_cmd_opt
Swap the Command & Option keys on Apple keyboards if set to 1.
Default is 0.
.It Va hw.usb.ukbd.apple_swap_cmd_ctl
Swap the Command & Control keys on Apple keyboards if set to 1.
Default is 0.
.It Va hw.usb.ukbd.apple_fn_mode
Direct access to media keys without holding Fn if set to 1.
Default is 0.
.It Va hw.usb.ukbd.no_leds
Disables setting of keyboard LEDs if set to 1.
Default is 0.
.El
.Sh FILES
.Bl -tag -width ".Pa /dev/kbd*" -compact