interface/wlr_pointer: rework destroy sequence

The destroy callback in wlr_pointer_impl has been removed. The function
`wlr_pointer_finish` has been introduced to clean up the resources owned by a
wlr_pointer.

`wlr_input_device_destroy` no longer destroys the wlr_pointer, attempting to
destroy a wlr_pointer will result in a no-op.

The field `name` has been added to the wlr_pointer_impl to be able to identify
a given wlr_pointer device.
This commit is contained in:
Simon Zeni 2022-03-02 13:57:28 -05:00 committed by Kirill Primak
parent 7dc4a3ecd7
commit 51cd3c0726
9 changed files with 40 additions and 59 deletions

View file

@ -2,7 +2,6 @@
#include <stdlib.h>
#include <string.h>
#include <wayland-server-core.h>
#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/interfaces/wlr_switch.h>
#include <wlr/interfaces/wlr_tablet_pad.h>
#include <wlr/interfaces/wlr_tablet_tool.h>
@ -43,7 +42,7 @@ void wlr_input_device_destroy(struct wlr_input_device *dev) {
wlr_log(WLR_ERROR, "wlr_keyboard will not be destroyed");
break;
case WLR_INPUT_DEVICE_POINTER:
wlr_pointer_destroy(dev->pointer);
wlr_log(WLR_ERROR, "wlr_pointer will not be destroyed");
break;
case WLR_INPUT_DEVICE_SWITCH:
wlr_switch_destroy(dev->switch_device);

View file

@ -25,14 +25,6 @@ void wlr_pointer_init(struct wlr_pointer *pointer,
wl_signal_init(&pointer->events.hold_end);
}
void wlr_pointer_destroy(struct wlr_pointer *pointer) {
if (!pointer) {
return;
}
void wlr_pointer_finish(struct wlr_pointer *pointer) {
wlr_input_device_finish(&pointer->base);
if (pointer->impl && pointer->impl->destroy) {
pointer->impl->destroy(pointer);
} else {
free(pointer);
}
}

View file

@ -8,12 +8,8 @@
#include "util/signal.h"
#include "wlr-virtual-pointer-unstable-v1-protocol.h"
static void pointer_destroy(struct wlr_pointer *pointer) {
/* no-op, pointer belongs to the wlr_virtual_pointer_v1 */
}
static const struct wlr_pointer_impl pointer_impl = {
.destroy = pointer_destroy,
.name = "virtual-pointer",
};
static const struct zwlr_virtual_pointer_v1_interface virtual_pointer_impl;
@ -203,9 +199,10 @@ static void virtual_pointer_destroy_resource(struct wl_resource *resource) {
return;
}
/* TODO: rework wlr_pointer device destruction */
wlr_signal_emit_safe(&pointer->events.destroy, pointer);
wlr_pointer_destroy(&pointer->pointer);
wlr_pointer_finish(&pointer->pointer);
wl_resource_set_user_data(pointer->resource, NULL);
wl_list_remove(&pointer->link);
free(pointer);
@ -251,7 +248,7 @@ static void virtual_pointer_manager_create_virtual_pointer_with_output(
}
wlr_pointer_init(&virtual_pointer->pointer, &pointer_impl,
"virtual-pointer");
"wlr_virtual_pointer_v1");
struct wl_resource *pointer_resource = wl_resource_create(client,
&zwlr_virtual_pointer_v1_interface, wl_resource_get_version(resource),