From 9f3c3c9a440276cc179dfbf7edd40506e0c9c00a Mon Sep 17 00:00:00 2001 From: liu weikai Date: Thu, 15 Oct 2026 15:33:09 +0800 Subject: [PATCH] Route native preview input through the bound page group --- tests/site/two-pane-layout.test.mjs | 2 +- tools/web_simulator/native_runtime.cpp | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/site/two-pane-layout.test.mjs b/tests/site/two-pane-layout.test.mjs index 9fb1a22b..6bdcfd9c 100644 --- a/tests/site/two-pane-layout.test.mjs +++ b/tests/site/two-pane-layout.test.mjs @@ -42,7 +42,7 @@ for(const [device,width,height] of [['pager',480,222],['tdeck',320,240],['wio-tr } runtime._native_key(27);tick(); assert.equal(runtime._native_page_value(),page,`${device}:${page}: Escape closes the menu before leaving the page`); - assert.ok(!snapshot().some(item=>item.button&&item.text===filterText)); + assert.ok(!snapshot().some(item=>item.button&&item.text===filterText),`${device}:${page}: Escape hides the filter menu`); } console.log(`${device}: six former two-pane pages use bottom menus, full-width content and menu-first back navigation.`); } diff --git a/tools/web_simulator/native_runtime.cpp b/tools/web_simulator/native_runtime.cpp index aecc9f03..e5f6e47c 100644 --- a/tools/web_simulator/native_runtime.cpp +++ b/tools/web_simulator/native_runtime.cpp @@ -36,7 +36,19 @@ EM_JS(void, request_menu, (), { if (Module.onExit) Module.onExit(); }); -void set_default_group(lv_group_t* group) { lv_group_set_default(group); } +void set_default_group(lv_group_t* group) +{ + if (pointer_device) lv_indev_set_group(pointer_device, group); + lv_group_set_default(group); +} + +static lv_group_t* input_group() +{ + // Pages may clear LVGL's auto-add default after binding their input group. + // Read the bound device just as the firmware input drivers do. + auto* group = pointer_device ? lv_indev_get_group(pointer_device) : nullptr; + return group ? group : lv_group_get_default(); +} void ui_request_exit_to_menu() { // Do not destroy the current page while its LVGL event is being dispatched. @@ -157,7 +169,7 @@ extern "C" { if (key == LV_KEY_ENTER && preview_current_page() == 10) { - auto* group = lv_group_get_default(); + auto* group = input_group(); auto* focused = group ? lv_group_get_focused(group) : nullptr; if (focused && !lv_obj_has_state(focused, LV_STATE_DISABLED)) { @@ -166,7 +178,7 @@ extern "C" return; } if (key < 128 && ui::menu_runtime::handleShortcutKey(static_cast(key), 1)) return; - if (auto* group = lv_group_get_default()) lv_group_send_data(group, key); + if (auto* group = input_group()) lv_group_send_data(group, key); } EMSCRIPTEN_KEEPALIVE void native_focus(uint32_t id) { @@ -196,7 +208,7 @@ extern "C" } EMSCRIPTEN_KEEPALIVE void native_encoder(int delta) { - if (auto* group = lv_group_get_default()) + if (auto* group = input_group()) { if (delta < 0) lv_group_focus_prev(group); else lv_group_focus_next(group);