relative-pointer-v1: don't allocate when inert

When the wl_pointer the zwp_relative_pointer_v1 is created with is
inert, don't allocate any struct, just leave the resource's data
pointer NULL.
Simon Ser 3 years ago committed by Isaac Freund
parent 1feb8edd21
commit 43020963d4

@ -74,20 +74,28 @@ static void relative_pointer_manager_v1_handle_destroy(struct wl_client *client,
static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_client *client,
struct wl_resource *resource, uint32_t id, struct wl_resource *pointer) {
struct wlr_relative_pointer_manager_v1 *manager =
relative_pointer_manager_from_resource(resource);
struct wlr_seat_client *seat_client =
wlr_seat_client_from_pointer_resource(pointer);
struct wlr_relative_pointer_v1 *relative_pointer =
calloc(1, sizeof(struct wlr_relative_pointer_v1));
if (relative_pointer == NULL) {
struct wl_resource *relative_pointer_resource = wl_resource_create(client,
&zwp_relative_pointer_v1_interface, wl_resource_get_version(resource), id);
if (relative_pointer_resource == NULL) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(relative_pointer_resource, &relative_pointer_v1_impl,
NULL, relative_pointer_v1_handle_resource_destroy);
struct wl_resource *relative_pointer_resource = wl_resource_create(client,
&zwp_relative_pointer_v1_interface, wl_resource_get_version(resource), id);
if (relative_pointer_resource == NULL) {
free(relative_pointer);
if (seat_client == NULL) {
// Leave the resource inert
return;
}
struct wlr_relative_pointer_v1 *relative_pointer =
calloc(1, sizeof(struct wlr_relative_pointer_v1));
if (relative_pointer == NULL) {
wl_client_post_no_memory(client);
return;
}
@ -95,25 +103,16 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl
relative_pointer->resource = relative_pointer_resource;
relative_pointer->pointer_resource = pointer;
if (seat_client) {
relative_pointer->seat = seat_client->seat;
wl_signal_add(&relative_pointer->seat->events.destroy,
&relative_pointer->seat_destroy);
relative_pointer->seat_destroy.notify = relative_pointer_handle_seat_destroy;
} else {
wl_list_init(&relative_pointer->seat_destroy.link);
}
wl_signal_init(&relative_pointer->events.destroy);
wl_resource_set_implementation(relative_pointer_resource, &relative_pointer_v1_impl,
relative_pointer, relative_pointer_v1_handle_resource_destroy);
struct wlr_relative_pointer_manager_v1 *manager =
relative_pointer_manager_from_resource(resource);
wl_resource_set_user_data(relative_pointer_resource, relative_pointer);
wl_list_insert(&manager->relative_pointers,
&relative_pointer->link);
wl_list_insert(&manager->relative_pointers, &relative_pointer->link);
wl_resource_add_destroy_listener(relative_pointer->pointer_resource,
&relative_pointer->pointer_destroy);

Loading…
Cancel
Save