libweston: check focus surface before enabling pointer constraint

Check if surface matches before enabling pointer constraint. If not
match, no constraint enabled. Otherwise, assertion would failed in
confined_pointer_grab_pointer_motion() and weston would crash.

This fixes crashes reported in GitLab issues #185 and #670.

Closes: https://gitlab.freedesktop.org/wayland/weston/-/issues/185
Closes: https://gitlab.freedesktop.org/wayland/weston/-/issues/670
Signed-off-by: Ruitang Wang <Ruitang.Wang@amd.com>
This commit is contained in:
Wang Ruitang 2026-02-05 13:26:45 +08:00
parent df40e3b93a
commit c23ea4ba8d

View file

@ -4628,6 +4628,14 @@ enable_pointer_constraint(struct weston_pointer_constraint *constraint,
struct weston_view *view)
{
assert(constraint->view == NULL);
if (!constraint->pointer->focus ||
constraint->pointer->focus->surface != constraint->surface) {
weston_log("WARNING: Not enabling constraint because "
"pointer focus doesn't match\n");
return;
}
constraint->view = view;
pointer_constraint_notify_activated(constraint);
weston_pointer_start_grab(constraint->pointer, &constraint->grab);