interface/wlr_touch: rework destroy sequence

The destroy callback in wlr_touch_impl has been removed. The function
`wlr_touch_finish` has been introduced to clean up the resources owned by a
wlr_touch.

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

The field `name` has been added to the wlr_touch_impl to be able to identify
a given wlr_touch device.
This commit is contained in:
Simon Zeni 2022-03-02 16:07:40 -05:00 committed by Kirill Primak
parent 8d3cb94b41
commit 10cbb9fbe1
8 changed files with 12 additions and 22 deletions

View file

@ -24,7 +24,7 @@ void destroy_libinput_input_device(struct wlr_libinput_input_device *dev) {
wlr_switch_finish(&dev->switch_device); wlr_switch_finish(&dev->switch_device);
} }
if (dev->touch.impl) { if (dev->touch.impl) {
wlr_touch_destroy(&dev->touch); wlr_touch_finish(&dev->touch);
} }
if (dev->tablet.impl) { if (dev->tablet.impl) {
finish_device_tablet(dev); finish_device_tablet(dev);

View file

@ -4,12 +4,8 @@
#include "backend/libinput.h" #include "backend/libinput.h"
#include "util/signal.h" #include "util/signal.h"
static void touch_destroy(struct wlr_touch *touch) {
/* wlr_touch belongs to the wlr_libinput_input_device */
}
const struct wlr_touch_impl libinput_touch_impl = { const struct wlr_touch_impl libinput_touch_impl = {
.destroy = touch_destroy, .name = "libinput-touch",
}; };
void init_device_touch(struct wlr_libinput_input_device *dev) { void init_device_touch(struct wlr_libinput_input_device *dev) {

View file

@ -567,6 +567,10 @@ void destroy_wl_input_device(struct wlr_wl_input_device *dev) {
wlr_tablet_finish(wlr_dev->tablet); wlr_tablet_finish(wlr_dev->tablet);
free(wlr_dev->tablet); free(wlr_dev->tablet);
break; break;
case WLR_INPUT_DEVICE_TOUCH:
wlr_touch_finish(wlr_dev->touch);
free(wlr_dev->touch);
break;
default: default:
wlr_input_device_destroy(wlr_dev); wlr_input_device_destroy(wlr_dev);
break; break;

View file

@ -293,12 +293,8 @@ const struct wlr_pointer_impl x11_pointer_impl = {
.name = "x11-pointer", .name = "x11-pointer",
}; };
static void touch_destroy(struct wlr_touch *wlr_touch) {
// Don't free the touch, it's on the stack
}
const struct wlr_touch_impl x11_touch_impl = { const struct wlr_touch_impl x11_touch_impl = {
.destroy = touch_destroy, .name = "x11-touch",
}; };
void update_x11_pointer_position(struct wlr_x11_output *output, void update_x11_pointer_position(struct wlr_x11_output *output,

View file

@ -77,7 +77,7 @@ static void output_destroy(struct wlr_output *wlr_output) {
pixman_region32_fini(&output->exposed); pixman_region32_fini(&output->exposed);
wlr_pointer_finish(&output->pointer); wlr_pointer_finish(&output->pointer);
wlr_touch_destroy(&output->touch); wlr_touch_finish(&output->touch);
struct wlr_x11_buffer *buffer, *buffer_tmp; struct wlr_x11_buffer *buffer, *buffer_tmp;
wl_list_for_each_safe(buffer, buffer_tmp, &output->buffers, link) { wl_list_for_each_safe(buffer, buffer_tmp, &output->buffers, link) {

View file

@ -12,11 +12,11 @@
#include <wlr/types/wlr_touch.h> #include <wlr/types/wlr_touch.h>
struct wlr_touch_impl { struct wlr_touch_impl {
void (*destroy)(struct wlr_touch *touch); const char *name;
}; };
void wlr_touch_init(struct wlr_touch *touch, void wlr_touch_init(struct wlr_touch *touch,
const struct wlr_touch_impl *impl, const char *name); const struct wlr_touch_impl *impl, const char *name);
void wlr_touch_destroy(struct wlr_touch *touch); void wlr_touch_finish(struct wlr_touch *touch);
#endif #endif

View file

@ -2,7 +2,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wlr/interfaces/wlr_touch.h>
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "util/signal.h" #include "util/signal.h"
@ -45,7 +44,7 @@ void wlr_input_device_destroy(struct wlr_input_device *dev) {
wlr_log(WLR_ERROR, "wlr_switch will not be destroyed"); wlr_log(WLR_ERROR, "wlr_switch will not be destroyed");
break; break;
case WLR_INPUT_DEVICE_TOUCH: case WLR_INPUT_DEVICE_TOUCH:
wlr_touch_destroy(dev->touch); wlr_log(WLR_ERROR, "wlr_touch will not be destroyed");
break; break;
case WLR_INPUT_DEVICE_TABLET_TOOL: case WLR_INPUT_DEVICE_TABLET_TOOL:
wlr_log(WLR_ERROR, "wlr_tablet_tool will not be destroyed"); wlr_log(WLR_ERROR, "wlr_tablet_tool will not be destroyed");

View file

@ -17,11 +17,6 @@ void wlr_touch_init(struct wlr_touch *touch,
wl_signal_init(&touch->events.frame); wl_signal_init(&touch->events.frame);
} }
void wlr_touch_destroy(struct wlr_touch *touch) { void wlr_touch_finish(struct wlr_touch *touch) {
wlr_input_device_finish(&touch->base); wlr_input_device_finish(&touch->base);
if (touch && touch->impl && touch->impl->destroy) {
touch->impl->destroy(touch);
} else {
free(touch);
}
} }