2017-04-25 15:32:52 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <wayland-server.h>
|
2017-04-25 19:06:58 +00:00
|
|
|
#include <assert.h>
|
2017-04-25 15:32:52 +00:00
|
|
|
#include "backend/wayland.h"
|
2017-04-25 19:06:58 +00:00
|
|
|
#include "common/log.h"
|
2017-04-25 15:32:52 +00:00
|
|
|
|
2017-04-25 19:06:58 +00:00
|
|
|
void wlr_wl_backend_free(struct wlr_wl_backend *backend) {
|
|
|
|
if (!backend) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-26 01:26:29 +00:00
|
|
|
// TODO: Free surfaces
|
|
|
|
for (size_t i = 0; backend->outputs && i < backend->outputs->length; ++i) {
|
|
|
|
struct wlr_wl_output *output = backend->outputs->items[i];
|
|
|
|
wlr_wl_output_free(output);
|
|
|
|
}
|
|
|
|
list_free(backend->outputs);
|
|
|
|
if (backend->seat) wlr_wl_seat_free(backend->seat);
|
|
|
|
if (backend->shm) wl_shm_destroy(backend->shm);
|
|
|
|
if (backend->shell) wl_shell_destroy(backend->shell);
|
|
|
|
if (backend->compositor) wl_compositor_destroy(backend->compositor);
|
|
|
|
if (backend->registry) wl_registry_destroy(backend->registry);
|
|
|
|
if (backend->remote_display) wl_display_disconnect(backend->remote_display);
|
2017-04-25 19:06:58 +00:00
|
|
|
free(backend);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializes the wayland backend. Opens a connection to a remote wayland
|
|
|
|
* compositor and creates surfaces for each output, then registers globals on
|
|
|
|
* the specified display.
|
|
|
|
*/
|
|
|
|
struct wlr_wl_backend *wlr_wl_backend_init(
|
|
|
|
struct wl_display *display, size_t outputs) {
|
|
|
|
assert(display);
|
|
|
|
struct wlr_wl_backend *backend;
|
|
|
|
if (!(backend = calloc(sizeof(struct wlr_wl_backend), 1))) {
|
|
|
|
wlr_log(L_ERROR, "Could not allocate backend");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (!(backend->outputs = list_create())) {
|
|
|
|
wlr_log(L_ERROR, "Could not allocate output list");
|
|
|
|
goto error;
|
|
|
|
}
|
2017-04-25 15:32:52 +00:00
|
|
|
backend->local_display = display;
|
2017-04-25 19:06:58 +00:00
|
|
|
backend->remote_display = wl_display_connect(getenv("_WAYLAND_DISPLAY"));
|
|
|
|
if (!backend->remote_display) {
|
|
|
|
wlr_log(L_ERROR, "Could not connect to remote display");
|
|
|
|
goto error;
|
|
|
|
}
|
2017-04-25 23:19:21 +00:00
|
|
|
if (!(backend->registry = wl_display_get_registry(backend->remote_display))) {
|
2017-04-25 19:06:58 +00:00
|
|
|
wlr_log(L_ERROR, "Could not obtain reference to remote registry");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
wlr_wlb_registry_poll(backend);
|
2017-04-25 15:32:52 +00:00
|
|
|
return backend;
|
2017-04-25 19:06:58 +00:00
|
|
|
error:
|
|
|
|
wlr_wl_backend_free(backend);
|
|
|
|
return NULL;
|
2017-04-25 15:32:52 +00:00
|
|
|
}
|