From 8aedf7b11e32301cb25673cace238e840e06a63a Mon Sep 17 00:00:00 2001 From: Giulio Camuffo Date: Thu, 2 Jun 2016 21:48:12 +0300 Subject: [PATCH] libinput: don't use weston_config when configuring input devices Instead add callbacks to the drm and fbdev backends and pass that to the input backens so that when a new device needs to be configured that is called and the compositor can configure it. Signed-off-by: Giulio Camuffo Reviewed-by: Quentin Glidic Reviewed-by: Pekka Paalanen --- Makefile.am | 3 ++- src/compositor-drm.c | 3 ++- src/compositor-drm.h | 11 +++++++++++ src/compositor-fbdev.c | 3 ++- src/compositor-fbdev.h | 11 +++++++++++ src/libinput-device.c | 31 +------------------------------ src/libinput-device.h | 2 ++ src/libinput-seat.c | 7 ++++++- src/libinput-seat.h | 9 ++++++++- src/main.c | 27 +++++++++++++++++++++++++++ 10 files changed, 72 insertions(+), 35 deletions(-) diff --git a/Makefile.am b/Makefile.am index 1b323006..fd10c131 100644 --- a/Makefile.am +++ b/Makefile.am @@ -65,7 +65,8 @@ weston_LDFLAGS = -export-dynamic weston_CPPFLAGS = $(AM_CPPFLAGS) -DIN_WESTON weston_CFLAGS = $(AM_CFLAGS) $(COMPOSITOR_CFLAGS) $(LIBUNWIND_CFLAGS) weston_LDADD = $(COMPOSITOR_LIBS) $(LIBUNWIND_LIBS) \ - $(DLOPEN_LIBS) -lm $(CLOCK_GETTIME_LIBS) libshared.la + $(DLOPEN_LIBS) -lm $(CLOCK_GETTIME_LIBS) \ + $(LIBINPUT_BACKEND_LIBS) libshared.la weston_SOURCES = \ src/git-version.h \ diff --git a/src/compositor-drm.c b/src/compositor-drm.c index 893877d9..39d061b5 100644 --- a/src/compositor-drm.c +++ b/src/compositor-drm.c @@ -3121,7 +3121,8 @@ drm_backend_create(struct weston_compositor *compositor, create_sprites(b); if (udev_input_init(&b->input, - compositor, b->udev, seat_id) < 0) { + compositor, b->udev, seat_id, + config->configure_device) < 0) { weston_log("failed to create input devices\n"); goto err_sprite; } diff --git a/src/compositor-drm.h b/src/compositor-drm.h index 3f150dba..1266031f 100644 --- a/src/compositor-drm.h +++ b/src/compositor-drm.h @@ -36,6 +36,8 @@ extern "C" { #define WESTON_DRM_BACKEND_CONFIG_VERSION 1 +struct libinput_device; + enum weston_drm_backend_output_mode { /** The output is disabled */ WESTON_DRM_BACKEND_OUTPUT_OFF, @@ -117,6 +119,15 @@ struct weston_drm_backend_config { bool use_current_mode, const char *name, struct weston_drm_backend_output_config *output_config); + + /** Callback used to configure input devices. + * + * This function will be called by the backend when a new input device + * needs to be configured. + * If NULL the device will use the default configuration. + */ + void (*configure_device)(struct weston_compositor *compositor, + struct libinput_device *device); bool use_current_mode; }; diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c index ee762e31..f66fe479 100644 --- a/src/compositor-fbdev.c +++ b/src/compositor-fbdev.c @@ -797,7 +797,8 @@ fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv if (fbdev_output_create(backend, param->device) < 0) goto out_launcher; - udev_input_init(&backend->input, compositor, backend->udev, seat_id); + udev_input_init(&backend->input, compositor, backend->udev, + seat_id, param->configure_device); compositor->backend = &backend->base; return backend; diff --git a/src/compositor-fbdev.h b/src/compositor-fbdev.h index bd60bdc4..450be5d1 100644 --- a/src/compositor-fbdev.h +++ b/src/compositor-fbdev.h @@ -34,6 +34,8 @@ extern "C" { #define WESTON_FBDEV_BACKEND_CONFIG_VERSION 1 +struct libinput_device; + struct weston_fbdev_backend_config { struct weston_backend_config base; @@ -42,6 +44,15 @@ struct weston_fbdev_backend_config { int use_gl; uint32_t output_transform; + + /** Callback used to configure input devices. + * + * This function will be called by the backend when a new input device + * needs to be configured. + * If NULL the device will use the default configuration. + */ + void (*configure_device)(struct weston_compositor *compositor, + struct libinput_device *device); }; #ifdef __cplusplus diff --git a/src/libinput-device.c b/src/libinput-device.c index 2126084c..62350f2e 100644 --- a/src/libinput-device.c +++ b/src/libinput-device.c @@ -39,7 +39,6 @@ #include "compositor.h" #include "libinput-device.h" #include "shared/helpers.h" -#include "weston.h" void evdev_led_update(struct evdev_device *device, enum weston_led weston_leds) @@ -430,7 +429,7 @@ notify_output_destroy(struct wl_listener *listener, void *data) * can't do that, so we need to convert the calibration to the normalized * format libinput expects. */ -static void +void evdev_device_set_calibration(struct evdev_device *device) { struct udev *udev; @@ -524,32 +523,6 @@ evdev_device_set_output(struct evdev_device *device, evdev_device_set_calibration(device); } -static void -configure_device(struct evdev_device *device) -{ - struct weston_compositor *compositor = device->seat->compositor; - struct weston_config_section *s; - struct weston_config *config = wet_get_config(compositor); - int enable_tap; - int enable_tap_default; - - s = weston_config_get_section(config, - "libinput", NULL, NULL); - - if (libinput_device_config_tap_get_finger_count(device->device) > 0) { - enable_tap_default = - libinput_device_config_tap_get_default_enabled( - device->device); - weston_config_section_get_bool(s, "enable_tap", - &enable_tap, - enable_tap_default); - libinput_device_config_tap_set_enabled(device->device, - enable_tap); - } - - evdev_device_set_calibration(device); -} - struct evdev_device * evdev_device_create(struct libinput_device *libinput_device, struct weston_seat *seat) @@ -583,8 +556,6 @@ evdev_device_create(struct libinput_device *libinput_device, libinput_device_set_user_data(libinput_device, device); libinput_device_ref(libinput_device); - configure_device(device); - return device; } diff --git a/src/libinput-device.h b/src/libinput-device.h index a3848cac..5041a4aa 100644 --- a/src/libinput-device.h +++ b/src/libinput-device.h @@ -71,6 +71,8 @@ evdev_device_destroy(struct evdev_device *device); void evdev_notify_keyboard_focus(struct weston_seat *seat, struct wl_list *evdev_devices); +void +evdev_device_set_calibration(struct evdev_device *device); int dispatch_libinput(struct libinput *libinput); diff --git a/src/libinput-seat.c b/src/libinput-seat.c index 51688905..94e19f5e 100644 --- a/src/libinput-seat.c +++ b/src/libinput-seat.c @@ -79,6 +79,9 @@ device_added(struct udev_input *input, struct libinput_device *libinput_device) if (device == NULL) return; + if (input->configure_device != NULL) + input->configure_device(c, device->device); + evdev_device_set_calibration(device); udev_seat = (struct udev_seat *) seat; wl_list_insert(udev_seat->devices_list.prev, &device->link); @@ -279,7 +282,8 @@ libinput_log_func(struct libinput *libinput, int udev_input_init(struct udev_input *input, struct weston_compositor *c, - struct udev *udev, const char *seat_id) + struct udev *udev, const char *seat_id, + udev_configure_device_t configure_device) { enum libinput_log_priority priority = LIBINPUT_LOG_PRIORITY_INFO; const char *log_priority = NULL; @@ -287,6 +291,7 @@ udev_input_init(struct udev_input *input, struct weston_compositor *c, memset(input, 0, sizeof *input); input->compositor = c; + input->configure_device = configure_device; log_priority = getenv("WESTON_LIBINPUT_LOG_PRIORITY"); diff --git a/src/libinput-seat.h b/src/libinput-seat.h index 0813189a..65c9b64b 100644 --- a/src/libinput-seat.h +++ b/src/libinput-seat.h @@ -33,17 +33,23 @@ #include "compositor.h" +struct libinput_device; + struct udev_seat { struct weston_seat base; struct wl_list devices_list; struct wl_listener output_create_listener; }; +typedef void (*udev_configure_device_t)(struct weston_compositor *compositor, + struct libinput_device *device); + struct udev_input { struct libinput *libinput; struct wl_event_source *libinput_source; struct weston_compositor *compositor; int suspended; + udev_configure_device_t configure_device; }; int @@ -54,7 +60,8 @@ int udev_input_init(struct udev_input *input, struct weston_compositor *c, struct udev *udev, - const char *seat_id); + const char *seat_id, + udev_configure_device_t configure_device); void udev_input_destroy(struct udev_input *input); diff --git a/src/main.c b/src/main.c index 4e78e917..6a94c765 100644 --- a/src/main.c +++ b/src/main.c @@ -38,6 +38,7 @@ #include #include #include +#include #ifdef HAVE_LIBUNWIND #define UNW_LOCAL_ONLY @@ -873,6 +874,30 @@ drm_configure_output(struct weston_compositor *c, return mode; } +static void +configure_input_device(struct weston_compositor *compositor, + struct libinput_device *device) +{ + struct weston_config_section *s; + struct weston_config *config = wet_get_config(compositor); + int enable_tap; + int enable_tap_default; + + s = weston_config_get_section(config, + "libinput", NULL, NULL); + + if (libinput_device_config_tap_get_finger_count(device) > 0) { + enable_tap_default = + libinput_device_config_tap_get_default_enabled( + device); + weston_config_section_get_bool(s, "enable_tap", + &enable_tap, + enable_tap_default); + libinput_device_config_tap_set_enabled(device, + enable_tap); + } +} + static int load_drm_backend(struct weston_compositor *c, const char *backend, int *argc, char **argv, struct weston_config *wc) @@ -899,6 +924,7 @@ load_drm_backend(struct weston_compositor *c, const char *backend, config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION; config.base.struct_size = sizeof(struct weston_drm_backend_config); config.configure_output = drm_configure_output; + config.configure_device = configure_input_device; ret = load_backend_new(c, backend, &config.base); @@ -1021,6 +1047,7 @@ load_fbdev_backend(struct weston_compositor *c, char const * backend, config.base.struct_version = WESTON_FBDEV_BACKEND_CONFIG_VERSION; config.base.struct_size = sizeof(struct weston_fbdev_backend_config); + config.configure_device = configure_input_device; /* load the actual wayland backend and configure it */ ret = load_backend_new(c, backend, &config.base);