From e62299daa45de139b912325eb5800796586e57c7 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sat, 26 Nov 2022 20:18:43 +0100 Subject: [PATCH] Make libinput backend optional --- meson.build | 4 ++-- sway/commands/input/events.c | 10 +++++++++- sway/input/input-manager.c | 20 +++++++++++++++++++- sway/input/seat.c | 6 ++++++ sway/input/tablet.c | 10 +++++++++- sway/ipc-json.c | 10 +++++++++- sway/meson.build | 7 +++++-- 7 files changed, 59 insertions(+), 8 deletions(-) diff --git a/meson.build b/meson.build index 5468064f..20ed8424 100644 --- a/meson.build +++ b/meson.build @@ -76,11 +76,11 @@ gdk_pixbuf = dependency('gdk-pixbuf-2.0', required: get_option('gdk-pixbuf')) pixman = dependency('pixman-1') glesv2 = wlroots_features['gles2_renderer'] ? dependency('glesv2') : null_dep libevdev = dependency('libevdev') -libinput = dependency('libinput', version: '>=1.21.0') +libinput = wlroots_features['libinput_backend'] ? dependency('libinput', version: '>=1.21.0') : null_dep xcb = dependency('xcb', required: get_option('xwayland')) drm_full = dependency('libdrm') # only needed for drm_fourcc.h drm = drm_full.partial_dependency(compile_args: true, includes: true) -libudev = dependency('libudev') +libudev = wlroots_features['libinput_backend'] ? dependency('libudev') : null_dep bash_comp = dependency('bash-completion', required: false) fish_comp = dependency('fish', required: false) math = cc.find_library('m') diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c index 9405181a..08d99bf0 100644 --- a/sway/commands/input/events.c +++ b/sway/commands/input/events.c @@ -1,14 +1,19 @@ #include #include #include -#include +#include #include "sway/config.h" #include "sway/commands.h" #include "sway/input/input-manager.h" #include "log.h" +#if WLR_HAS_LIBINPUT_BACKEND +#include +#endif + static void toggle_supported_send_events_for_device(struct input_config *ic, struct sway_input_device *input_device) { +#if WLR_HAS_LIBINPUT_BACKEND struct wlr_input_device *wlr_device = input_device->wlr_device; if (!wlr_input_device_is_libinput(wlr_device)) { return; @@ -41,6 +46,7 @@ static void toggle_supported_send_events_for_device(struct input_config *ic, } ic->send_events = mode; +#endif } static int mode_for_name(const char *name) { @@ -56,6 +62,7 @@ static int mode_for_name(const char *name) { static void toggle_select_send_events_for_device(struct input_config *ic, struct sway_input_device *input_device, int argc, char **argv) { +#if WLR_HAS_LIBINPUT_BACKEND if (!wlr_input_device_is_libinput(input_device->wlr_device)) { return; } @@ -72,6 +79,7 @@ static void toggle_select_send_events_for_device(struct input_config *ic, } } ic->send_events = mode_for_name(argv[index % argc]); +#endif } static void toggle_send_events(int argc, char **argv) { diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 26eefc8a..634d8981 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -22,6 +22,10 @@ #include "list.h" #include "log.h" +#if WLR_HAS_LIBINPUT_BACKEND +#include +#endif + #define DEFAULT_SEAT "seat0" struct input_config *current_input_config = NULL; @@ -90,6 +94,7 @@ char *input_device_get_identifier(struct wlr_input_device *device) { } static bool device_is_touchpad(struct sway_input_device *device) { +#if WLR_HAS_LIBINPUT_BACKEND if (device->wlr_device->type != WLR_INPUT_DEVICE_POINTER || !wlr_input_device_is_libinput(device->wlr_device)) { return false; @@ -99,6 +104,9 @@ static bool device_is_touchpad(struct sway_input_device *device) { wlr_libinput_get_device_handle(device->wlr_device); return libinput_device_config_tap_get_finger_count(libinput_device) > 0; +#else + return false; +#endif } const char *input_device_get_type(struct sway_input_device *device) { @@ -236,7 +244,11 @@ static void handle_new_input(struct wl_listener *listener, void *data) { apply_input_type_config(input_device); +#if WLR_HAS_LIBINPUT_BACKEND bool config_changed = sway_input_configure_libinput_device(input_device); +#else + bool config_changed = false; +#endif wl_signal_add(&device->events.destroy, &input_device->device_destroy); input_device->device_destroy.notify = handle_device_destroy; @@ -532,7 +544,11 @@ static void retranslate_keysyms(struct input_config *input_config) { static void input_manager_configure_input( struct sway_input_device *input_device) { +#if WLR_HAS_LIBINPUT_BACKEND bool config_changed = sway_input_configure_libinput_device(input_device); +#else + bool config_changed = false; +#endif struct sway_seat *seat = NULL; wl_list_for_each(seat, &server.input->seats, link) { seat_configure_device(seat, input_device); @@ -567,7 +583,9 @@ void input_manager_apply_input_config(struct input_config *input_config) { } void input_manager_reset_input(struct sway_input_device *input_device) { +#if WLR_HAS_LIBINPUT_BACKEND sway_input_reset_libinput_device(input_device); +#endif struct sway_seat *seat = NULL; wl_list_for_each(seat, &server.input->seats, link) { seat_reset_device(seat, input_device); diff --git a/sway/input/seat.c b/sway/input/seat.c index c263eb82..4919bed0 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -750,6 +751,7 @@ static void seat_apply_input_config(struct sway_seat *seat, mapped_to_output = NULL; break; } +#if WLR_HAS_LIBINPUT_BACKEND if (mapped_to_output == NULL && is_touch_or_tablet_tool(sway_device) && sway_libinput_device_is_builtin(sway_device->input_device)) { mapped_to_output = get_builtin_output_name(); @@ -758,6 +760,10 @@ static void seat_apply_input_config(struct sway_seat *seat, mapped_to_output, sway_device->input_device->identifier); } } +#else + (void)is_touch_or_tablet_tool; + (void)get_builtin_output_name; +#endif if (mapped_to_output == NULL) { return; } diff --git a/sway/input/tablet.c b/sway/input/tablet.c index 92ede3fa..a62e77ec 100644 --- a/sway/input/tablet.c +++ b/sway/input/tablet.c @@ -1,6 +1,6 @@ #define _POSIX_C_SOURCE 200809L #include -#include +#include #include #include #include @@ -9,6 +9,10 @@ #include "sway/input/seat.h" #include "sway/input/tablet.h" +#if WLR_HAS_LIBINPUT_BACKEND +#include +#endif + static void handle_pad_tablet_destroy(struct wl_listener *listener, void *data) { struct sway_tablet_pad *pad = wl_container_of(listener, pad, tablet_destroy); @@ -63,6 +67,7 @@ void sway_configure_tablet(struct sway_tablet *tablet) { wlr_tablet_create(server.tablet_v2, seat->wlr_seat, device); } +#if WLR_HAS_LIBINPUT_BACKEND /* Search for a sibling tablet pad */ if (!wlr_input_device_is_libinput(device)) { /* We can only do this on libinput devices */ @@ -87,6 +92,7 @@ void sway_configure_tablet(struct sway_tablet *tablet) { break; } } +#endif } void sway_tablet_destroy(struct sway_tablet *tablet) { @@ -287,6 +293,7 @@ void sway_configure_tablet_pad(struct sway_tablet_pad *tablet_pad) { tablet_pad->ring.notify = handle_tablet_pad_ring; wl_signal_add(&tablet_pad->wlr->events.ring, &tablet_pad->ring); +#if WLR_HAS_LIBINPUT_BACKEND /* Search for a sibling tablet */ if (!wlr_input_device_is_libinput(wlr_device)) { /* We can only do this on libinput devices */ @@ -311,6 +318,7 @@ void sway_configure_tablet_pad(struct sway_tablet_pad *tablet_pad) { break; } } +#endif } void sway_tablet_pad_destroy(struct sway_tablet_pad *tablet_pad) { diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 73a3d376..8aa9557e 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -21,6 +21,10 @@ #include "wlr-layer-shell-unstable-v1-protocol.h" #include "sway/desktop/idle_inhibit_v1.h" +#if WLR_HAS_LIBINPUT_BACKEND +#include +#endif + static const int i3_output_id = INT32_MAX; static const int i3_scratch_id = INT32_MAX - 1; @@ -847,6 +851,7 @@ json_object *ipc_json_describe_node_recursive(struct sway_node *node) { return object; } +#if WLR_HAS_LIBINPUT_BACKEND static json_object *describe_libinput_device(struct libinput_device *device) { json_object *object = json_object_new_object(); @@ -1052,6 +1057,7 @@ static json_object *describe_libinput_device(struct libinput_device *device) { return object; } +#endif json_object *ipc_json_describe_input(struct sway_input_device *device) { if (!(sway_assert(device, "Device must not be null"))) { @@ -1115,12 +1121,14 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) { json_object_new_double(scroll_factor)); } +#if WLR_HAS_LIBINPUT_BACKEND if (wlr_input_device_is_libinput(device->wlr_device)) { struct libinput_device *libinput_dev; libinput_dev = wlr_libinput_get_device_handle(device->wlr_device); json_object_object_add(object, "libinput", describe_libinput_device(libinput_dev)); } +#endif return object; } diff --git a/sway/meson.build b/sway/meson.build index 8a73cc86..de10e14f 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -26,7 +26,6 @@ sway_sources = files( 'input/input-manager.c', 'input/cursor.c', 'input/keyboard.c', - 'input/libinput.c', 'input/seat.c', 'input/seatop_default.c', 'input/seatop_down.c', @@ -227,12 +226,16 @@ sway_deps = [ wayland_server, wlroots, xkbcommon, + xcb, xcb_icccm, ] if have_xwayland sway_sources += 'desktop/xwayland.c' - sway_deps += xcb +endif + +if wlroots_features['libinput_backend'] + sway_sources += 'input/libinput.c' endif executable(