From: Quentin Glidic <[email protected]>

Signed-off-by: Quentin Glidic <[email protected]>
---
 Makefile.am                   |  2 +-
 {src => lib}/compositor-x11.c | 87 ++++++++++++++++---------------------------
 lib/libweston.c               |  2 +
 lib/libweston.h               |  1 +
 src/main.c                    |  2 +
 5 files changed, 39 insertions(+), 55 deletions(-)
 rename {src => lib}/compositor-x11.c (95%)

diff --git a/Makefile.am b/Makefile.am
index 68997d8..59e2130 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -260,7 +260,7 @@ x11_backend_la_CFLAGS =                             \
        $(X11_COMPOSITOR_CFLAGS)                \
        $(AM_CFLAGS)
 x11_backend_la_SOURCES =                       \
-       src/compositor-x11.c                    \
+       lib/compositor-x11.c                    \
        shared/helpers.h
 endif
 
diff --git a/src/compositor-x11.c b/lib/compositor-x11.c
similarity index 95%
rename from src/compositor-x11.c
rename to lib/compositor-x11.c
index cac96cb..f71b813 100644
--- a/src/compositor-x11.c
+++ b/lib/compositor-x11.c
@@ -49,7 +49,7 @@
 
 #include <xkbcommon/xkbcommon.h>
 
-#include "libweston.h"
+#include "libweston-internal.h"
 #include "compositor.h"
 #include "gl-renderer.h"
 #include "pixman-renderer.h"
@@ -61,13 +61,9 @@
 
 #define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int(10)
 
-static int option_width;
-static int option_height;
-static int option_scale;
-static int option_count;
-
 struct x11_backend {
        struct weston_backend    base;
+       struct libweston_context *context;
        struct weston_compositor *compositor;
 
        Display                 *dpy;
@@ -1564,19 +1560,22 @@ init_gl_renderer(struct x11_backend *b)
        return ret;
 }
 static struct x11_backend *
-x11_backend_create(struct weston_compositor *compositor,
-                  int fullscreen,
-                  int no_input,
-                  int use_pixman,
-                  int *argc, char *argv[],
-                  struct weston_config *config)
+x11_backend_create(struct libweston_context *context)
 {
+       struct weston_compositor *compositor = context->compositor;
        struct x11_backend *b;
+       char **output_names;
+       size_t output_names_size;
        struct x11_output *output;
-       struct weston_config_section *section;
+       bool fullscreen;
+       bool no_input;
+       int option_width;
+       int option_height;
+       int option_scale;
+       int option_count;
        int i, x = 0, output_count = 0;
        int width, height, scale, count;
-       const char *section_name;
+       char section[64];
        char *name, *t, *mode;
        uint32_t transform;
 
@@ -1586,6 +1585,7 @@ x11_backend_create(struct weston_compositor *compositor,
        if (b == NULL)
                return NULL;
 
+       b->context = context;
        b->compositor = compositor;
        if (weston_compositor_set_presentation_clock_software(compositor) < 0)
                goto err_free;
@@ -1600,6 +1600,13 @@ x11_backend_create(struct weston_compositor *compositor,
        if (xcb_connection_has_error(b->conn))
                goto err_xdisplay;
 
+       fullscreen = b->context->backend_config.bool_getter(NULL, "fullscreen", 
false, b->context->backend_config.user_data);
+       option_width = b->context->backend_config.int_getter(NULL, "width", 0, 
b->context->backend_config.user_data);
+       option_height = b->context->backend_config.int_getter(NULL, "height", 
0, b->context->backend_config.user_data);
+       option_scale = b->context->backend_config.int_getter(NULL, "scale", 0, 
b->context->backend_config.user_data);
+       option_count = b->context->backend_config.int_getter(NULL, 
"output-count", 0, b->context->backend_config.user_data);
+       no_input = b->context->backend_config.bool_getter(NULL, "no-input", 
false, b->context->backend_config.user_data);
+
        b->screen = x11_compositor_get_default_screen(b);
        wl_array_init(&b->keys);
 
@@ -1612,7 +1619,7 @@ x11_backend_create(struct weston_compositor *compositor,
                fullscreen = 0;
        }
 
-       b->use_pixman = use_pixman;
+       b->use_pixman = b->context->backend_config.bool_getter(NULL, 
"use-pixman", false, b->context->backend_config.user_data);
        if (b->use_pixman) {
                if (pixman_renderer_init(compositor) < 0) {
                        weston_log("Failed to initialize pixman renderer for 
X11 backend\n");
@@ -1622,7 +1629,7 @@ x11_backend_create(struct weston_compositor *compositor,
        else if (init_gl_renderer(b) < 0) {
                goto err_xdisplay;
        }
-       weston_log("Using %s renderer\n", use_pixman ? "pixman" : "gl");
+       weston_log("Using %s renderer\n", b->use_pixman ? "pixman" : "gl");
 
        b->base.destroy = x11_destroy;
        b->base.restore = x11_restore;
@@ -1637,19 +1644,12 @@ x11_backend_create(struct weston_compositor *compositor,
        scale = option_scale ? option_scale : 1;
        count = option_count ? option_count : 1;
 
-       section = NULL;
-       while (weston_config_next_section(config,
-                                         &section, &section_name)) {
-               if (strcmp(section_name, "output") != 0)
-                       continue;
-               weston_config_section_get_string(section, "name", &name, NULL);
-               if (name == NULL || name[0] != 'X') {
-                       free(name);
-                       continue;
-               }
+       output_names = b->context->backend_config.string_list_getter("x11", 
"outputs", NULL, &output_names_size, b->context->backend_config.user_data);
+       for (i = 0; i < (int)output_names_size; ++i) {
+               name = output_names[i];
+               snprintf(section, sizeof section, "output %s", output_names[i]);
 
-               weston_config_section_get_string(section,
-                                                "mode", &mode, "1024x600");
+               mode = b->context->backend_config.string_getter(section, 
"mode", "1024x600", b->context->backend_config.user_data);
                if (sscanf(mode, "%dx%d", &width, &height) != 2) {
                        weston_log("Invalid mode \"%s\" for output %s\n",
                                   mode, name);
@@ -1663,12 +1663,11 @@ x11_backend_create(struct weston_compositor *compositor,
                if (option_height)
                        height = option_height;
 
-               weston_config_section_get_int(section, "scale", &scale, 1);
+               scale = b->context->backend_config.int_getter(section, "scale", 
1, b->context->backend_config.user_data);
                if (option_scale)
                        scale = option_scale;
 
-               weston_config_section_get_string(section,
-                                                "transform", &t, "normal");
+               t = b->context->backend_config.string_getter(section, 
"transform", "normal", b->context->backend_config.user_data);
                if (weston_parse_transform(t, &transform) < 0)
                        weston_log("Invalid transform \"%s\" for output %s\n",
                                   t, name);
@@ -1690,6 +1689,7 @@ x11_backend_create(struct weston_compositor *compositor,
                if (option_count && output_count >= option_count)
                        break;
        }
+       free(output_names);
 
        for (i = output_count; i < count; i++) {
                output = x11_backend_create_output(b, x, 0, width, height,
@@ -1731,32 +1731,11 @@ err_free:
 }
 
 WL_EXPORT int
-backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
-            struct weston_config *config,
-            struct weston_backend_config *config_base)
+libweston_backend_init(struct libweston_context *context)
 {
        struct x11_backend *b;
-       int fullscreen = 0;
-       int no_input = 0;
-       int use_pixman = 0;
-
-       const struct weston_option x11_options[] = {
-               { WESTON_OPTION_INTEGER, "width", 0, &option_width },
-               { WESTON_OPTION_INTEGER, "height", 0, &option_height },
-               { WESTON_OPTION_INTEGER, "scale", 0, &option_scale },
-               { WESTON_OPTION_BOOLEAN, "fullscreen", 'f', &fullscreen },
-               { WESTON_OPTION_INTEGER, "output-count", 0, &option_count },
-               { WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input },
-               { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
-       };
-
-       parse_options(x11_options, ARRAY_LENGTH(x11_options), argc, argv);
 
-       b = x11_backend_create(compositor,
-                              fullscreen,
-                              no_input,
-                              use_pixman,
-                              argc, argv, config);
+       b = x11_backend_create(context);
        if (b == NULL)
                return -1;
        return 0;
diff --git a/lib/libweston.c b/lib/libweston.c
index dd77f6b..11ad982 100644
--- a/lib/libweston.c
+++ b/lib/libweston.c
@@ -92,6 +92,8 @@ libweston_load_backend(struct libweston_context *context, 
enum libweston_backend
        switch (preffered) {
        case LIBWESTON_BACKEND_DRM:
                return load_backend(context, "drm-backend.so");
+       case LIBWESTON_BACKEND_X11:
+               return load_backend(context, "x11-backend.so");
        case LIBWESTON_BACKEND_NONE:
        break;
        }
diff --git a/lib/libweston.h b/lib/libweston.h
index 3950316..c5eacab 100644
--- a/lib/libweston.h
+++ b/lib/libweston.h
@@ -15,6 +15,7 @@ void *libweston_load_module(const char *name, const char 
*entrypoint);
 enum libweston_backend {
        LIBWESTON_BACKEND_NONE = 0,
        LIBWESTON_BACKEND_DRM,
+       LIBWESTON_BACKEND_X11,
 };
 int libweston_load_backend(struct libweston_context *context, enum 
libweston_backend preffered);
 
diff --git a/src/main.c b/src/main.c
index c03835a..046c3d7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -662,6 +662,8 @@ load_backend(struct weston_compositor *compositor, const 
char *backend,
 
        if (strstr(backend, "drm"))
                libweston_backend = LIBWESTON_BACKEND_DRM;
+       else if (strstr(backend, "x11"))
+               libweston_backend = LIBWESTON_BACKEND_X11;
 
        if (libweston_load_backend(compositor->libweston, libweston_backend) == 
0)
                return 0;
-- 
2.6.4

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

Reply via email to