mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-25 08:32:30 +00:00
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:
parent
7dc4a3ecd7
commit
51cd3c0726
@ -18,7 +18,7 @@ void destroy_libinput_input_device(struct wlr_libinput_input_device *dev) {
|
|||||||
wlr_keyboard_finish(&dev->keyboard);
|
wlr_keyboard_finish(&dev->keyboard);
|
||||||
}
|
}
|
||||||
if (dev->pointer.impl) {
|
if (dev->pointer.impl) {
|
||||||
wlr_pointer_destroy(&dev->pointer);
|
wlr_pointer_finish(&dev->pointer);
|
||||||
}
|
}
|
||||||
if (dev->switch_device.impl) {
|
if (dev->switch_device.impl) {
|
||||||
wlr_switch_destroy(&dev->switch_device);
|
wlr_switch_destroy(&dev->switch_device);
|
||||||
|
@ -4,12 +4,8 @@
|
|||||||
#include "backend/libinput.h"
|
#include "backend/libinput.h"
|
||||||
#include "util/signal.h"
|
#include "util/signal.h"
|
||||||
|
|
||||||
static void pointer_destroy(struct wlr_pointer *pointer) {
|
|
||||||
/* wlr_pointer belongs to the wlr_libinput_input_device */
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct wlr_pointer_impl libinput_pointer_impl = {
|
const struct wlr_pointer_impl libinput_pointer_impl = {
|
||||||
.destroy = pointer_destroy,
|
.name = "libinput-pointer",
|
||||||
};
|
};
|
||||||
|
|
||||||
void init_device_pointer(struct wlr_libinput_input_device *dev) {
|
void init_device_pointer(struct wlr_libinput_input_device *dev) {
|
||||||
|
@ -500,29 +500,6 @@ struct wlr_wl_input_device *create_wl_input_device(
|
|||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_wl_input_device(struct wlr_wl_input_device *dev) {
|
|
||||||
/**
|
|
||||||
* TODO remove the redundant wlr_input_device from wlr_wl_input_device
|
|
||||||
* wlr_wl_input_device::wlr_input_device is not owned by its input device
|
|
||||||
* type, which means we have 2 wlr_input_device to cleanup
|
|
||||||
*/
|
|
||||||
wlr_input_device_finish(&dev->wlr_input_device);
|
|
||||||
if (dev->wlr_input_device._device) {
|
|
||||||
struct wlr_input_device *wlr_dev = &dev->wlr_input_device;
|
|
||||||
switch (wlr_dev->type) {
|
|
||||||
case WLR_INPUT_DEVICE_KEYBOARD:
|
|
||||||
wlr_keyboard_finish(wlr_dev->keyboard);
|
|
||||||
free(wlr_dev->keyboard);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
wlr_input_device_destroy(wlr_dev);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wl_list_remove(&dev->link);
|
|
||||||
free(dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct wlr_wl_pointer *pointer_get_wl(struct wlr_pointer *wlr_pointer) {
|
struct wlr_wl_pointer *pointer_get_wl(struct wlr_pointer *wlr_pointer) {
|
||||||
assert(wlr_pointer->impl == &pointer_impl);
|
assert(wlr_pointer->impl == &pointer_impl);
|
||||||
return (struct wlr_wl_pointer *)wlr_pointer;
|
return (struct wlr_wl_pointer *)wlr_pointer;
|
||||||
@ -555,13 +532,37 @@ static void pointer_destroy(struct wlr_pointer *wlr_pointer) {
|
|||||||
zwp_relative_pointer_v1_destroy(pointer->relative_pointer);
|
zwp_relative_pointer_v1_destroy(pointer->relative_pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wlr_pointer_finish(&pointer->wlr_pointer);
|
||||||
wl_list_remove(&pointer->output_destroy.link);
|
wl_list_remove(&pointer->output_destroy.link);
|
||||||
free(pointer);
|
free(pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct wlr_pointer_impl pointer_impl = {
|
void destroy_wl_input_device(struct wlr_wl_input_device *dev) {
|
||||||
.destroy = pointer_destroy,
|
/**
|
||||||
};
|
* TODO remove the redundant wlr_input_device from wlr_wl_input_device
|
||||||
|
* wlr_wl_input_device::wlr_input_device is not owned by its input device
|
||||||
|
* type, which means we have 2 wlr_input_device to cleanup
|
||||||
|
*/
|
||||||
|
wlr_input_device_finish(&dev->wlr_input_device);
|
||||||
|
if (dev->wlr_input_device._device) {
|
||||||
|
struct wlr_input_device *wlr_dev = &dev->wlr_input_device;
|
||||||
|
switch (wlr_dev->type) {
|
||||||
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
||||||
|
wlr_keyboard_finish(wlr_dev->keyboard);
|
||||||
|
free(wlr_dev->keyboard);
|
||||||
|
break;
|
||||||
|
case WLR_INPUT_DEVICE_POINTER:
|
||||||
|
/* Owned by wlr_wl_pointer */
|
||||||
|
pointer_destroy(wlr_dev->pointer);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
wlr_input_device_destroy(wlr_dev);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wl_list_remove(&dev->link);
|
||||||
|
free(dev);
|
||||||
|
}
|
||||||
|
|
||||||
static void gesture_swipe_begin(void *data,
|
static void gesture_swipe_begin(void *data,
|
||||||
struct zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1,
|
struct zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1,
|
||||||
|
@ -289,12 +289,8 @@ const struct wlr_keyboard_impl x11_keyboard_impl = {
|
|||||||
.name = "x11-keyboard",
|
.name = "x11-keyboard",
|
||||||
};
|
};
|
||||||
|
|
||||||
static void pointer_destroy(struct wlr_pointer *wlr_pointer) {
|
|
||||||
// Don't free the pointer, it's on the stack
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct wlr_pointer_impl x11_pointer_impl = {
|
const struct wlr_pointer_impl x11_pointer_impl = {
|
||||||
.destroy = pointer_destroy,
|
.name = "x11-pointer",
|
||||||
};
|
};
|
||||||
|
|
||||||
static void touch_destroy(struct wlr_touch *wlr_touch) {
|
static void touch_destroy(struct wlr_touch *wlr_touch) {
|
||||||
|
@ -76,7 +76,7 @@ static void output_destroy(struct wlr_output *wlr_output) {
|
|||||||
|
|
||||||
pixman_region32_fini(&output->exposed);
|
pixman_region32_fini(&output->exposed);
|
||||||
|
|
||||||
wlr_pointer_destroy(&output->pointer);
|
wlr_pointer_finish(&output->pointer);
|
||||||
wlr_touch_destroy(&output->touch);
|
wlr_touch_destroy(&output->touch);
|
||||||
|
|
||||||
struct wlr_x11_buffer *buffer, *buffer_tmp;
|
struct wlr_x11_buffer *buffer, *buffer_tmp;
|
||||||
|
@ -12,11 +12,11 @@
|
|||||||
#include <wlr/types/wlr_pointer.h>
|
#include <wlr/types/wlr_pointer.h>
|
||||||
|
|
||||||
struct wlr_pointer_impl {
|
struct wlr_pointer_impl {
|
||||||
void (*destroy)(struct wlr_pointer *pointer);
|
const char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
void wlr_pointer_init(struct wlr_pointer *pointer,
|
void wlr_pointer_init(struct wlr_pointer *pointer,
|
||||||
const struct wlr_pointer_impl *impl, const char *name);
|
const struct wlr_pointer_impl *impl, const char *name);
|
||||||
void wlr_pointer_destroy(struct wlr_pointer *pointer);
|
void wlr_pointer_finish(struct wlr_pointer *pointer);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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_pointer.h>
|
|
||||||
#include <wlr/interfaces/wlr_switch.h>
|
#include <wlr/interfaces/wlr_switch.h>
|
||||||
#include <wlr/interfaces/wlr_tablet_pad.h>
|
#include <wlr/interfaces/wlr_tablet_pad.h>
|
||||||
#include <wlr/interfaces/wlr_tablet_tool.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");
|
wlr_log(WLR_ERROR, "wlr_keyboard will not be destroyed");
|
||||||
break;
|
break;
|
||||||
case WLR_INPUT_DEVICE_POINTER:
|
case WLR_INPUT_DEVICE_POINTER:
|
||||||
wlr_pointer_destroy(dev->pointer);
|
wlr_log(WLR_ERROR, "wlr_pointer will not be destroyed");
|
||||||
break;
|
break;
|
||||||
case WLR_INPUT_DEVICE_SWITCH:
|
case WLR_INPUT_DEVICE_SWITCH:
|
||||||
wlr_switch_destroy(dev->switch_device);
|
wlr_switch_destroy(dev->switch_device);
|
||||||
|
@ -25,14 +25,6 @@ void wlr_pointer_init(struct wlr_pointer *pointer,
|
|||||||
wl_signal_init(&pointer->events.hold_end);
|
wl_signal_init(&pointer->events.hold_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_pointer_destroy(struct wlr_pointer *pointer) {
|
void wlr_pointer_finish(struct wlr_pointer *pointer) {
|
||||||
if (!pointer) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
wlr_input_device_finish(&pointer->base);
|
wlr_input_device_finish(&pointer->base);
|
||||||
if (pointer->impl && pointer->impl->destroy) {
|
|
||||||
pointer->impl->destroy(pointer);
|
|
||||||
} else {
|
|
||||||
free(pointer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,8 @@
|
|||||||
#include "util/signal.h"
|
#include "util/signal.h"
|
||||||
#include "wlr-virtual-pointer-unstable-v1-protocol.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 = {
|
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;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: rework wlr_pointer device destruction */
|
|
||||||
wlr_signal_emit_safe(&pointer->events.destroy, pointer);
|
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_resource_set_user_data(pointer->resource, NULL);
|
||||||
wl_list_remove(&pointer->link);
|
wl_list_remove(&pointer->link);
|
||||||
free(pointer);
|
free(pointer);
|
||||||
@ -251,7 +248,7 @@ static void virtual_pointer_manager_create_virtual_pointer_with_output(
|
|||||||
}
|
}
|
||||||
|
|
||||||
wlr_pointer_init(&virtual_pointer->pointer, &pointer_impl,
|
wlr_pointer_init(&virtual_pointer->pointer, &pointer_impl,
|
||||||
"virtual-pointer");
|
"wlr_virtual_pointer_v1");
|
||||||
|
|
||||||
struct wl_resource *pointer_resource = wl_resource_create(client,
|
struct wl_resource *pointer_resource = wl_resource_create(client,
|
||||||
&zwlr_virtual_pointer_v1_interface, wl_resource_get_version(resource),
|
&zwlr_virtual_pointer_v1_interface, wl_resource_get_version(resource),
|
||||||
|
Loading…
Reference in New Issue
Block a user