keyboard: use XKB_CONTEXT_NO_SECURE_GETENV on Android

Android's bionic libc implements secure_getenv() as a function that
always returns NULL because app processes don't have AT_SECURE set.
This prevents xkbcommon from reading XKB_DEFAULT_LAYOUT and other
environment variables when resolving keyboard layouts.

Use XKB_CONTEXT_NO_SECURE_GETENV on Android so xkbcommon falls back
to regular getenv(), which works correctly in the Android app
environment.
This commit is contained in:
GlassOnTin 2026-03-30 11:56:31 +01:00 committed by Johan Malm
parent 862d230ff9
commit 9a8154836c

View file

@ -745,7 +745,18 @@ set_layout(struct wlr_keyboard *kb)
static bool fallback_mode;
struct xkb_rule_names rules = { 0 };
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
enum xkb_context_flags ctx_flags = XKB_CONTEXT_NO_FLAGS;
#ifdef __ANDROID__
/*
* Android's bionic libc implements secure_getenv() as a function
* that always returns NULL (the app process has no AT_SECURE).
* This prevents xkbcommon from reading XKB_DEFAULT_LAYOUT and
* friends via secure_getenv(). Use the flag to fall back to
* regular getenv() which works fine on Android.
*/
ctx_flags |= XKB_CONTEXT_NO_SECURE_GETENV;
#endif
struct xkb_context *context = xkb_context_new(ctx_flags);
struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules,
XKB_KEYMAP_COMPILE_NO_FLAGS);