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

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
+2
View File
@@ -46,5 +46,7 @@ check_save
.codewhale .codewhale
.mimocode .mimocode
.claude
src/demo
*.deb *.deb
+1 -1
View File
@@ -1,5 +1,5 @@
Package: ktouch Package: ktouch
Version: 2.1 Version: 2.1.1
Architecture: arm64 Architecture: arm64
Maintainer: Kushidou <kushidou@small09.top> Maintainer: Kushidou <kushidou@small09.top>
Depends: xinput, python3 Depends: xinput, python3
+6
View File
@@ -1,3 +1,9 @@
ktouch (2.1.1) unstable; urgency=medium
* 适配只支持鼠标事件的屏幕
-- Kushidou <kushidou@small09.top> Mon, 24 Aug 2026 13:00:00 +0800
ktouch (2.1) unstable; urgency=medium ktouch (2.1) unstable; urgency=medium
* 适配只支持鼠标事件的屏幕 * 适配只支持鼠标事件的屏幕
+14 -2
View File
@@ -180,6 +180,7 @@ void close_touch_devices() {
void process_input_event(struct input_event *ev, struct touch_device *device, void process_input_event(struct input_event *ev, struct touch_device *device,
struct touch_event *touch_ev) { struct touch_event *touch_ev) {
static int x = 0, y = 0, pressure = 0, touch_id = 0; 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); touch_ev->device_id = hash_string(device->path);
strncpy(touch_ev->device_name, device->name, sizeof(touch_ev->device_name)); 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) { if (event_callback) {
event_callback(*touch_ev); event_callback(*touch_ev);
} }
} else if (ev->code == BTN_LEFT) {
// 鼠标模拟触摸屏: 只记录按键状态, 按下/释放延迟到随后的 SYN_REPORT 上报(此时坐标已更新)
pending_button = ev->value ? 1 : -1;
} }
break; break;
case EV_SYN: case EV_SYN:
if (ev->code == SYN_REPORT) { if (ev->code == SYN_REPORT) {
// 报告同步事件,表示一组事件完成 // 报告同步事件,表示一组事件完成
touch_ev->event_type = 1; // 移动
touch_ev->x = x; touch_ev->x = x;
touch_ev->y = y; touch_ev->y = y;
touch_ev->pressure = pressure; touch_ev->pressure = pressure;
touch_ev->touch_id = touch_id; 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); event_callback(*touch_ev);
} }
} }