summaryrefslogtreecommitdiff
path: root/src/compositor-x11.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/compositor-x11.c')
-rw-r--r--src/compositor-x11.c159
1 files changed, 58 insertions, 101 deletions
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index f1cb71bd..0c49992e 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -50,21 +50,17 @@
#include <xkbcommon/xkbcommon.h>
#include "compositor.h"
-#include "gl-renderer.h"
-#include "pixman-renderer.h"
+#include "compositor-x11.h"
#include "shared/config-parser.h"
#include "shared/helpers.h"
#include "shared/image-loader.h"
+#include "gl-renderer.h"
+#include "pixman-renderer.h"
#include "presentation-time-server-protocol.h"
#include "linux-dmabuf.h"
#define DEFAULT_AXIS_STEP_DISTANCE 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 weston_compositor *compositor;
@@ -130,6 +126,12 @@ struct window_delete_data {
struct gl_renderer_interface *gl_renderer;
+static void
+weston_x11_backend_config_init_default(struct weston_x11_backend_config * ths) {
+ /* TODO: Why not memset?? Or zalloc originally instead of this function. */
+ bzero(ths, sizeof(*ths));
+}
+
static xcb_screen_t *
x11_compositor_get_default_screen(struct x11_backend *b)
{
@@ -1566,24 +1568,20 @@ 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)
+ struct weston_x11_backend_config *foreign_config)
{
struct x11_backend *b;
struct x11_output *output;
- struct weston_config_section *section;
- int i, x = 0, output_count = 0;
- int width, height, scale, count;
- const char *section_name;
- char *name, *t, *mode;
- uint32_t transform;
+ struct weston_x11_backend_config config = {{ 0 }};
+ int x = 0;
+ unsigned i;
weston_log("initializing x11 backend\n");
+ weston_x11_backend_config_init_default(&config);
+ memcpy(&config, foreign_config, foreign_config->base.struct_size);
b = zalloc(sizeof *b);
if (b == NULL)
@@ -1609,13 +1607,13 @@ x11_backend_create(struct weston_compositor *compositor,
x11_backend_get_resources(b);
x11_backend_get_wm_info(b);
- if (!b->has_net_wm_state_fullscreen && fullscreen) {
+ if (!b->has_net_wm_state_fullscreen && config.fullscreen) {
weston_log("Can not fullscreen without window manager support"
"(need _NET_WM_STATE_FULLSCREEN)\n");
- fullscreen = 0;
+ config.fullscreen = 0;
}
- b->use_pixman = use_pixman;
+ b->use_pixman = config.use_pixman;
if (b->use_pixman) {
if (pixman_renderer_init(compositor) < 0) {
weston_log("Failed to initialize pixman renderer for X11 backend\n");
@@ -1625,83 +1623,51 @@ 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", config.use_pixman ? "pixman" : "gl");
b->base.destroy = x11_destroy;
b->base.restore = x11_restore;
- if (x11_input_create(b, no_input) < 0) {
+ if (x11_input_create(b, config.no_input) < 0) {
weston_log("Failed to create X11 input\n");
goto err_renderer;
}
- width = option_width ? option_width : 1024;
- height = option_height ? option_height : 640;
- scale = option_scale ? option_scale : 1;
- count = option_count ? option_count : 1;
+ for (i = 0; i < config.num_outputs; ++i) {
+ struct weston_x11_backend_output_config * output_iterator =
+ &config.outputs[i];
- 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);
+ if (output_iterator->name == NULL) {
continue;
}
- weston_config_section_get_string(section,
- "mode", &mode, "1024x600");
- if (sscanf(mode, "%dx%d", &width, &height) != 2) {
- weston_log("Invalid mode \"%s\" for output %s\n",
- mode, name);
- width = 1024;
- height = 600;
+ if (output_iterator->width < 1) {
+ weston_log("Invalid width \"%d\" for output %s\n",
+ output_iterator->width, output_iterator->name);
+ output_iterator->width = 1024;
}
- free(mode);
-
- if (option_width)
- width = option_width;
- if (option_height)
- height = option_height;
-
- weston_config_section_get_int(section, "scale", &scale, 1);
- if (option_scale)
- scale = option_scale;
-
- weston_config_section_get_string(section,
- "transform", &t, "normal");
- if (weston_parse_transform(t, &transform) < 0)
- weston_log("Invalid transform \"%s\" for output %s\n",
- t, name);
- free(t);
-
- output = x11_backend_create_output(b, x, 0,
- width, height,
- fullscreen, no_input,
- name, transform, scale);
- free(name);
- if (output == NULL) {
- weston_log("Failed to create configured x11 output\n");
- goto err_x11_input;
- }
-
- x = pixman_region32_extents(&output->base.region)->x2;
- output_count++;
- if (option_count && output_count >= option_count)
- break;
- }
+ if (output_iterator->height < 1) {
+ weston_log("Invalid height \"%d\" for output %s\n",
+ output_iterator->height, output_iterator->name);
+ output_iterator->height = 600;
+ }
- for (i = output_count; i < count; i++) {
- output = x11_backend_create_output(b, x, 0, width, height,
- fullscreen, no_input, NULL,
- WL_OUTPUT_TRANSFORM_NORMAL, scale);
+ output = x11_backend_create_output(b,
+ x,
+ 0,
+ output_iterator->width,
+ output_iterator->height,
+ config.fullscreen,
+ config.no_input,
+ output_iterator->name,
+ output_iterator->transform,
+ output_iterator->scale);
if (output == NULL) {
- weston_log("Failed to create x11 output #%d\n", i);
+ weston_log("Failed to create configured x11 output\n");
goto err_x11_input;
}
+
x = pixman_region32_extents(&output->base.region)->x2;
}
@@ -1734,33 +1700,24 @@ err_free:
}
WL_EXPORT int
-backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
- struct weston_config *config,
+backend_init(struct weston_compositor *compositor,
+ int *argc, char *argv[],
+ struct weston_config *wc,
struct weston_backend_config *config_base)
{
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 },
- };
+ struct weston_x11_backend_config *config;
- parse_options(x11_options, ARRAY_LENGTH(x11_options), argc, argv);
+ if (config_base == NULL ||
+ config_base->struct_version != 1 ||
+ config_base->struct_size > sizeof(struct weston_x11_backend_config))
+ return -1;
+
+ config = (struct weston_x11_backend_config *)config_base;
- b = x11_backend_create(compositor,
- fullscreen,
- no_input,
- use_pixman,
- argc, argv, config);
+ b = x11_backend_create(compositor, config);
if (b == NULL)
return -1;
+
return 0;
}