xwayland: make the plugin usable by libweston compositors

This patch follows a similar approach taken to detach the backends from
weston. But instead of passing a configuration struct when loading the
plugin, we use the plugin API registry to register an API, and to get it
in the compositor side.  This API allows to spawn the Xwayland process
in the compositor side, and to deal with signal handling.  A new
function is added in compositor.c to load and init the xwayland.so
plugin.

Also make sure to re-arm the SIGUSR1 when the X server quits.

Signed-off-by: Giulio Camuffo <giuliocamuffo@gmail.com>
[Pekka: moved xwayland/weston-xwayland.c -> compositor/xwayland.c]
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 113f5fc..0c405ac 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -5019,3 +5019,18 @@
 
 	return backend_init(compositor, config_base);
 }
+
+WL_EXPORT int
+weston_compositor_load_xwayland(struct weston_compositor *compositor)
+{
+	int (*module_init)(struct weston_compositor *ec,
+			   int *argc, char *argv[]);
+	int argc = 0;
+
+	module_init = weston_load_module("xwayland.so", "module_init");
+	if (!module_init)
+		return -1;
+	if (module_init(compositor, &argc, NULL) < 0)
+		return -1;
+	return 0;
+}
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 33b86c1..93fbc97 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -1720,6 +1720,9 @@
 weston_seat_set_keyboard_focus(struct weston_seat *seat,
 			       struct weston_surface *surface);
 
+int
+weston_compositor_load_xwayland(struct weston_compositor *compositor);
+
 #ifdef  __cplusplus
 }
 #endif