diff options
author | emersion <contact@emersion.fr> | 2018-03-30 22:09:06 -0400 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-03-30 23:51:19 -0400 |
commit | 0a7a8cbd1c64e50978e846d8cf1bf8b1f6868655 (patch) | |
tree | 755a1e6c49c5cf1c1d91660dc35cd4cd7b58c28c /backend | |
parent | d4f7ced6e260961f701f73f672fffa87ee333c3d (diff) |
backend/x11: add WLR_X11_OUTPUTS support
Diffstat (limited to 'backend')
-rw-r--r-- | backend/backend.c | 67 | ||||
-rw-r--r-- | backend/x11/backend.c | 3 | ||||
-rw-r--r-- | backend/x11/output.c | 20 |
3 files changed, 64 insertions, 26 deletions
diff --git a/backend/backend.c b/backend/backend.c index 52344dac..ff5603bd 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -61,26 +61,48 @@ struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend) { return NULL; } +static int parse_outputs_env(const char *name) { + const char *outputs_str = getenv(name); + if (outputs_str == NULL) { + return 1; + } + + char *end; + int outputs = (int)strtol(outputs_str, &end, 10); + if (*end || outputs < 0) { + wlr_log(L_ERROR, "%s specified with invalid integer, ignoring", name); + return 1; + } + + return outputs; +} + static struct wlr_backend *attempt_wl_backend(struct wl_display *display) { struct wlr_backend *backend = wlr_wl_backend_create(display, NULL); - if (backend) { - int outputs = 1; - const char *_outputs = getenv("WLR_WL_OUTPUTS"); - if (_outputs) { - char *end; - outputs = (int)strtol(_outputs, &end, 10); - if (*end) { - wlr_log(L_ERROR, "WLR_WL_OUTPUTS specified with invalid integer, ignoring"); - outputs = 1; - } else if (outputs < 0) { - wlr_log(L_ERROR, "WLR_WL_OUTPUTS specified with negative outputs, ignoring"); - outputs = 1; - } - } - while (outputs--) { - wlr_wl_output_create(backend); - } + if (backend == NULL) { + return NULL; + } + + int outputs = parse_outputs_env("WLR_WL_OUTPUTS"); + for (int i = 0; i < outputs; ++i) { + wlr_wl_output_create(backend); } + + return backend; +} + +static struct wlr_backend *attempt_x11_backend(struct wl_display *display, + const char *x11_display) { + struct wlr_backend *backend = wlr_x11_backend_create(display, x11_display); + if (backend == NULL) { + return NULL; + } + + int outputs = parse_outputs_env("WLR_X11_OUTPUTS"); + for (int i = 0; i < outputs; ++i) { + wlr_x11_output_create(backend); + } + return backend; } @@ -91,7 +113,8 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { return NULL; } - if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY")) { + if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY") || + getenv("WAYLAND_SOCKET")) { struct wlr_backend *wl_backend = attempt_wl_backend(display); if (wl_backend) { wlr_multi_backend_add(backend, wl_backend); @@ -103,9 +126,11 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { const char *x11_display = getenv("DISPLAY"); if (x11_display) { struct wlr_backend *x11_backend = - wlr_x11_backend_create(display, x11_display); - wlr_multi_backend_add(backend, x11_backend); - return backend; + attempt_x11_backend(display, x11_display); + if (x11_backend) { + wlr_multi_backend_add(backend, x11_backend); + return backend; + } } #endif diff --git a/backend/x11/backend.c b/backend/x11/backend.c index c72cdcac..80998f3f 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -96,6 +96,7 @@ static int x11_event(int fd, uint32_t mask, void *data) { static bool wlr_x11_backend_start(struct wlr_backend *backend) { struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend; + x11->started = true; struct { const char *name; @@ -167,7 +168,7 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { wlr_signal_emit_safe(&x11->backend.events.new_input, &x11->pointer_dev); for (size_t i = 0; i < x11->requested_outputs; ++i) { - x11_output_create(x11); + wlr_x11_output_create(&x11->backend); } return true; diff --git a/backend/x11/output.c b/backend/x11/output.c index f039baad..9e7424d8 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -1,3 +1,4 @@ +#include <assert.h> #include <stdlib.h> #include <wlr/interfaces/wlr_output.h> #include <wlr/util/log.h> @@ -77,18 +78,29 @@ static const struct wlr_output_impl output_impl = { .swap_buffers = output_swap_buffers, }; -struct wlr_x11_output *x11_output_create(struct wlr_x11_backend *x11) { +struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) { + assert(wlr_backend_is_x11(backend)); + struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend; + + if (!x11->started) { + ++x11->requested_outputs; + return NULL; + } + struct wlr_x11_output *output = calloc(1, sizeof(struct wlr_x11_output)); if (output == NULL) { return NULL; } output->x11 = x11; - output->frame_delay = 16; // 60 Hz struct wlr_output *wlr_output = &output->wlr_output; wlr_output_init(wlr_output, &x11->backend, &output_impl, x11->wl_display); - snprintf(wlr_output->name, sizeof(wlr_output->name), "X11-1"); + wlr_output->refresh = 60 * 1000000; + output->frame_delay = 16; // 60 Hz + + snprintf(wlr_output->name, sizeof(wlr_output->name), "X11-%d", + wl_list_length(&x11->outputs) + 1); parse_xcb_setup(wlr_output, x11->xcb_conn); uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; @@ -135,7 +147,7 @@ struct wlr_x11_output *x11_output_create(struct wlr_x11_backend *x11) { wl_list_insert(&x11->outputs, &output->link); wlr_signal_emit_safe(&x11->backend.events.new_output, wlr_output); - return output; + return wlr_output; } void x11_output_handle_configure_notify(struct wlr_x11_output *output, |