修复识别到鼠标事件后无法响应的问题

This commit is contained in:
2026-08-24 13:23:37 +08:00
parent 75727afd24
commit 471935a966
6 changed files with 582 additions and 562 deletions
+14 -2
View File
@@ -180,6 +180,7 @@ void close_touch_devices() {
void process_input_event(struct input_event *ev, struct touch_device *device,
struct touch_event *touch_ev) {
static int x = 0, y = 0, pressure = 0, touch_id = 0;
static int pending_button = 0; // 鼠标模拟屏: BTN_LEFT 状态待定, 延迟到 SYN_REPORT 上报 (0=无, 1=待按下, -1=待释放)
touch_ev->device_id = hash_string(device->path);
strncpy(touch_ev->device_name, device->name, sizeof(touch_ev->device_name));
@@ -241,17 +242,28 @@ void process_input_event(struct input_event *ev, struct touch_device *device,
if (event_callback) {
event_callback(*touch_ev);
}
} else if (ev->code == BTN_LEFT) {
// 鼠标模拟触摸屏: 只记录按键状态, 按下/释放延迟到随后的 SYN_REPORT 上报(此时坐标已更新)
pending_button = ev->value ? 1 : -1;
}
break;
case EV_SYN:
if (ev->code == SYN_REPORT) {
// 报告同步事件,表示一组事件完成
touch_ev->event_type = 1; // 移动
touch_ev->x = x;
touch_ev->y = y;
touch_ev->pressure = pressure;
touch_ev->touch_id = touch_id;
if (event_callback && (x != 0 || y != 0)) {
// 鼠标模拟触摸屏: 把待定的按下/释放在此刻上报(此时该帧坐标已更新完毕)
if (pending_button != 0) {
touch_ev->event_type = (pending_button == 1) ? 0 : 2; // 按下/释放
pending_button = 0;
if (event_callback) {
event_callback(*touch_ev);
}
} else if (event_callback && (x != 0 || y != 0)) {
touch_ev->event_type = 1; // 移动
event_callback(*touch_ev);
}
}