在 QtWayland 中,QWaylandInputDevice::touch_frame() 通过 QWindowSystemInterface::handleTouchEvent() 将触摸点传递给 Qt 内部窗口系统。Weston 根本不发送 WL_TOUCH_FRAME 事件,因此按钮或 QML MouseArea 永远不会收到触摸事件。您可以将以下行添加到 weston/src/evdev.c 中 evdev_flush_motion() 的末尾:
notify_touch(master, time, 0, 0, 0, WL_TOUCH_FRAME);
并重写 weston/src/input.c 中的 notify_touch():
WL_EXPORT void
notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
wl_fixed_t x, wl_fixed_t y, int touch_type)
{
struct weston_compositor *ec = seat->compositor;
struct weston_touch *touch = seat->touch;
struct weston_touch_grab *grab = touch->grab;
struct weston_surface *es;
wl_fixed_t sx, sy;
struct weston_touch *grab_touch = grab->touch;
/* Update grab's global coordinates. */
touch->grab_x = x;
touch->grab_y = y;
switch (touch_type) {
case WL_TOUCH_DOWN:
weston_compositor_idle_inhibit(ec);
seat->num_tp++;
/* the first finger down picks the surface, and all further go
* to that surface for the remainder of the touch session i.e.
* until all touch points are up again. */
if (seat->num_tp == 1) {
es = weston_compositor_pick_surface(ec, x, y, &sx, &sy);
weston_touch_set_focus(seat, es);
} else if (touch->focus) {
es = (struct weston_surface *) touch->focus;
weston_surface_from_global_fixed(es, x, y, &sx, &sy);
} else {
/* Unexpected condition: We have non-initial touch but
* there is no focused surface.
*/
weston_log("touch event received with %d points down"
"but no surface focused\n", seat->num_tp);
return;
}
grab->interface->down(grab, time, touch_id, sx, sy);
if (seat->num_tp == 1) {
touch->grab_serial =
wl_display_get_serial(ec->wl_display);
touch->grab_time = time;
touch->grab_x = x;
touch->grab_y = y;
}
break;
case WL_TOUCH_MOTION:
es = (struct weston_surface *) touch->focus;
if (!es)
break;
weston_surface_from_global_fixed(es, x, y, &sx, &sy);
grab->interface->motion(grab, time, touch_id, sx, sy);
break;
case WL_TOUCH_UP:
weston_compositor_idle_release(ec);
seat->num_tp--;
grab->interface->up(grab, time, touch_id);
break;
case WL_TOUCH_FRAME:
if (grab_touch->focus_resource) {
wl_touch_send_frame(grab_touch->focus_resource);
if (seat->num_tp == 0)
weston_touch_set_focus(seat, NULL);
}
}
}
同时,我发现 weston 不能正确处理多点触控,因为它的 mt 结构(下图)使用了一个只能跟踪当前插槽号的 int 值 'slot'。
struct {
int slot;
int32_t x[MAX_SLOTS];
int32_t y[MAX_SLOTS];
} mt;
在多点触控协议类型 B 中,每个插槽与一个手指接触相关联,您会在一个触摸帧中获得多个插槽事件,例如 touch_down 帧;
ABS_MT_SLOT
ABS_MT_TRACKING_ID
ABS_MT_POSITION_X
ABS_MT_POSITION_Y
ABS_MT_SLOT
ABS_MT_TRACKING_ID
ABS_MT_POSITION_X
ABS_MT_POSITION_Y
EV_SYN
weston 处理从第一个 slot 事件到 EV_SYN 事件的事件,如果遇到 EV_SYN,它会调用 notify_touch()。因此,weston 不能通过 notify_touch() 以不同的 slot number 参数顺序发送两个 touch down 事件。
在我的重新实现中,我更改了 mt 结构:
struct {
int current_slot;
uint32_t num_down_event;
uint32_t num_motion_event;
uint32_t num_up_event;
int slots[MAX_CONTACTS];
int32_t x[MAX_SLOTS];
int32_t y[MAX_SLOTS];
} mt;
- num_down_event:跟踪有多少手指触碰
- num_motion_event:跟踪有多少手指移动
- num_up_event:跟踪有多少手指抬起
- 插槽:跟踪每个触摸帧中的插槽号