diff options
author | Tobias Heider <tobhe@cvs.openbsd.org> | 2023-11-22 18:19:26 +0000 |
---|---|---|
committer | Tobias Heider <tobhe@cvs.openbsd.org> | 2023-11-22 18:19:26 +0000 |
commit | dbc6b58e78e2aeeab94f2793c0ff8953f2df5273 (patch) | |
tree | 34699efa7ef182d1ea648f527143b6488b6d3fce /sys | |
parent | d09e623001e3718154fbf8398bbf96a5759ad177 (diff) |
Add support for keyboard backlight hotkeys in wskbd and hook up macppc apple
keyboards.
From jon (at) elytron (dot) openbsd (dot) amsterdam with some changes by me
ok gkoehler@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/hid/hidkbd.c | 8 | ||||
-rw-r--r-- | sys/dev/usb/makemap.awk | 7 | ||||
-rw-r--r-- | sys/dev/wscons/wskbd.c | 55 | ||||
-rw-r--r-- | sys/dev/wscons/wsksymdef.h | 5 |
4 files changed, 70 insertions, 5 deletions
diff --git a/sys/dev/hid/hidkbd.c b/sys/dev/hid/hidkbd.c index ef57b4f16a3..5f14fa5763c 100644 --- a/sys/dev/hid/hidkbd.c +++ b/sys/dev/hid/hidkbd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hidkbd.c,v 1.9 2023/07/09 08:02:13 tobhe Exp $ */ +/* $OpenBSD: hidkbd.c,v 1.10 2023/11/22 18:19:25 tobhe Exp $ */ /* $NetBSD: ukbd.c,v 1.85 2003/03/11 16:44:00 augustss Exp $ */ /* @@ -143,6 +143,9 @@ static const struct hidkbd_translation apple_fn_trans[] = { { 60, 127 }, /* F3 -> audio mute */ { 61, 129 }, /* F4 -> audio lower */ { 62, 128 }, /* F5 -> audio raise */ + { 65, 234 }, /* F8 -> backlight toggle */ + { 66, 236 }, /* F9 -> backlight lower */ + { 67, 235 }, /* F10 -> backlight raise */ #else { 63, 102 }, /* F6 -> sleep */ { 67, 127 }, /* F10 -> audio mute */ @@ -569,6 +572,9 @@ hidkbd_decode(struct hidkbd *kbd, struct hidkbd_data *ud) case 129: case 232: case 233: + case 234: + case 235: + case 236: wskbd_input(kbd->sc_wskbddev, key & RELEASE ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN, key & CODEMASK); diff --git a/sys/dev/usb/makemap.awk b/sys/dev/usb/makemap.awk index 547f19bfa62..e749fa49080 100644 --- a/sys/dev/usb/makemap.awk +++ b/sys/dev/usb/makemap.awk @@ -1,5 +1,5 @@ #! /usr/bin/awk -f -# $OpenBSD: makemap.awk,v 1.16 2023/07/09 08:02:13 tobhe Exp $ +# $OpenBSD: makemap.awk,v 1.17 2023/11/22 18:19:25 tobhe Exp $ # # Copyright (c) 2005, Miodrag Vallat # @@ -31,7 +31,7 @@ # BEGIN { - rcsid = "$OpenBSD: makemap.awk,v 1.16 2023/07/09 08:02:13 tobhe Exp $" + rcsid = "$OpenBSD: makemap.awk,v 1.17 2023/11/22 18:19:25 tobhe Exp $" ifdepth = 0 ignore = 0 declk = 0 @@ -343,6 +343,9 @@ $1 == "#define" || $1 == "#undef" { lines[126] = " KC(126),\tKS_Find," lines[232] = " KC(232),\tKS_Cmd_BrightnessUp," lines[233] = " KC(233),\tKS_Cmd_BrightnessDown," + lines[234] = " KC(234),\tKS_Cmd_KbdBacklightToggle," + lines[235] = " KC(235),\tKS_Cmd_KbdBacklightUp," + lines[236] = " KC(236),\tKS_Cmd_KbdBacklightDown," } for (i = 0; i < 256; i++) diff --git a/sys/dev/wscons/wskbd.c b/sys/dev/wscons/wskbd.c index 23a0744b0df..cf9ac177ed9 100644 --- a/sys/dev/wscons/wskbd.c +++ b/sys/dev/wscons/wskbd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wskbd.c,v 1.115 2023/07/09 08:02:14 tobhe Exp $ */ +/* $OpenBSD: wskbd.c,v 1.116 2023/11/22 18:19:25 tobhe Exp $ */ /* $NetBSD: wskbd.c,v 1.80 2005/05/04 01:52:16 augustss Exp $ */ /* @@ -177,12 +177,21 @@ struct wskbd_softc { #if NAUDIO > 0 void *sc_audiocookie; #endif + struct task sc_kbd_backlight_task; + u_int sc_kbd_backlight_cmd; #if NWSDISPLAY > 0 struct task sc_brightness_task; int sc_brightness_steps; #endif }; +enum wskbd_kbd_backlight_cmds { + KBD_BACKLIGHT_NONE, + KBD_BACKLIGHT_UP, + KBD_BACKLIGHT_DOWN, + KBD_BACKLIGHT_TOGGLE, +}; + #define MOD_SHIFT_L (1 << 0) #define MOD_SHIFT_R (1 << 1) #define MOD_SHIFTLOCK (1 << 2) @@ -249,6 +258,8 @@ void wskbd_set_keymap(struct wskbd_softc *, struct wscons_keymap *, int); int (*wskbd_get_backlight)(struct wskbd_backlight *); int (*wskbd_set_backlight)(struct wskbd_backlight *); + +void wskbd_kbd_backlight_task(void *); #if NWSDISPLAY > 0 void wskbd_brightness_task(void *); #endif @@ -406,6 +417,7 @@ wskbd_attach(struct device *parent, struct device *self, void *aux) bcopy(ap->keymap, &sc->id->t_keymap, sizeof(sc->id->t_keymap)); } + task_set(&sc->sc_kbd_backlight_task, wskbd_kbd_backlight_task, sc); #if NWSDISPLAY > 0 timeout_set(&sc->sc_repeat_ch, wskbd_repeat, sc); task_set(&sc->sc_brightness_task, wskbd_brightness_task, sc); @@ -1544,6 +1556,21 @@ internal_command(struct wskbd_softc *sc, u_int *type, keysym_t ksym, #endif #endif + switch (ksym) { + case KS_Cmd_KbdBacklightUp: + atomic_store_int(&sc->sc_kbd_backlight_cmd, KBD_BACKLIGHT_UP); + task_add(systq, &sc->sc_kbd_backlight_task); + return (1); + case KS_Cmd_KbdBacklightDown: + atomic_store_int(&sc->sc_kbd_backlight_cmd, KBD_BACKLIGHT_DOWN); + task_add(systq, &sc->sc_kbd_backlight_task); + return (1); + case KS_Cmd_KbdBacklightToggle: + atomic_store_int(&sc->sc_kbd_backlight_cmd, KBD_BACKLIGHT_TOGGLE); + task_add(systq, &sc->sc_kbd_backlight_task); + return (1); + } + #if NWSDISPLAY > 0 switch(ksym) { case KS_Cmd_BrightnessUp: @@ -1899,6 +1926,32 @@ wskbd_set_keymap(struct wskbd_softc *sc, struct wscons_keymap *map, int maplen) sc->sc_maplen = maplen; } +void +wskbd_kbd_backlight_task(void *arg) +{ + struct wskbd_softc *sc = arg; + struct wskbd_backlight data; + int step, val; + u_int cmd; + + if (wskbd_get_backlight == NULL || wskbd_set_backlight == NULL) + return; + + cmd = atomic_swap_uint(&sc->sc_kbd_backlight_cmd, 0); + if (cmd != KBD_BACKLIGHT_UP && + cmd != KBD_BACKLIGHT_DOWN && + cmd != KBD_BACKLIGHT_TOGGLE) + return; + + (*wskbd_get_backlight)(&data); + step = (data.max - data.min + 1) / 8; + val = (cmd == KBD_BACKLIGHT_UP) ? data.curval + step : + (cmd == KBD_BACKLIGHT_DOWN) ? data.curval - step : + (data.curval) ? 0 : (data.max - data.min + 1) / 2; + data.curval = (val > 0xff) ? 0xff : (val < 0) ? 0 : val; + (*wskbd_set_backlight)(&data); +} + #if NWSDISPLAY > 0 void wskbd_brightness_task(void *arg) diff --git a/sys/dev/wscons/wsksymdef.h b/sys/dev/wscons/wsksymdef.h index 69cc685d99d..759f805c581 100644 --- a/sys/dev/wscons/wsksymdef.h +++ b/sys/dev/wscons/wsksymdef.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wsksymdef.h,v 1.41 2023/07/09 08:02:14 tobhe Exp $ */ +/* $OpenBSD: wsksymdef.h,v 1.42 2023/11/22 18:19:25 tobhe Exp $ */ /* $NetBSD: wsksymdef.h,v 1.34.4.1 2000/07/07 09:49:54 hannken Exp $ */ /*- @@ -668,6 +668,9 @@ #define KS_Cmd_ScrollFwd 0xf42d #define KS_Cmd_KbdReset 0xf42e #define KS_Cmd_Sleep 0xf42f +#define KS_Cmd_KbdBacklightToggle 0xf430 +#define KS_Cmd_KbdBacklightUp 0xf431 +#define KS_Cmd_KbdBacklightDown 0xf432 /* * Group 5 (internal) |