Make libinput backend optional

This commit is contained in:
Simon Ser 2022-11-26 20:18:43 +01:00 committed by Simon Zeni
parent 46170580b2
commit e62299daa4
7 changed files with 59 additions and 8 deletions

View file

@ -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')

View file

@ -1,14 +1,19 @@
#include <limits.h>
#include <string.h>
#include <strings.h>
#include <wlr/backend/libinput.h>
#include <wlr/config.h>
#include "sway/config.h"
#include "sway/commands.h"
#include "sway/input/input-manager.h"
#include "log.h"
#if WLR_HAS_LIBINPUT_BACKEND
#include <wlr/backend/libinput.h>
#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) {

View file

@ -3,7 +3,7 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <wlr/backend/libinput.h>
#include <wlr/config.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_keyboard_group.h>
#include <wlr/types/wlr_input_inhibitor.h>
@ -22,6 +22,10 @@
#include "list.h"
#include "log.h"
#if WLR_HAS_LIBINPUT_BACKEND
#include <wlr/backend/libinput.h>
#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);

View file

@ -4,6 +4,7 @@
#include <string.h>
#include <strings.h>
#include <time.h>
#include <wlr/config.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_idle.h>
@ -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;
}

View file

@ -1,6 +1,6 @@
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <wlr/backend/libinput.h>
#include <wlr/config.h>
#include <wlr/types/wlr_tablet_v2.h>
#include <wlr/types/wlr_tablet_tool.h>
#include <wlr/types/wlr_tablet_pad.h>
@ -9,6 +9,10 @@
#include "sway/input/seat.h"
#include "sway/input/tablet.h"
#if WLR_HAS_LIBINPUT_BACKEND
#include <wlr/backend/libinput.h>
#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) {

View file

@ -3,7 +3,7 @@
#include <json.h>
#include <libevdev/libevdev.h>
#include <stdio.h>
#include <wlr/backend/libinput.h>
#include <wlr/config.h>
#include <wlr/types/wlr_content_type_v1.h>
#include <wlr/types/wlr_output.h>
#include <xkbcommon/xkbcommon.h>
@ -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 <wlr/backend/libinput.h>
#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;
}

View file

@ -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(