mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-11-03 09:01:40 -05:00 
			
		
		
		
	pointer-constraints: handle inert pointer resources correctly
(cherry picked from commit cb815e8847)
			
			
This commit is contained in:
		
							parent
							
								
									9a9540aa8c
								
							
						
					
					
						commit
						c9909ac54c
					
				
					 1 changed files with 25 additions and 15 deletions
				
			
		| 
						 | 
					@ -176,17 +176,8 @@ static void pointer_constraint_create(struct wl_client *client,
 | 
				
			||||||
		pointer_constraints_from_resource(pointer_constraints_resource);
 | 
							pointer_constraints_from_resource(pointer_constraints_resource);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct wlr_surface *surface = wlr_surface_from_resource(surface_resource);
 | 
						struct wlr_surface *surface = wlr_surface_from_resource(surface_resource);
 | 
				
			||||||
	struct wlr_seat *seat =
 | 
						struct wlr_seat_client *seat_client =
 | 
				
			||||||
		wlr_seat_client_from_pointer_resource(pointer_resource)->seat;
 | 
							wlr_seat_client_from_pointer_resource(pointer_resource);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (wlr_pointer_constraints_v1_constraint_for_surface(pointer_constraints,
 | 
					 | 
				
			||||||
			surface, seat)) {
 | 
					 | 
				
			||||||
		wl_resource_post_error(pointer_constraints_resource,
 | 
					 | 
				
			||||||
			ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED,
 | 
					 | 
				
			||||||
			"a pointer constraint with a wl_pointer of the same wl_seat"
 | 
					 | 
				
			||||||
			" is already on this surface");
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint32_t version = wl_resource_get_version(pointer_constraints_resource);
 | 
						uint32_t version = wl_resource_get_version(pointer_constraints_resource);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -200,6 +191,28 @@ static void pointer_constraint_create(struct wl_client *client,
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void *impl = locked_pointer ?
 | 
				
			||||||
 | 
							(void *)&locked_pointer_impl : (void *)&confined_pointer_impl;
 | 
				
			||||||
 | 
						wl_resource_set_implementation(resource, impl, NULL,
 | 
				
			||||||
 | 
							pointer_constraint_destroy_resource);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (seat_client == NULL) {
 | 
				
			||||||
 | 
							// Leave the resource inert
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct wlr_seat *seat = seat_client->seat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (wlr_pointer_constraints_v1_constraint_for_surface(pointer_constraints,
 | 
				
			||||||
 | 
								surface, seat)) {
 | 
				
			||||||
 | 
							wl_resource_destroy(resource);
 | 
				
			||||||
 | 
							wl_resource_post_error(pointer_constraints_resource,
 | 
				
			||||||
 | 
								ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED,
 | 
				
			||||||
 | 
								"a pointer constraint with a wl_pointer of the same wl_seat"
 | 
				
			||||||
 | 
								" is already on this surface");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct wlr_pointer_constraint_v1 *constraint = calloc(1, sizeof(*constraint));
 | 
						struct wlr_pointer_constraint_v1 *constraint = calloc(1, sizeof(*constraint));
 | 
				
			||||||
	if (constraint == NULL) {
 | 
						if (constraint == NULL) {
 | 
				
			||||||
		wl_resource_destroy(resource);
 | 
							wl_resource_destroy(resource);
 | 
				
			||||||
| 
						 | 
					@ -234,10 +247,7 @@ static void pointer_constraint_create(struct wl_client *client,
 | 
				
			||||||
	constraint->seat_destroy.notify = handle_seat_destroy;
 | 
						constraint->seat_destroy.notify = handle_seat_destroy;
 | 
				
			||||||
	wl_signal_add(&seat->events.destroy, &constraint->seat_destroy);
 | 
						wl_signal_add(&seat->events.destroy, &constraint->seat_destroy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void *impl = locked_pointer ?
 | 
						wl_resource_set_user_data(resource, constraint);
 | 
				
			||||||
		(void *)&locked_pointer_impl : (void *)&confined_pointer_impl;
 | 
					 | 
				
			||||||
	wl_resource_set_implementation(constraint->resource, impl, constraint,
 | 
					 | 
				
			||||||
		pointer_constraint_destroy_resource);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wlr_log(WLR_DEBUG, "new %s_pointer %p (res %p)",
 | 
						wlr_log(WLR_DEBUG, "new %s_pointer %p (res %p)",
 | 
				
			||||||
		locked_pointer ? "locked" : "confined",
 | 
							locked_pointer ? "locked" : "confined",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue