From 9de6d7f50247f5774fc2fd1fa609162fb02eba7d Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 9 Nov 2022 10:05:18 +0000 Subject: [PATCH] translate Fn+(1-10,-,=) keys to F1-F12 on M1 laptops with a touchbar ok kettenis@, miod@ --- sys/arch/arm64/dev/aplhidev.c | 16 +++++++++++++--- sys/dev/hid/hidkbd.c | 31 ++++++++++++++++++++++++++++++- sys/dev/hid/hidkbdsc.h | 3 ++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/sys/arch/arm64/dev/aplhidev.c b/sys/arch/arm64/dev/aplhidev.c index dc221a0f677..f1c3f5ad0e7 100644 --- a/sys/arch/arm64/dev/aplhidev.c +++ b/sys/arch/arm64/dev/aplhidev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aplhidev.c,v 1.8 2022/10/02 19:00:46 kettenis Exp $ */ +/* $OpenBSD: aplhidev.c,v 1.9 2022/11/09 10:05:18 robert Exp $ */ /* * Copyright (c) 2021 Mark Kettenis * Copyright (c) 2013-2014 joshua stein @@ -33,6 +33,8 @@ #include #include +#include + #include #include #include @@ -526,8 +528,16 @@ aplkbd_attach(struct device *parent, struct device *self, void *aux) printf("\n"); if (hid_locate(aa->aa_desc, aa->aa_desclen, HID_USAGE2(HUP_APPLE, HUG_FN_KEY), - 1, hid_input, &kbd->sc_fn, NULL)) - kbd->sc_munge = hidkbd_apple_munge; + 1, hid_input, &kbd->sc_fn, NULL)) { + switch (sc->sc_hidev->sc_product) { + case USB_PRODUCT_APPLE_WELLSPRINGM1_J293: + kbd->sc_munge = hidkbd_apple_tb_munge; + break; + default: + kbd->sc_munge = hidkbd_apple_munge; + break; + } + } if (kbd->sc_console_keyboard) { extern struct wskbd_mapdata ukbd_keymapdata; diff --git a/sys/dev/hid/hidkbd.c b/sys/dev/hid/hidkbd.c index 08e02c4f9c5..c1faded214a 100644 --- a/sys/dev/hid/hidkbd.c +++ b/sys/dev/hid/hidkbd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hidkbd.c,v 1.7 2022/09/16 16:30:10 robert Exp $ */ +/* $OpenBSD: hidkbd.c,v 1.8 2022/11/09 10:05:18 robert Exp $ */ /* $NetBSD: ukbd.c,v 1.85 2003/03/11 16:44:00 augustss Exp $ */ /* @@ -108,6 +108,21 @@ const u_int8_t hidkbd_trtab[256] = { }; #endif /* defined(WSDISPLAY_COMPAT_RAWKBD) */ +static const struct hidkbd_translation apple_tb_trans[] = { + { 30, 58 }, /* 1 -> F1 */ + { 31, 59 }, /* 2 -> F2 */ + { 32, 60 }, /* 3 -> F3 */ + { 33, 61 }, /* 4 -> F4 */ + { 34, 62 }, /* 5 -> F5 */ + { 35, 63 }, /* 6 -> F6 */ + { 36, 64 }, /* 7 -> F7 */ + { 37, 65 }, /* 8 -> F8 */ + { 38, 66 }, /* 9 -> F9 */ + { 39, 67 }, /* 0 -> F10 */ + { 45, 68 }, /* - -> F11 */ + { 46, 69 } /* = -> F12 */ +}; + static const struct hidkbd_translation apple_fn_trans[] = { { 40, 73 }, /* return -> insert */ { 42, 76 }, /* backspace -> delete */ @@ -336,6 +351,20 @@ hidkbd_apple_munge(void *vsc, uint8_t *ibuf, u_int ilen) nitems(apple_fn_trans)); } +void +hidkbd_apple_tb_munge(void *vsc, uint8_t *ibuf, u_int ilen) +{ + struct hidkbd *kbd = vsc; + + if (!hid_get_data(ibuf, ilen, &kbd->sc_fn)) + return; + + hidkbd_apple_munge(vsc, ibuf, ilen); + + hidkbd_apple_translate(vsc, ibuf, ilen, apple_tb_trans, + nitems(apple_tb_trans)); +} + void hidkbd_apple_iso_munge(void *vsc, uint8_t *ibuf, u_int ilen) { diff --git a/sys/dev/hid/hidkbdsc.h b/sys/dev/hid/hidkbdsc.h index f8efc80fe45..d7128523bc7 100644 --- a/sys/dev/hid/hidkbdsc.h +++ b/sys/dev/hid/hidkbdsc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hidkbdsc.h,v 1.2 2022/09/16 16:30:10 robert Exp $ */ +/* $OpenBSD: hidkbdsc.h,v 1.3 2022/11/09 10:05:18 robert Exp $ */ /* $NetBSD: ukbd.c,v 1.85 2003/03/11 16:44:00 augustss Exp $ */ /* @@ -113,6 +113,7 @@ int hidkbd_ioctl(struct hidkbd *, u_long, caddr_t, int, struct proc *); int hidkbd_set_leds(struct hidkbd *, int, uint8_t *); uint8_t hidkbd_translate(const struct hidkbd_translation *, size_t, uint8_t); void hidkbd_apple_munge(void *, uint8_t *, u_int); +void hidkbd_apple_tb_munge(void *, uint8_t *, u_int); void hidkbd_apple_iso_munge(void *, uint8_t *, u_int); void hidkbd_apple_mba_munge(void *, uint8_t *, u_int); void hidkbd_apple_iso_mba_munge(void *, uint8_t *, u_int); -- 2.20.1