fix: correct emulation of cursor pointer from unhandled touch events

This commit is contained in:
werapi 2025-11-30 06:51:05 +01:00 committed by Ching Pei Yang
parent 47c5adfb37
commit afd0f9278c

View file

@ -5881,9 +5881,9 @@ void touchdown(struct wl_listener *listener, void *data) {
struct wlr_touch_down_event *event = data; struct wlr_touch_down_event *event = data;
double lx, ly; double lx, ly;
double sx, sy; double sx, sy;
double dx, dy;
struct wlr_surface *surface; struct wlr_surface *surface;
Client *c = NULL; Client *c = NULL;
uint32_t serial = 0;
Monitor *m; Monitor *m;
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
@ -5908,48 +5908,54 @@ void touchdown(struct wl_listener *listener, void *data) {
/* Find the client under the pointer and send the event along. */ /* Find the client under the pointer and send the event along. */
xytonode(lx, ly, &surface, &c, NULL, &sx, &sy); xytonode(lx, ly, &surface, &c, NULL, &sx, &sy);
if (sloppyfocus && c) if (surface != NULL && wlr_surface_accepts_touch(surface, seat)) {
focusclient(c, 0); if (sloppyfocus && c)
focusclient(c, 0);
if (surface != NULL) { wlr_seat_touch_notify_down(seat, surface, event->time_msec,
serial = wlr_seat_touch_notify_down(seat, surface, event->time_msec, event->touch_id, sx, sy);
event->touch_id, sx, sy); emulating_pointer_from_touch = false;
return;
} }
if (serial && wlr_seat_touch_num_points(seat) == 1) { /* Emulate a mouse click if the touch event wasn't handled */
/* Emulate a mouse click if the touch event wasn't handled */ if (!emulating_pointer_from_touch) {
struct wlr_pointer_button_event *button_event = data; emulating_pointer_from_touch = true;
struct wlr_pointer_motion_absolute_event *motion_event = data; emulated_pointer_touch_id = event->touch_id;
double dx, dy;
wlr_cursor_absolute_to_layout_coords( wlr_cursor_warp_closest(cursor, &event->touch->base, lx, ly);
cursor, &motion_event->pointer->base, motion_event->x,
motion_event->y, &lx, &ly);
wlr_cursor_warp_closest(cursor, &motion_event->pointer->base, lx, ly);
dx = lx - cursor->x; dx = lx - cursor->x;
dy = ly - cursor->y; dy = ly - cursor->y;
motionnotify(motion_event->time_msec, &motion_event->pointer->base, dx, motionnotify(event->time_msec, &event->touch->base, dx, dy, dx, dy);
dy, dx, dy);
button_event->button = BTN_LEFT; struct wlr_pointer_button_event button_event = {
button_event->state = WL_POINTER_BUTTON_STATE_PRESSED; .pointer = (struct wlr_pointer *)event->touch,
buttonpress(listener, button_event); .time_msec = event->time_msec,
.button = BTN_LEFT,
.state = WL_POINTER_BUTTON_STATE_PRESSED};
buttonpress(listener, &button_event);
} }
} }
void touchup(struct wl_listener *listener, void *data) { void touchup(struct wl_listener *listener, void *data) {
struct wlr_touch_up_event *event = data; struct wlr_touch_up_event *event = data;
if (!wlr_seat_touch_get_point(seat, event->touch_id)) { if (emulating_pointer_from_touch) {
if (emulated_pointer_touch_id == event->touch_id) {
struct wlr_pointer_button_event button_event = {
.pointer = (struct wlr_pointer *)event->touch,
.time_msec = event->time_msec,
.button = BTN_LEFT,
.state = WL_POINTER_BUTTON_STATE_RELEASED};
buttonpress(listener, &button_event);
emulating_pointer_from_touch = false;
}
return; return;
} }
if (wlr_seat_touch_num_points(seat) == 1) { if (!wlr_seat_touch_get_point(seat, event->touch_id)) {
struct wlr_pointer_button_event *button_event = data; return;
button_event->button = BTN_LEFT;
button_event->state = WL_POINTER_BUTTON_STATE_RELEASED;
buttonpress(listener, button_event);
} }
wlr_seat_touch_notify_up(seat, event->time_msec, event->touch_id); wlr_seat_touch_notify_up(seat, event->time_msec, event->touch_id);
@ -5957,7 +5963,11 @@ void touchup(struct wl_listener *listener, void *data) {
} }
void touchframe(struct wl_listener *listener, void *data) { void touchframe(struct wl_listener *listener, void *data) {
wlr_seat_touch_notify_frame(seat); if (emulating_pointer_from_touch) {
wlr_seat_pointer_notify_frame(seat);
} else {
wlr_seat_touch_notify_frame(seat);
}
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
} }
@ -5965,9 +5975,23 @@ void touchmotion(struct wl_listener *listener, void *data) {
struct wlr_touch_motion_event *event = data; struct wlr_touch_motion_event *event = data;
double lx, ly; double lx, ly;
double sx, sy; double sx, sy;
double dx, dy;
struct wlr_surface *surface; struct wlr_surface *surface;
Client *c = NULL; Client *c = NULL;
struct wlr_touch_point *p = wlr_seat_touch_get_point(seat, event->touch_id); struct wlr_touch_point *p = NULL;
if (emulating_pointer_from_touch) {
if (emulated_pointer_touch_id == event->touch_id) {
wlr_cursor_absolute_to_layout_coords(cursor, &event->touch->base,
event->x, event->y, &lx, &ly);
dx = lx - cursor->x;
dy = ly - cursor->y;
motionnotify(event->time_msec, &event->touch->base, dx, dy, dx, dy);
}
return;
}
p = wlr_seat_touch_get_point(seat, event->touch_id);
if (!p) { if (!p) {
return; return;
@ -5977,20 +6001,23 @@ void touchmotion(struct wl_listener *listener, void *data) {
event->y, &lx, &ly); event->y, &lx, &ly);
surface = p->surface; surface = p->surface;
c = surface ? get_client_from_surface(surface) : NULL; c = surface ? get_client_from_surface(surface) : NULL;
sx = lx - c->current.x;
sy = ly - c->current.y;
if (c != NULL) { if (!c) {
if (sloppyfocus)
focusclient(c, 0);
wlr_seat_touch_point_focus(seat, surface, event->time_msec,
event->touch_id, sx, sy);
} else {
if (sloppyfocus) if (sloppyfocus)
focusclient(NULL, 0); focusclient(NULL, 0);
wlr_seat_touch_point_clear_focus(seat, event->time_msec, wlr_seat_touch_point_clear_focus(seat, event->time_msec,
event->touch_id); event->touch_id);
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
return;
} }
sx = lx - c->current.x;
sy = ly - c->current.y;
if (sloppyfocus)
focusclient(c, 0);
wlr_seat_touch_point_focus(seat, surface, event->time_msec, event->touch_id,
sx, sy);
wlr_seat_touch_notify_motion(seat, event->time_msec, event->touch_id, sx, wlr_seat_touch_notify_motion(seat, event->time_msec, event->touch_id, sx,
sy); sy);