From 3468395cba5abcf54b2beb054241b254f610928d Mon Sep 17 00:00:00 2001 From: illiliti Date: Sun, 13 Mar 2022 22:45:09 +0300 Subject: [PATCH] backend/libinput/backend.c, backend/libinput/tablet_pad.c, backend/libinput/tablet_tool.c, backend/session/session.c: make udev optional --- backend/libinput/backend.c | 22 +++++++++++++++++++++- backend/libinput/tablet_pad.c | 8 +++++++- backend/libinput/tablet_tool.c | 8 +++++++- backend/session/meson.build | 17 ++++++++++++++++- backend/session/session.c | 10 ++++++++++ include/wlr/config.h.in | 2 ++ meson.build | 3 +-- meson_options.txt | 1 + 8 files changed, 65 insertions(+), 6 deletions(-) diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 5eac2c96b..2dcbc5024 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -5,10 +5,16 @@ #include #include #include +#include #include "backend/libinput.h" -#include "backend/session/dev_udev.h" #include "util/signal.h" +#if WLR_HAS_UDEV +#include "backend/session/dev_udev.h" +#endif + +#define NETLINK_BITMASK 4 + static struct wlr_libinput_backend *get_libinput_backend_from_backend( struct wlr_backend *wlr_backend) { assert(wlr_backend_is_libinput(wlr_backend)); @@ -87,15 +93,29 @@ static bool backend_start(struct wlr_backend *wlr_backend) { get_libinput_backend_from_backend(wlr_backend); wlr_log(WLR_DEBUG, "Starting libinput backend"); +#if WLR_HAS_UDEV backend->libinput_context = libinput_udev_create_context(&libinput_impl, backend, backend->session->dev->udev); +#elif defined(__linux__) + backend->libinput_context = libinput_netlink_create_context(&libinput_impl, + backend, NETLINK_BITMASK); +#else +#error Unsupported platform +#endif if (!backend->libinput_context) { wlr_log(WLR_ERROR, "Failed to create libinput context"); return false; } +#if WLR_HAS_UDEV if (libinput_udev_assign_seat(backend->libinput_context, backend->session->seat) != 0) { +#elif defined(__linux__) + if (libinput_netlink_assign_seat(backend->libinput_context, + backend->session->seat) != 0) { +#else +#error Unsupported platform +#endif wlr_log(WLR_ERROR, "Failed to assign libinput seat"); return false; } diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index 8b9daef72..580676ec4 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -3,12 +3,16 @@ #include #include #include -#include #include #include +#include #include "backend/libinput.h" #include "util/signal.h" +#if WLR_HAS_UDEV +#include +#endif + const struct wlr_tablet_pad_impl libinput_tablet_pad_impl = { .name = "libinput-tablet-pad", }; @@ -107,9 +111,11 @@ void init_device_tablet_pad(struct wlr_libinput_input_device *dev) { wlr_tablet_pad->strip_count = libinput_device_tablet_pad_get_num_strips(handle); +#if WLR_HAS_UDEV struct udev_device *udev = libinput_device_get_udev_device(handle); char **dst = wl_array_add(&wlr_tablet_pad->paths, sizeof(char *)); *dst = strdup(udev_device_get_syspath(udev)); +#endif int groups = libinput_device_tablet_pad_get_num_mode_groups(handle); for (int i = 0; i < groups; ++i) { diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 04f11d8fa..5d0f6edba 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -3,12 +3,16 @@ #include #include #include -#include #include #include +#include #include "backend/libinput.h" #include "util/signal.h" +#if WLR_HAS_UDEV +#include +#endif + struct tablet_tool { struct wlr_tablet_tool wlr_tool; struct libinput_tablet_tool *handle; @@ -29,9 +33,11 @@ void init_device_tablet(struct wlr_libinput_input_device *dev) { libinput_device_get_size(dev->handle, &wlr_tablet->width_mm, &wlr_tablet->height_mm); +#if WLR_HAS_UDEV struct udev_device *udev = libinput_device_get_udev_device(dev->handle); char **dst = wl_array_add(&wlr_tablet->paths, sizeof(char *)); *dst = strdup(udev_device_get_syspath(udev)); +#endif wl_list_init(&dev->tablet_tools); } diff --git a/backend/session/meson.build b/backend/session/meson.build index f0ff132f1..f407a2131 100644 --- a/backend/session/meson.build +++ b/backend/session/meson.build @@ -3,5 +3,20 @@ libseat = dependency('libseat', fallback: 'seatd', default_options: ['server=disabled', 'man-pages=disabled'], ) -wlr_files += files('session.c', 'dev_udev.c') +wlr_files += files('session.c') wlr_deps += libseat + +# libudev + +if get_option('enum-backend') == 'auto' + udev = dependency('libudev', required: false) + if udev.found() + wlr_files += files('dev_udev.c') + wlr_deps += udev + features += { 'udev': true } + endif +elif get_option('enum-backend') == 'udev' + wlr_files += files('dev_udev.c') + wlr_deps += dependency('libudev') + features += { 'udev': true } +endif diff --git a/backend/session/session.c b/backend/session/session.c index cd46a04fb..2d18d4231 100644 --- a/backend/session/session.c +++ b/backend/session/session.c @@ -144,10 +144,12 @@ struct wlr_session *wlr_session_create(struct wl_display *disp) { goto error_open; } +#if WLR_HAS_UDEV if (dev_init(session, disp) == -1) { wlr_log(WLR_ERROR, "Failed to initialize dev backend"); goto error_session; } +#endif session->display = disp; @@ -156,8 +158,10 @@ struct wlr_session *wlr_session_create(struct wl_display *disp) { return session; +#if WLR_HAS_UDEV error_session: libseat_session_finish(session); +#endif error_open: free(session); return NULL; @@ -171,7 +175,9 @@ void wlr_session_destroy(struct wlr_session *session) { wlr_signal_emit_safe(&session->events.destroy, session); wl_list_remove(&session->display_destroy.link); +#if WLR_HAS_UDEV dev_finish(session); +#endif struct wlr_device *dev, *tmp_dev; wl_list_for_each_safe(dev, tmp_dev, &session->devices, link) { @@ -293,5 +299,9 @@ ssize_t wlr_session_find_gpus(struct wlr_session *session, return explicit_find_gpus(session, ret_len, ret, explicit); } +#if WLR_HAS_UDEV return dev_find_gpus(session, ret_len, ret); +#endif + + return -1; } diff --git a/include/wlr/config.h.in b/include/wlr/config.h.in index 71868a349..e636bf5e0 100644 --- a/include/wlr/config.h.in +++ b/include/wlr/config.h.in @@ -11,4 +11,6 @@ #mesondefine WLR_HAS_XWAYLAND +#mesondefine WLR_HAS_UDEV + #endif diff --git a/meson.build b/meson.build index f7fb659c4..ec3b734db 100644 --- a/meson.build +++ b/meson.build @@ -92,6 +92,7 @@ features = { 'xwayland': false, 'gles2-renderer': false, 'vulkan-renderer': false, + 'udev': false, } internal_features = { 'xcb-errors': false, @@ -127,7 +128,6 @@ drm = dependency('libdrm', ) gbm = dependency('gbm', version: '>=17.1.0') xkbcommon = dependency('xkbcommon') -udev = dependency('libudev') pixman = dependency('pixman-1') math = cc.find_library('m') rt = cc.find_library('rt') @@ -138,7 +138,6 @@ wlr_deps = [ drm, gbm, xkbcommon, - udev, pixman, math, rt, diff --git a/meson_options.txt b/meson_options.txt index 550acbe6f..01eca736e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -4,3 +4,4 @@ option('examples', type: 'boolean', value: true, description: 'Build example app option('icon_directory', description: 'Location used to look for cursors (default: ${datadir}/icons)', type: 'string', value: '') option('renderers', type: 'array', choices: ['auto', 'gles2', 'vulkan'], value: ['auto'], description: 'Select built-in renderers') option('backends', type: 'array', choices: ['auto', 'drm', 'libinput', 'x11'], value: ['auto'], description: 'Select built-in backends') +option('enum-backend', type: 'combo', choices: ['auto', 'disabled', 'udev'], value: 'udev', description: 'Select device enumeration backend')