Files
MeowOS-For-R3P2/patch_v2/sdk/test_meow_ui_dispatch.c
T
AskaEth 837cd47e7c fix(sdk+launcher): M39 点击输入门 — 固定时长吞窗改为「启动排空 + 短系统手势防穿透」
根因(M36 已查实):不是布局竞态,而是固定时长的输入封闭窗口且窗口起点在首帧之后。
- SDK meow_ui_run:M2.22(C) 500ms 内丢弃 TAP/SWIPE/HOME/NOTIF_PULL/TOUCH_DOWN/MOVE/LONG_PRESS,
  窗口在 App 画完首帧后才 arm → 用户看到界面后第一下必被吞。
  改为入口 meow_input_drain() 排空一次(清环形队列 + 复位触摸状态机),
  TAP/TOUCH_DOWN/TOUCH_MOVE/LONG_PRESS 立即生效;仅系统手势(左缘 SWIPE、底部上滑 HOME、
  顶部下拉 NOTIF_PULL、SWIPE_PROGRESS)保留 STARTUP_GESTURE_GUARD_MS=150 防穿透。
- launcher:menu_after_app_exit 1200ms→150ms;子页返回 800ms→150ms;菜单/子页打开
  300ms→150ms(统一 MENU_TOUCH_GUARD_MS)。menu_drain_touch() 同时复位 t_down/原点/坐标:
  只清队列会把「按下已被 drain、抬手稍后才到」误判成一次 tap(幽灵重放的另一半)。
  历史理由已核对:旧窗口是为 Bug2/4(App 运行期事件堆积在 launcher 自身 touch_fd 里被重放)
  加的,真正的机制就是排空本进程 fd —— evdev 每 fd 各收一份,App/子页运行期全量事件都在
  这个 fd 里,drain 后无历史事件可重放;窗口只兜面板重配尾巴。
- 单测:test_meow_ui_home_gesture 新增 T4(11 断言:立即点击生效/立即上滑被守卫挡+守卫后生效/
  立即左缘 SWIPE 同理/TOUCH_DOWN+MOVE 立即下发/LONG_PRESS 立即下发/run 入口 drain 丢弃预置残留;
  旧 SDK 下 8 条红、新 SDK 30 pass/0 fail);test_meow_ui_dispatch 新增 M5(drain 清队列+复位在途
  手势+新点击不受影响,ALL PASS);swipe 35/0、view_event ALL PASS(回归)。
- 重编重链(铁律):meow_ui.a 8525aa6b(meow_ui_input.o 8248a6c6,旧 e54903ca)→
  meow_launcherd e342d24f(891164) / files 17edac0f(383072) / hello 65c1c575(499380) /
  ncm 1c2f5ff7(1225676) / reader a463645f(1716212,gitignore 不入库)。
  picbrowser 仓库内 0 个 tracked 文件(源码不存在)→ 无法重链,见 finding。
- 真机:未验证(纪律禁止覆盖设备已装组件;uinput 注入是 M36 设备失联诱因)。
2026-11-10 21:58:13 +08:00

182 lines
10 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* test_meow_ui_dispatch.c — §6.4 事件分发形式化宿主验证(离屏 480x720,16bpp)。
*
* 覆盖(新穿透矩阵,全部直接驱动 SDK §6.4 仲裁者 API + 真实注册控件):
* M1 模态打开点下层不触发:modal_begin 后 meow_ui_hit_topdown 恒返回模态哨兵(不再落到下层
* 同坐标控件),gesture_begin 捕获的是模态(哨兵)而非下层按钮——下层绝不消费;
* M2 弹层叠开两层不叠黑/层隔离:modal_begin 两次 → depth=2;end(LIFO)逐层递减;期间
* hit_topdown 始终返回哨兵,下层收不到任何触摸;
* M3 捕获手势滑出不误触:gesture_begin 命中按钮 A 后捕获;任凭概念滑动到远处(不重新命中),
* meow_ui_gesture_owner 恒为 A(绝不滑出误触下层/邻控件);end 释放;
* M4 list 焦点点外释放:meow_list_tap_at/meow_listview_tap_at 使列表成为唯一焦点;
* focus_tap 落在列表内 → 保位;落在列表外(页面内容/空白)→ 释放焦点并触发 lost 回调;
* M5 启动排空 drain 语义(M39):drain 清空已入队事件 + 复位在途手势(迟到抬手不产 TAP),
* 且 drain 之后的新按下仍正常产出 TAP(排空只清残留,不吞新输入)。
*
* 编译(宿主 gcc,链真实 widget/draw/input/activity/gfx/sys/theme/vol/log/dialog/ime/notify/ipc +
* 打桩 font/global;完整超集便于链接):
* gcc -Wall -Wextra -o test_meow_ui_dispatch test_meow_ui_dispatch.c test_host_stub.c \
* meow_ui_gfx.c meow_ui_time.c meow_ui_sys.c meow_ui_theme.c meow_ui_vol.c meow_ui_log.c \
* meow_ui_widget.c meow_ui_input.c meow_ui_activity.c meow_ui_dialog.c meow_ui_ime.c meow_ui_str.c \
* meow_pinyin.c meow_ui_draw.c meow_ui_view.c meow_ui_box.c meow_ui_anim.c meow_ui_scroll.c \
* meow_ui_img.c meow_ui_media.c meow_notify_ipc.c stb_image.c meow_jpeg.c meow_png_stream.c \
* -I. -I../meow_launcherd -DMEOW_UI_HOST_TEST -pthread -lm -lz
* 运行:./test_meow_ui_dispatch (无设备,纯宿主)
*/
#include "meow_ui.h"
#include "meow_ui_internal.h"
#include "meow_ui_view.h"
#include "meow_ui_nav.h" /* meow_ui_nav_request_exit:meow_ui_input.c 的 MEOW_EV_HOME 分支引用 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* 不链 meow_ui_nav.c:以桩满足 HOME 分支的链接依赖(同 test_meow_ui_home_gesture 范式)。 */
static int g_nav_exit_calls = 0;
void meow_ui_nav_request_exit(void) { g_nav_exit_calls++; }
static int g_fail = 0;
#define CHECK(cond, name) do { \
if (cond) { printf(" PASS %s\n", name); } \
else { printf(" FAIL %s\n", name); g_fail++; } } while (0)
/* 焦点丢失回调计数 */
static int g_lost_calls = 0;
static void *g_lost_last = NULL;
static void focus_lost(void *owner, void *ctx)
{ (void)ctx; g_lost_calls++; g_lost_last = owner; }
/* 列表数据源(最小 W_LIST) */
static int list_src(int idx, char *label, int len, void *ctx)
{
(void)ctx;
if (idx < 0 || idx >= 8) return 0;
snprintf(label, (size_t)len, "item %d", idx);
return 1;
}
int main(void)
{
setenv("MEOW_UI_DUMP", "/tmp/dispatch.ppm", 1);
meow_ui_opts o = { 480, 720 };
if (meow_ui_init(&o) != 0) { printf("init failed\n"); return 1; }
meow_ui_activity_push(5); /* 页面控件 owner=5,命中/绘制对齐 */
/* 场景控件:两个不重叠按钮 A/B + 一个 LazyColumn 列表 */
meow_widget *btnA = meow_btn_create(20, 100, 200, 60, "A");
meow_widget *btnB = meow_btn_create(240, 100, 200, 60, "B");
meow_widget *list = meow_lazycolumn_create(20, 300, 400, 150, 44, 8, list_src, NULL);
/* ================= M1:模态打开点下层不触发 =================
* 无模态:hit_topdown(按钮A中心) == 按钮A;modal_begin 后同一落点返回模态哨兵(≠按钮A),
* gesture_begin 捕获的是模态而非下层按钮——下层绝不消费(穿透根治)。 */
printf("M1 modal open -> lower not triggered\n");
void *h0 = meow_ui_hit_topdown(120, 130);
printf(" no-modal hit_topdown(120,130) = %s\n",
h0 == (void *)btnA ? "btnA" : (h0 ? "other" : "NULL"));
CHECK(h0 == (void *)btnA, "no-modal topdown hits btnA (z-top)");
meow_ui_modal *m = meow_ui_modal_begin();
void *hm = meow_ui_hit_topdown(120, 130);
printf(" modal-open hit_topdown(120,130) = %s (sentinel=%d)\n",
hm == (void *)btnA ? "btnA(LEAK!)" : "modal-sentinel", hm != NULL && hm != (void *)btnA);
CHECK(meow_ui_modal_active(), "modal active");
CHECK(hm != NULL && hm != (void *)btnA, "modal present -> hit_topdown never reaches btnA");
void *g0 = meow_ui_gesture_begin(120, 130); /* 下层同坐标:捕获的是模态而非按钮 */
CHECK(g0 == hm, "gesture_begin during modal captures modal (sentinel), not btnA");
meow_ui_gesture_end();
meow_ui_modal_end(m);
CHECK(meow_ui_hit_topdown(120, 130) == (void *)btnA, "after modal_end topdown returns btnA again");
CHECK(!meow_ui_modal_active(), "modal released");
/* ================= M2:弹层叠开两层(层隔离,depth 语义) =================
* 两层弹开:depth 1→2;期间 hit_topdown 恒返回哨兵;LIFO 关内层→1,关外层→0。
* 叠黑由 Dialog/Sheet 的「打开前整帧快照 + 关闭还原 + 高亮仅重绘卡片不叠遮罩」保证
* (meow_ui_dialog.c,M2.71-bug3),本处验证层隔离 + 栈深。 */
printf("M2 stacked modals (two layers)\n");
meow_ui_modal *m1 = meow_ui_modal_begin();
meow_ui_modal *m2 = meow_ui_modal_begin();
CHECK(meow_ui_modal_depth() == 2, "two modals -> depth 2");
CHECK(meow_ui_hit_topdown(120, 130) != (void *)btnA, "either modal -> lower btnA blocked");
meow_ui_modal_end(m2);
CHECK(meow_ui_modal_depth() == 1, "close inner -> depth 1");
CHECK(meow_ui_hit_topdown(120, 130) != (void *)btnA, "outer modal still blocks lower");
meow_ui_modal_end(m1);
CHECK(meow_ui_modal_depth() == 0, "close outer -> depth 0");
CHECK(meow_ui_hit_topdown(120, 130) == (void *)btnA, "both closed -> lower reachable");
/* ================= M3:捕获手势滑出不误触 =================
* touch-down 命中按钮 A → 捕获。此后 move(即使滑到按钮 B / 空白)不重新命中,owner 恒为 A;
* 绝不滑出误触 B 或下层。抬手(gesture_end)释放。 */
printf("M3 gesture capture: slide-out no false-trigger\n");
void *g1 = meow_ui_gesture_begin(120, 130);
CHECK(g1 == (void *)btnA, "down on A captures A");
CHECK(meow_ui_gesture_owner() == (void *)btnA, "owner == A after down");
/* 概念滑动到按钮 B 中心 (340,130):捕获不重命中 → 仍是 A(不误触 B) */
CHECK(meow_ui_gesture_owner() == (void *)btnA, "slide to B point: owner stays A (no re-hit)");
/* 滑出到空白 */
CHECK(meow_ui_gesture_owner() == (void *)btnA, "slide to blank: owner stays A");
meow_ui_gesture_end();
CHECK(meow_ui_gesture_owner() == NULL, "release -> no owner");
/* ================= M4:list 焦点点外释放 =================
* meow_list_tap_at 使列表成为唯一焦点;focus_tap 落在列表内→保位;落在列表外→释放并通知。 */
printf("M4 list focus release on tap outside\n");
meow_ui_focus_set_lost_cb(focus_lost, NULL);
CHECK(meow_ui_focus_owner() == NULL, "no focus initially");
int idx = meow_list_tap_at(list, 120, 320); /* 命中列表行0 */
CHECK(idx >= 0, "list tap hits a row");
CHECK(meow_ui_focus_owner() == (void *)list, "list tap -> list becomes focus owner");
meow_ui_focus_tap(120, 320); /* 点列表内:保位 */
CHECK(meow_ui_focus_owner() == (void *)list, "tap inside list -> focus retained");
CHECK(g_lost_calls == 0, "no lost callback while focus retained");
meow_ui_focus_tap(120, 130); /* 命中按钮A(非列表):释放焦点+通知 */
CHECK(meow_ui_focus_owner() == NULL, "tap outside list (on A) -> focus released");
CHECK(g_lost_calls == 1 && g_lost_last == (void *)list, "lost callback fired with list owner");
/* 再次聚焦后再点「空白」(无控件命中):同样释放 */
meow_list_tap_at(list, 120, 320);
meow_ui_focus_tap(400, 650); /* 列表外空白 */
CHECK(meow_ui_focus_owner() == NULL, "tap on blank -> focus released");
CHECK(g_lost_calls == 2, "lost callback fired again");
(void)btnB;
/* ================= M5:启动排空 drain 语义(M39) =================
* M39 用「meow_ui_run 入口 drain 一次」取代 M2.22(C) 的 500ms 按时间吞输入窗口,
* 所以 drain 必须真的清干净:①队列里已入队的事件被丢弃;②在途手势(按下已发生、
* 抬手尚未到)被复位 —— 抬手不得再产出 TAP(否则 drain 之后会冒出迟到点击);
* ③drain 之后的新按下仍能正常产出 TAP(排空只清残留,不吞新输入)。 */
printf("M5 startup drain semantics (queue + in-flight gesture)\n");
{
/* ① 队列排空 */
meow_input_inject(MEOW_EV_TAP, 10, 20);
meow_input_inject(MEOW_EV_TAP, 30, 40);
meow_input_drain();
meow_input_ev e;
CHECK(!meow_input_pop(&e), "drain empties already-queued events");
/* ② 在途手势:按下 → drain → 抬手,不得产生迟到 TAP */
meow_input_touch_set(1, 120, 130, 0);
meow_input_drain();
meow_input_touch_release();
CHECK(!meow_input_pop(&e), "drain resets in-flight gesture (late release -> no TAP)");
/* ③ drain 之后的新一次点击正常产出 */
meow_input_touch_set(1, 200, 300, 0);
meow_input_touch_release();
int ok = meow_input_pop(&e);
int coords_ok = ok && e.type == MEOW_EV_TAP && e.a == 200 && e.b == 300;
if (!coords_ok && ok) printf(" tap after drain: type=%d a=%d b=%d\n", e.type, e.a, e.b);
CHECK(coords_ok, "tap after drain still dispatches");
}
/* 清理:控件释放自动注销 z 序绘制物 + 焦点/捕获复位 */
meow_widget_free(list);
meow_widget_free(btnB);
meow_widget_free(btnA);
meow_ui_focus_release(NULL);
meow_ui_activity_pop();
meow_ui_shutdown();
printf(g_fail ? "\nRESULT: %d FAIL(S)\n" : "\nRESULT: ALL PASS\n", g_fail);
return g_fail;
}