mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 21:05:58 +01:00
backend/wayland: take existing wl_display in wlr_wl_backend_create()
This allows compositors to use an existing wl_display, to integrate wlroots with an existing toolkit.
This commit is contained in:
parent
664ec59095
commit
dd24991c9e
3 changed files with 20 additions and 11 deletions
|
@ -529,7 +529,9 @@ static void backend_destroy(struct wlr_backend *backend) {
|
||||||
wl_compositor_destroy(wl->compositor);
|
wl_compositor_destroy(wl->compositor);
|
||||||
wl_registry_destroy(wl->registry);
|
wl_registry_destroy(wl->registry);
|
||||||
wl_display_flush(wl->remote_display);
|
wl_display_flush(wl->remote_display);
|
||||||
|
if (wl->own_remote_display) {
|
||||||
wl_display_disconnect(wl->remote_display);
|
wl_display_disconnect(wl->remote_display);
|
||||||
|
}
|
||||||
free(wl);
|
free(wl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,7 +570,7 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
|
struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
|
||||||
const char *remote) {
|
struct wl_display *remote_display) {
|
||||||
wlr_log(WLR_INFO, "Creating wayland backend");
|
wlr_log(WLR_INFO, "Creating wayland backend");
|
||||||
|
|
||||||
struct wlr_wl_backend *wl = calloc(1, sizeof(*wl));
|
struct wlr_wl_backend *wl = calloc(1, sizeof(*wl));
|
||||||
|
@ -585,11 +587,16 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
|
||||||
wl_list_init(&wl->buffers);
|
wl_list_init(&wl->buffers);
|
||||||
wl->presentation_clock = CLOCK_MONOTONIC;
|
wl->presentation_clock = CLOCK_MONOTONIC;
|
||||||
|
|
||||||
wl->remote_display = wl_display_connect(remote);
|
if (remote_display != NULL) {
|
||||||
|
wl->remote_display = remote_display;
|
||||||
|
} else {
|
||||||
|
wl->remote_display = wl_display_connect(NULL);
|
||||||
if (!wl->remote_display) {
|
if (!wl->remote_display) {
|
||||||
wlr_log_errno(WLR_ERROR, "Could not connect to remote display");
|
wlr_log_errno(WLR_ERROR, "Could not connect to remote display");
|
||||||
goto error_wl;
|
goto error_wl;
|
||||||
}
|
}
|
||||||
|
wl->own_remote_display = true;
|
||||||
|
}
|
||||||
|
|
||||||
wl->registry = wl_display_get_registry(wl->remote_display);
|
wl->registry = wl_display_get_registry(wl->remote_display);
|
||||||
if (!wl->registry) {
|
if (!wl->registry) {
|
||||||
|
@ -685,7 +692,9 @@ error_registry:
|
||||||
}
|
}
|
||||||
wl_registry_destroy(wl->registry);
|
wl_registry_destroy(wl->registry);
|
||||||
error_display:
|
error_display:
|
||||||
|
if (wl->own_remote_display) {
|
||||||
wl_display_disconnect(wl->remote_display);
|
wl_display_disconnect(wl->remote_display);
|
||||||
|
}
|
||||||
error_wl:
|
error_wl:
|
||||||
wlr_backend_finish(&wl->backend);
|
wlr_backend_finish(&wl->backend);
|
||||||
free(wl);
|
free(wl);
|
||||||
|
|
|
@ -30,6 +30,7 @@ struct wlr_wl_backend {
|
||||||
|
|
||||||
/* remote state */
|
/* remote state */
|
||||||
struct wl_display *remote_display;
|
struct wl_display *remote_display;
|
||||||
|
bool own_remote_display;
|
||||||
struct wl_event_source *remote_display_src;
|
struct wl_event_source *remote_display_src;
|
||||||
struct wl_registry *registry;
|
struct wl_registry *registry;
|
||||||
struct wl_compositor *compositor;
|
struct wl_compositor *compositor;
|
||||||
|
|
|
@ -12,12 +12,11 @@ struct wlr_input_device;
|
||||||
* Creates a new Wayland backend. This backend will be created with no outputs;
|
* Creates a new Wayland backend. This backend will be created with no outputs;
|
||||||
* you must use wlr_wl_output_create() to add them.
|
* you must use wlr_wl_output_create() to add them.
|
||||||
*
|
*
|
||||||
* The `remote` argument is the name of the host compositor wayland socket. Set
|
* The remote_display argument is an existing libwayland-client struct wl_display
|
||||||
* to NULL for the default behaviour (WAYLAND_DISPLAY env variable or wayland-0
|
* to use. Leave it NULL to create a new connection to the compositor.
|
||||||
* default).
|
|
||||||
*/
|
*/
|
||||||
struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
|
struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
|
||||||
const char *remote);
|
struct wl_display *remote_display);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the remote struct wl_display used by the Wayland backend.
|
* Returns the remote struct wl_display used by the Wayland backend.
|
||||||
|
|
Loading…
Reference in a new issue