diff --git a/docs/README-migration.md b/docs/README-migration.md index 676ad1332..3b87da24c 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -815,6 +815,8 @@ The following environment variables have been removed: * SDL_HAPTIC_GAIN_MAX * SDL_HIDAPI_DISABLE_LIBUSB - replaced with the hint SDL_HINT_HIDAPI_LIBUSB * SDL_HIDAPI_JOYSTICK_DISABLE_UDEV - replaced with the hint SDL_HINT_HIDAPI_UDEV +* SDL_INPUT_FREEBSD_KEEP_KBD - replaced with the hint SDL_HINT_MUTE_CONSOLE_KEYBOARD +* SDL_INPUT_LINUX_KEEP_KBD - replaced with the hint SDL_HINT_MUTE_CONSOLE_KEYBOARD * VITA_DISABLE_TOUCH_BACK - replaced with the hint SDL_HINT_VITA_ENABLE_BACK_TOUCH * VITA_DISABLE_TOUCH_FRONT - replaced with the hint SDL_HINT_VITA_ENABLE_FRONT_TOUCH * VITA_MODULE_PATH - replaced with the hint SDL_HINT_VITA_MODULE_PATH diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h index ab94f7eab..6203f3271 100644 --- a/include/SDL3/SDL_hints.h +++ b/include/SDL3/SDL_hints.h @@ -2482,6 +2482,22 @@ extern "C" { */ #define SDL_HINT_MOUSE_TOUCH_EVENTS "SDL_MOUSE_TOUCH_EVENTS" +/** + * A variable controlling whether the keyboard should be muted on the console. + * + * Normally the keyboard is muted while SDL applications are running so that keyboard input doesn't show up as key strokes on the console. This hint allows you to turn that off for debugging purposes. + * + * The variable can be set to the following values: + * + * - "0": Allow keystrokes to go through to the console. + * - "1": Mute keyboard input so it doesn't show up on the console. (default) + * + * This hint should be set before SDL is initialized. + * + * \since This hint is available since SDL 3.0.0. + */ +#define SDL_HINT_MUTE_CONSOLE_KEYBOARD "SDL_MUTE_CONSOLE_KEYBOARD" + /** * Tell SDL not to catch the SIGINT or SIGTERM signals on POSIX platforms. * diff --git a/src/core/freebsd/SDL_evdev_kbd_freebsd.c b/src/core/freebsd/SDL_evdev_kbd_freebsd.c index 10ee85dca..a980c8d18 100644 --- a/src/core/freebsd/SDL_evdev_kbd_freebsd.c +++ b/src/core/freebsd/SDL_evdev_kbd_freebsd.c @@ -264,8 +264,8 @@ SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void) SDL_free(kbd->key_map); kbd->key_map = &keymap_default_us_acc; } - /* Allow inhibiting keyboard mute with env. variable for debugging etc. */ - if (SDL_getenv("SDL_INPUT_FREEBSD_KEEP_KBD") == NULL) { + + if (SDL_GetHintBoolean(SDL_HINT_MUTE_CONSOLE_KEYBOARD, SDL_TRUE)) { /* Take keyboard from console and open the actual keyboard device. * Ensures that the keystrokes do not leak through to the console. */ diff --git a/src/core/linux/SDL_evdev_kbd.c b/src/core/linux/SDL_evdev_kbd.c index bf4832983..8af1cf35e 100644 --- a/src/core/linux/SDL_evdev_kbd.c +++ b/src/core/linux/SDL_evdev_kbd.c @@ -473,8 +473,7 @@ void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, SDL_bool muted) } if (muted) { - /* Allow inhibiting keyboard mute with env. variable for debugging etc. */ - if (SDL_getenv("SDL_INPUT_LINUX_KEEP_KBD") == NULL) { + if (SDL_GetHintBoolean(SDL_HINT_MUTE_CONSOLE_KEYBOARD, SDL_TRUE)) { /* Mute the keyboard so keystrokes only generate evdev events * and do not leak through to the console */