compositor-headless: create input devices
authorEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
Fri, 7 Feb 2014 08:34:43 +0000 (09:34 +0100)
committerKristian Høgsberg <krh@bitplanet.net>
Tue, 18 Feb 2014 21:48:49 +0000 (13:48 -0800)
Fixes a segfault when using compositor-headless for the test suite
as many tests assume there are input devices and try to use them
through the wl_test interface.

Signed-off-by: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
src/compositor-headless.c

index 5a5c1e6..4ecb8d4 100644 (file)
@@ -131,6 +131,25 @@ headless_compositor_create_output(struct headless_compositor *c,
        return 0;
 }
 
+static int
+headless_input_create(struct headless_compositor *c)
+{
+       weston_seat_init(&c->fake_seat, &c->base, "default");
+
+       weston_seat_init_pointer(&c->fake_seat);
+
+       if (weston_seat_init_keyboard(&c->fake_seat, NULL) < 0)
+               return -1;
+
+       return 0;
+}
+
+static void
+headless_input_destroy(struct headless_compositor *c)
+{
+       weston_seat_release(&c->fake_seat);
+}
+
 static void
 headless_restore(struct weston_compositor *ec)
 {
@@ -141,7 +160,7 @@ headless_destroy(struct weston_compositor *ec)
 {
        struct headless_compositor *c = (struct headless_compositor *) ec;
 
-       weston_seat_release(&c->fake_seat);
+       headless_input_destroy(c);
        weston_compositor_shutdown(ec);
 
        free(ec);
@@ -162,19 +181,22 @@ headless_compositor_create(struct wl_display *display,
        if (weston_compositor_init(&c->base, display, argc, argv, config) < 0)
                goto err_free;
 
-       weston_seat_init(&c->fake_seat, &c->base, "default");
+       if (headless_input_create(c) < 0)
+               goto err_compositor;
 
        c->base.destroy = headless_destroy;
        c->base.restore = headless_restore;
 
        if (headless_compositor_create_output(c, width, height) < 0)
-               goto err_compositor;
+               goto err_input;
 
        if (noop_renderer_init(&c->base) < 0)
-               goto err_compositor;
+               goto err_input;
 
        return &c->base;
 
+err_input:
+       headless_input_destroy(c);
 err_compositor:
        weston_compositor_shutdown(&c->base);
 err_free: