From 0f14ae95b020e8e43da9b5593d1cba8e48f56a55 Mon Sep 17 00:00:00 2001 From: Alexandros Frantzis Date: Thu, 8 Feb 2018 15:37:52 +0200 Subject: [PATCH] libweston: Support NULL weston_pointer in init_pointer_constraint Fix init_pointer_constraint so that it creates a valid, but inert, resource if a NULL weston_pointer value is passed in. In that case no constraint object is associated with the resource, but this is not an issue since affected code can already handle NULL constraint objects. Signed-off-by: Alexandros Frantzis Reviewed-by: Pekka Paalanen --- libweston/input.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/libweston/input.c b/libweston/input.c index 96cded47..390698c7 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -3572,7 +3572,7 @@ init_pointer_constraint(struct wl_resource *pointer_constraints_resource, struct wl_resource *cr; struct weston_pointer_constraint *constraint; - if (get_pointer_constraint_for_pointer(surface, pointer)) { + if (pointer && get_pointer_constraint_for_pointer(surface, pointer)) { wl_resource_post_error(pointer_constraints_resource, ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED, "the pointer has a lock/confine request on this surface"); @@ -3587,18 +3587,23 @@ init_pointer_constraint(struct wl_resource *pointer_constraints_resource, return; } - constraint = weston_pointer_constraint_create(surface, pointer, - region, lifetime, - cr, grab_interface); - if (constraint == NULL) { - wl_client_post_no_memory(client); - return; + if (pointer) { + constraint = weston_pointer_constraint_create(surface, pointer, + region, lifetime, + cr, grab_interface); + if (constraint == NULL) { + wl_client_post_no_memory(client); + return; + } + } else { + constraint = NULL; } wl_resource_set_implementation(cr, implementation, constraint, pointer_constraint_constrain_resource_destroyed); - maybe_enable_pointer_constraint(constraint); + if (constraint) + maybe_enable_pointer_constraint(constraint); } static void