libinput: don't use weston_config when configuring input devices
authorGiulio Camuffo <giuliocamuffo@gmail.com>
Thu, 2 Jun 2016 18:48:12 +0000 (21:48 +0300)
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>
Fri, 3 Jun 2016 10:17:18 +0000 (13:17 +0300)
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 <giuliocamuffo@gmail.com>
Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Makefile.am
src/compositor-drm.c
src/compositor-drm.h
src/compositor-fbdev.c
src/compositor-fbdev.h
src/libinput-device.c
src/libinput-device.h
src/libinput-seat.c
src/libinput-seat.h
src/main.c

index 1b323006d9fdd55ab656c4978b5a59a0668b50c2..fd10c131cf7f95030db84f30f825b4f716c547e2 100644 (file)
@@ -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                               \
index 893877d946ff4258041fd2fd919e4da9373b5e5f..39d061b5530464366b7f302b2b250b523f1ad6c5 100644 (file)
@@ -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;
        }
index 3f150dba28b3370743af5f56016e40d162e28445..1266031f09f15b4df99244d8a663335d36b6a76a 100644 (file)
@@ -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;
 };
 
index ee762e312c59f3de8c4614d68b9639d849a8db6e..f66fe479727e6397f52944ad82402e52949ad422 100644 (file)
@@ -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;
index bd60bdc47e1e499c6bfa6f93bee327294a368f35..450be5d170fefca207ebc31f04ac6dd6a1eedec4 100644 (file)
@@ -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
index 2126084c8b8894c087bec33f1547c4f0141145f3..62350f2e41112f88e34df4d72600693b5672b9e8 100644 (file)
@@ -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;
 }
 
index a3848caceeb6f048f2a43b32e2d4c605e76ab83a..5041a4aa65b435e3b0225672107de8921fb12afe 100644 (file)
@@ -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);
index 516889054fc3a1e38b6561a66562ccc8aaadc408..94e19f5ee7974d6549defd45bfa1d38e717977e0 100644 (file)
@@ -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");
 
index 0813189a56356a62fa562045b6d1e562325ec29c..65c9b64bac1d6a5b44e64410f14c723ba9c8ec50 100644 (file)
 
 #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);
 
index 4e78e917e4719d30945c6f464dd348f00b05f122..6a94c765f18830fd6a2b3706526262485e1c0b6b 100644 (file)
@@ -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
@@ -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);