backend/libinput: add devices wl_list

This commit prepares the ground for a wlr_libinput_input_device refactoring.
This commit is contained in:
Simon Zeni 2022-02-22 16:17:48 -05:00 committed by Kirill Primak
parent 0a5a65cf48
commit 9dd6e2b905
3 changed files with 21 additions and 2 deletions

View File

@ -110,9 +110,11 @@ static bool backend_start(struct wlr_backend *wlr_backend) {
no_devs = NULL;
}
}
if (!no_devs && backend->wlr_device_lists.size == 0) {
if (!no_devs && (backend->wlr_device_lists.size == 0
|| wl_list_empty(&backend->devices))) {
handle_libinput_readable(libinput_fd, WL_EVENT_READABLE, backend);
if (backend->wlr_device_lists.size == 0) {
if (backend->wlr_device_lists.size == 0
&& wl_list_empty(&backend->devices)) {
wlr_log(WLR_ERROR, "libinput initialization failed, no input devices");
wlr_log(WLR_ERROR, "Set WLR_LIBINPUT_NO_DEVICES=1 to suppress this check");
return false;
@ -150,6 +152,11 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
free(*wlr_devices_ptr);
}
struct wlr_libinput_input_device *dev, *tmp;
wl_list_for_each_safe(dev, tmp, &backend->devices, link) {
destroy_libinput_input_device(dev);
}
wlr_backend_finish(wlr_backend);
wl_list_remove(&backend->display_destroy.link);
@ -212,6 +219,7 @@ struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display,
wlr_backend_init(&backend->backend, &backend_impl);
wl_array_init(&backend->wlr_device_lists);
wl_list_init(&backend->devices);
backend->session = session;
backend->display = display;

View File

@ -224,6 +224,16 @@ static void handle_device_removed(struct wlr_libinput_backend *backend,
int product = libinput_device_get_id_product(libinput_dev);
const char *name = libinput_device_get_name(libinput_dev);
wlr_log(WLR_DEBUG, "Removing %s [%d:%d]", name, vendor, product);
if (!wl_list_empty(&backend->devices)) {
struct wlr_libinput_input_device *dev, *tmp_dev;
wl_list_for_each_safe(dev, tmp_dev, &backend->devices, link) {
if (dev->handle == libinput_dev) {
destroy_libinput_input_device(dev);
}
}
}
if (!wlr_devices) {
return;
}

View File

@ -27,6 +27,7 @@ struct wlr_libinput_backend {
struct wl_listener session_signal;
struct wl_array wlr_device_lists; // struct wl_list *
struct wl_list devices; // wlr_libinput_device::link
};
struct wlr_libinput_input_device {