mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 04:45:58 +01:00
backend/x11: add WLR_X11_OUTPUTS support
This commit is contained in:
parent
d4f7ced6e2
commit
0a7a8cbd1c
5 changed files with 69 additions and 29 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/backend/x11.h>
|
||||
#include <wlr/interfaces/wlr_input_device.h>
|
||||
#include <wlr/interfaces/wlr_output.h>
|
||||
#include <wlr/render/egl.h>
|
||||
#include <X11/Xlib-xcb.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <wlr/interfaces/wlr_input_device.h>
|
||||
#include <wlr/interfaces/wlr_output.h>
|
||||
|
||||
#define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f
|
||||
|
||||
|
@ -28,6 +29,7 @@ struct wlr_x11_output {
|
|||
struct wlr_x11_backend {
|
||||
struct wlr_backend backend;
|
||||
struct wl_display *wl_display;
|
||||
bool started;
|
||||
|
||||
Display *xlib_conn;
|
||||
xcb_connection_t *xcb_conn;
|
||||
|
@ -73,7 +75,6 @@ const struct wlr_input_device_impl input_device_impl;
|
|||
bool x11_handle_input_event(struct wlr_x11_backend *x11,
|
||||
xcb_generic_event_t *event);
|
||||
|
||||
struct wlr_x11_output *x11_output_create(struct wlr_x11_backend *x11);
|
||||
void x11_output_handle_configure_notify(struct wlr_x11_output *output,
|
||||
xcb_configure_notify_event_t *event);
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
|
||||
const char *x11_display);
|
||||
struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend);
|
||||
|
||||
bool wlr_backend_is_x11(struct wlr_backend *backend);
|
||||
bool wlr_input_device_is_x11(struct wlr_input_device *device);
|
||||
|
|
Loading…
Reference in a new issue