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 <giuliocamu...@gmail.com>
---
 Makefile.am            |  3 ++-
 src/compositor-drm.c   |  3 ++-
 src/compositor-drm.h   | 11 +++++++++++
 src/compositor-fbdev.c |  3 ++-
 src/compositor-fbdev.h | 11 +++++++++++
 src/compositor-rpi.c   |  2 +-
 src/libinput-device.c  | 31 +------------------------------
 src/libinput-device.h  |  2 ++
 src/libinput-seat.c    |  7 ++++++-
 src/libinput-seat.h    |  9 ++++++++-
 src/main.c             | 27 +++++++++++++++++++++++++++
 11 files changed, 73 insertions(+), 36 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index b32084f..2f81ec0 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 893877d..39d061b 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 3f150db..1266031 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 ee762e3..f66fe47 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 bd60bdc..450be5d 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/compositor-rpi.c b/src/compositor-rpi.c
index 75b808e..07e5d6a 100644
--- a/src/compositor-rpi.c
+++ b/src/compositor-rpi.c
@@ -514,7 +514,7 @@ rpi_backend_create(struct weston_compositor *compositor,
 
        if (udev_input_init(&backend->input,
                            compositor,
-                           backend->udev, "seat0") != 0) {
+                           backend->udev, "seat0", NULL) != 0) {
                weston_log("Failed to initialize udev input.\n");
                goto out_launcher;
        }
diff --git a/src/libinput-device.c b/src/libinput-device.c
index 3443666..62350f2 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 = weston_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 a3848ca..5041a4a 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 5168890..94e19f5 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 0813189..65c9b64 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 81802f6..e71fce9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -38,6 +38,7 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
+#include <libinput.h>
 
 #ifdef HAVE_LIBUNWIND
 #define UNW_LOCAL_ONLY
@@ -888,6 +889,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 = weston_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)
@@ -914,6 +939,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);
 
@@ -1036,6 +1062,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);
-- 
2.8.3

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to