Files
MeowOS-For-R3P2/patch_v2/files_app/app.c
T
MeowOS e95552b949 feat(sdk): 通用长按事件 (agent-191, 用户定案) — MEOW_EV_LONG_PRESS 坐标式事件+meow_ui_set_long_press_cb/ms(opt-in,默认500ms,移动>12px取消,长按后抬手抑制TAP/SWIPE); 按钮按住视觉阈值同源; files 长按从App层迁入 SDK
meow_ui.a 4335c33a→6de89c27; hello→72fb20da; files→b1c4f58f
宿主 widgets(含6条长按断言)/p1p2p3/ime_fix/test_fsx 全 PASS; 未改 meow_ui_events 结构(防 -Wmissing-field-initializers 破坏既有App)
2026-08-31 05:04:26 +08:00

114 lines
4.4 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.
/* app.c — files 应用装配层:main + 组装 + 事件分发。
*
* 职责(对齐 hello_app/app.c):main 只做初始化/建页/跑事件循环/清理;把 meow_ui_run 的平铺输入
* 回调(key/tap/swipe/tick/touch)路由到当前活动页(browser/viewer);通用长按走独立注册
* (meow_ui_set_long_press_cb,§6.3)路由到 browser。页面切换统一走
* meow_view_page_push/pop(活动栈 + on_enter/on_leave 唯一驱动)。
*
* 铁律(APPS.md §3.4.1 / WORK_STATE.md):物理键禁映射——不处理任何 key 语义;返回=左缘左滑
* (on_swipe LEFT)/返回钮/meow_ui_request_exit。目录进退不换页(browser 改 cur_dir 重扫);
* 文本预览换页(push ACT_VIEWER)。退出=在根目录左滑或 SIGTERM(看门狗)。
*/
#include "files_internal.h"
#include <signal.h>
static meow_view *g_browser_view;
static meow_view *g_viewer_view;
static void on_sigterm(int s) { (void)s; meow_ui_request_exit(); }
/* ============================================================ */
/* 事件分发:meow_ui_run 平铺回调 → 当前页 */
/* ============================================================ */
/* 物理键系统语义(息屏/音量/媒体)由 SDK 消化;App 不映射(§3.4.1)。 */
static void app_on_key(int keycode, int is_down)
{
(void)keycode; (void)is_down;
}
static void app_on_tap(int x, int y)
{
if (viewer_is_active()) { viewer_on_tap(x, y); return; }
if (browser_is_active()) { browser_on_tap(x, y); return; }
}
static void app_on_swipe(int dir, int dx, int dy)
{
(void)dx;
if (dir == MEOW_SWIPE_LEFT) {
/* 左缘返回:预览页→回目录;浏览器→上级目录;到根→退出 App。 */
if (viewer_is_active()) { meow_view_page_pop(); return; }
if (browser_is_active() && browser_go_up()) return;
meow_log(MEOW_LOG_INFO, "exit:swipe");
meow_ui_request_exit();
return;
}
if (viewer_is_active()) { viewer_swipe(dir, dy); return; }
if (browser_is_active()) { browser_swipe(dir, dy); return; }
}
/* 左缘返回手势过程视觉条(SDK 自动画顶部进度条,App 转发)。 */
static void app_on_swipe_progress(int x_start, int dx)
{
meow_ui_swipe_hint(x_start + dx);
}
/* 拖拽过程(跟手):列表/文本内容滚动。 */
static void app_on_touch_down(int x, int y)
{
if (viewer_is_active()) viewer_touch_down(x, y);
else if (browser_is_active()) browser_touch_down(x, y);
}
static void app_on_touch_move(int x, int y)
{
if (viewer_is_active()) viewer_touch_move(x, y);
else if (browser_is_active()) browser_touch_move(x, y);
}
/* 通用长按(§6.3):SDK 判定「按下 ≥ 阈值未抬手且位移 ≤ 容忍」后带坐标回调;
* browser 据此行命中打开 BottomSheet。viewer 无长按语义。 */
static void app_on_long_press(int x, int y)
{
if (browser_is_active()) browser_on_long_press(x, y);
}
/* on_tick:本 App 无帧动画/时钟(长按计时已下沉 SDK §6.3),保留为空槽。 */
static void app_on_tick(void) { }
/* ============================================================ */
/* main */
/* ============================================================ */
int main(void)
{
meow_log(MEOW_LOG_INFO, "start");
meow_ui_opts o = { APP_W, APP_H };
if (meow_ui_init(&o) != 0) { meow_log(MEOW_LOG_ERROR, "init failed"); return 1; }
meow_theme_add_listener(NULL);
signal(SIGTERM, on_sigterm);
/* 建两页 view(on_create 建各自控件/状态 + 读卡扫首个目录) */
g_browser_view = browser_view_create();
g_viewer_view = viewer_view_create();
/* 进入根页(ACT_BROWSER = 目录浏览;默认卡根 /usr/data/mnt/sd_0) */
meow_view_page_push(ACT_BROWSER);
meow_ui_events ev = {
app_on_key, app_on_tap, app_on_swipe, app_on_tick, app_on_swipe_progress,
app_on_touch_down, app_on_touch_move,
};
/* 通用长按走独立注册(§6.3):不进 meow_ui_events(避免位置初始化在 -Wextra 下告警)。 */
meow_ui_set_long_press_cb(app_on_long_press);
meow_ui_run(&ev);
/* 清理:meow_view_free 触发各页 on_destroy(控件 + 文本缓冲) */
meow_view_free(g_viewer_view);
meow_view_free(g_browser_view);
meow_ui_shutdown();
meow_log(MEOW_LOG_INFO, "exit");
return 0;
}