This function gets called after backend_init, so compositors can add
their input devices slightly later on in the process.  This gives us a
chance to set the default XKB rulesets, in particular.

Signed-off-by: Daniel Stone <[email protected]>
---
 src/compositor-drm.c     |   18 ++++++++++++++++--
 src/compositor-wayland.c |   10 ++++------
 src/compositor-x11.c     |    9 ++++-----
 src/compositor.c         |   16 ++++++++--------
 src/compositor.h         |    1 +
 5 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 98e8b07..b0376d7 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -62,6 +62,8 @@ struct drm_compositor {
        uint32_t connector_allocator;
        struct tty *tty;
 
+       char *seat;
+
        struct gbm_surface *dummy_surface;
        EGLSurface dummy_egl_surface;
 
@@ -1638,6 +1640,8 @@ drm_destroy(struct weston_compositor *ec)
                fprintf(stderr, "failed to drop master: %m\n");
        tty_destroy(d->tty);
 
+       free(ec->seat);
+
        free(d);
 }
 
@@ -1734,6 +1738,16 @@ switch_vt_binding(struct wl_seat *seat, uint32_t time, 
uint32_t key, void *data)
        tty_activate_vt(ec->tty, key - KEY_F1 + 1);
 }
 
+static int
+drm_input_init(struct weston_compositor *compositor)
+{
+       struct drm_compositor *ec = (struct drm_compositor *) compositor;
+
+       evdev_input_create(&ec->base, ec->udev, ec->seat);
+
+       return 0;
+}
+
 static const char default_seat[] = "seat0";
 
 static struct weston_compositor *
@@ -1786,6 +1800,7 @@ drm_compositor_create(struct wl_display *display,
                }
                udev_device_unref(device);
        }
+       ec->seat = strdup(seat);
 
        if (drm_device == NULL) {
                fprintf(stderr, "no drm device found\n");
@@ -1797,6 +1812,7 @@ drm_compositor_create(struct wl_display *display,
                return NULL;
        }
 
+       ec->base.input_init = drm_input_init;
        ec->base.destroy = drm_destroy;
 
        ec->base.focus = 1;
@@ -1824,8 +1840,6 @@ drm_compositor_create(struct wl_display *display,
        udev_enumerate_unref(e);
        path = NULL;
 
-       evdev_input_create(&ec->base, ec->udev, seat);
-
        loop = wl_display_get_event_loop(ec->base.wl_display);
        ec->drm_source =
                wl_event_loop_add_fd(loop, ec->drm.fd,
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index 60fb9d9..4b4f1eb 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -245,7 +245,7 @@ create_border(struct wayland_compositor *c)
 }
 
 static int
-wayland_input_create(struct wayland_compositor *c)
+wayland_input_init(struct weston_compositor *ec)
 {
        struct weston_seat *seat;
 
@@ -254,9 +254,9 @@ wayland_input_create(struct wayland_compositor *c)
                return -1;
 
        memset(seat, 0, sizeof *seat);
-       weston_seat_init(seat, &c->base);
+       weston_seat_init(seat, ec);
 
-       c->base.seat = seat;
+       ec->seat = seat;
 
        return 0;
 }
@@ -766,6 +766,7 @@ wayland_compositor_create(struct wl_display *display,
        if (wayland_compositor_init_egl(c) < 0)
                return NULL;
 
+       c->base.input_init = wayland_input_init;
        c->base.destroy = wayland_destroy;
 
        /* Can't init base class until we have a current egl context */
@@ -776,9 +777,6 @@ wayland_compositor_create(struct wl_display *display,
        if (wayland_compositor_create_output(c, width, height) < 0)
                return NULL;
 
-       if (wayland_input_create(c) < 0)
-               return NULL;
-
        loop = wl_display_get_event_loop(c->base.wl_display);
 
        fd = wl_display_get_fd(c->parent.display, update_event_mask, c);
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index b314a1d..b137ac8 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -129,8 +129,9 @@ x11_compositor_get_keymap(struct x11_compositor *c)
 }
 
 static int
-x11_input_create(struct x11_compositor *c)
+x11_input_init(struct weston_compositor *ec)
 {
+       struct x11_compositor *c = (struct x11_compositor *) ec;
        struct x11_input *input;
        struct xkb_keymap *keymap;
 
@@ -139,7 +140,7 @@ x11_input_create(struct x11_compositor *c)
                return -1;
 
        memset(input, 0, sizeof *input);
-       weston_seat_init(&input->base, &c->base);
+       weston_seat_init(&input->base, ec);
        weston_seat_init_pointer(&input->base);
 
        keymap = x11_compositor_get_keymap(c);
@@ -875,6 +876,7 @@ x11_compositor_create(struct wl_display *display,
        if (x11_compositor_init_egl(c) < 0)
                return NULL;
 
+       c->base.input_init = x11_input_init;
        c->base.destroy = x11_destroy;
 
        /* Can't init base class until we have a current egl context */
@@ -888,9 +890,6 @@ x11_compositor_create(struct wl_display *display,
                x += width;
        }
 
-       if (x11_input_create(c) < 0)
-               return NULL;
-
        c->xcb_source =
                wl_event_loop_add_fd(c->base.input_loop,
                                     xcb_get_file_descriptor(c->conn),
diff --git a/src/compositor.c b/src/compositor.c
index e65ea5a..70db411 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -2229,12 +2229,10 @@ device_handle_new_drag_icon(struct wl_listener 
*listener, void *data)
 static void weston_compositor_xkb_init(struct weston_compositor *ec,
                                       struct xkb_rule_names *names)
 {
+       ec->xkb_context = xkb_context_new(0);
        if (ec->xkb_context == NULL) {
-               ec->xkb_context = xkb_context_new(0);
-               if (ec->xkb_context == NULL) {
-                       fprintf(stderr, "failed to create XKB context\n");
-                       exit(1);
-               }
+               fprintf(stderr, "failed to create XKB context\n");
+               exit(1);
        }
 
        if (names)
@@ -2289,9 +2287,6 @@ weston_compositor_build_global_keymap(struct 
weston_compositor *ec)
        if (ec->xkb_info.keymap != NULL)
                return;
 
-       if (ec->xkb_names.rules == NULL)
-               weston_compositor_xkb_init(ec, NULL);
-
        ec->xkb_info.keymap = xkb_map_new_from_names(ec->xkb_context,
                                                     &ec->xkb_names,
                                                     0);
@@ -3089,6 +3084,11 @@ int main(int argc, char *argv[])
 
        weston_compositor_xkb_init(ec, &xkb_names);
 
+       if (ec->input_init(ec) != 0) {
+               fprintf(stderr, "failed to create input devices\n");
+               exit(EXIT_FAILURE);
+       }
+
        ec->option_idle_time = idle_time;
        ec->idle_time = idle_time;
 
diff --git a/src/compositor.h b/src/compositor.h
index 2df753f..8809f9d 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -313,6 +313,7 @@ struct weston_compositor {
        PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
        int has_bind_display;
 
+       int (*input_init)(struct weston_compositor *ec);
        void (*destroy)(struct weston_compositor *ec);
        int (*authenticate)(struct weston_compositor *c, uint32_t id);
 
-- 
1.7.10

_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to