From 9a8154836c04765e209f77bd1e3810e2a4818324 Mon Sep 17 00:00:00 2001 From: GlassOnTin Date: Mon, 30 Mar 2026 11:56:31 +0100 Subject: [PATCH] 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. --- src/input/keyboard.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/input/keyboard.c b/src/input/keyboard.c index 8e5c1f78..5a5c7595 100644 --- a/src/input/keyboard.c +++ b/src/input/keyboard.c @@ -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);