compositor-wayland: Delay seat creation

We'll get a rash of seats added when we run our first wl_display_iterate
across the parent display, but won't actually be ready to create them.
Create a new global listener on our parent display for wl_seats only,
and run that from wayland_input_create.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index 9e1f8a3..c25f093 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -246,23 +246,6 @@
 }
 
 static int
-wayland_input_create(struct wayland_compositor *c)
-{
-	struct weston_seat *seat;
-
-	seat = malloc(sizeof *seat);
-	if (seat == NULL)
-		return -1;
-
-	memset(seat, 0, sizeof *seat);
-	weston_seat_init(seat, &c->base);
-
-	c->base.seat = seat;
-
-	return 0;
-}
-
-static int
 wayland_compositor_init_egl(struct wayland_compositor *c)
 {
 	EGLint major, minor;
@@ -722,6 +705,22 @@
 	wl_seat_set_user_data(input->seat, input);
 }
 
+/* We can't start adding input devices until weston_compositor_init, but
+ * also can't call weston_compositor_init until we've handled some of the
+ * base display code first.  So, we have a separate global handler for
+ * seats. */
+static void
+display_handle_global_input(struct wl_display *display, uint32_t id,
+			    const char *interface, uint32_t version,
+			    void *data)
+{
+	struct wayland_compositor *c = data;
+
+	if (strcmp(interface, "wl_seat") == 0)
+		display_add_seat(c, id);
+}
+
+
 static void
 display_handle_global(struct wl_display *display, uint32_t id,
 		      const char *interface, uint32_t version, void *data)
@@ -735,8 +734,6 @@
 		c->parent.output =
 			wl_display_bind(display, id, &wl_output_interface);
 		wl_output_add_listener(c->parent.output, &output_listener, c);
-	} else if (strcmp(interface, "wl_seat") == 0) {
-		display_add_seat(c, id);
 	} else if (strcmp(interface, "wl_shell") == 0) {
 		c->parent.shell =
 			wl_display_bind(display, id, &wl_shell_interface);
@@ -768,6 +765,27 @@
 	return 1;
 }
 
+static int
+wayland_input_create(struct wayland_compositor *c)
+{
+	struct weston_seat *seat;
+
+	seat = malloc(sizeof *seat);
+	if (seat == NULL)
+		return -1;
+
+	memset(seat, 0, sizeof *seat);
+	weston_seat_init(seat, &c->base);
+
+	c->base.seat = seat;
+
+	wl_display_add_global_listener(c->parent.display,
+				       display_handle_global_input,
+				       c);
+
+	return 0;
+}
+
 static void
 wayland_destroy(struct weston_compositor *ec)
 {