From 44a4792fd80acfeb15e2cf88304f283855689fd0 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 6 Nov 2020 10:16:07 +0100 Subject: backend/session: operate on wlr_device Instead of operating on FDs in {open,close}_device, operate on wlr_devices. This avoids the device lookup in wlr_session and allows callers to have access to wlr_device fields. For now, we use it to remove wlr_session_signal_add and replace it with a more idiomatic wlr_session.events.change field. In the future, other events will be added. --- backend/libinput/backend.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'backend/libinput') diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 12f76bbf..7037084d 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -17,12 +17,27 @@ static struct wlr_libinput_backend *get_libinput_backend_from_backend( static int libinput_open_restricted(const char *path, int flags, void *_backend) { struct wlr_libinput_backend *backend = _backend; - return wlr_session_open_file(backend->session, path); + struct wlr_device *dev = wlr_session_open_file(backend->session, path); + if (dev == NULL) { + return -1; + } + return dev->fd; } static void libinput_close_restricted(int fd, void *_backend) { struct wlr_libinput_backend *backend = _backend; - wlr_session_close_file(backend->session, fd); + + struct wlr_device *dev; + bool found = false; + wl_list_for_each(dev, &backend->session->devices, link) { + if (dev->fd == fd) { + found = true; + break; + } + } + if (found) { + wlr_session_close_file(backend->session, dev); + } } static const struct libinput_interface libinput_impl = { -- cgit v1.2.3