2020-12-15 20:52:53 +01:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2017-04-25 21:06:58 +02:00
|
|
|
#include <assert.h>
|
2020-12-15 20:52:53 +01:00
|
|
|
#include <fcntl.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2020-11-26 11:40:23 +01:00
|
|
|
#include <unistd.h>
|
2018-11-11 06:14:48 +01:00
|
|
|
|
2019-09-24 14:33:15 +02:00
|
|
|
#include <drm_fourcc.h>
|
2019-07-27 10:53:54 +02:00
|
|
|
#include <wayland-server-core.h>
|
2021-01-04 10:51:34 +01:00
|
|
|
#include <xf86drm.h>
|
2018-11-11 06:14:48 +01:00
|
|
|
|
2017-06-19 17:46:50 +02:00
|
|
|
#include <wlr/backend/interface.h>
|
2017-06-21 16:27:45 +02:00
|
|
|
#include <wlr/interfaces/wlr_input_device.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <wlr/interfaces/wlr_output.h>
|
2017-06-21 18:10:07 +02:00
|
|
|
#include <wlr/util/log.h>
|
2018-11-11 06:14:48 +01:00
|
|
|
|
2017-04-25 17:32:52 +02:00
|
|
|
#include "backend/wayland.h"
|
2020-11-26 11:40:23 +01:00
|
|
|
#include "render/drm_format_set.h"
|
2021-02-09 23:29:44 +01:00
|
|
|
#include "render/pixel_format.h"
|
2018-02-12 21:29:23 +01:00
|
|
|
#include "util/signal.h"
|
2020-11-26 11:40:23 +01:00
|
|
|
|
2021-01-04 10:51:34 +01:00
|
|
|
#include "drm-client-protocol.h"
|
2019-09-24 14:33:15 +02:00
|
|
|
#include "linux-dmabuf-unstable-v1-client-protocol.h"
|
2019-06-21 00:48:19 +02:00
|
|
|
#include "pointer-gestures-unstable-v1-client-protocol.h"
|
2019-11-16 21:05:46 +01:00
|
|
|
#include "presentation-time-client-protocol.h"
|
2021-10-26 08:31:48 +02:00
|
|
|
#include "xdg-activation-v1-client-protocol.h"
|
2019-09-24 14:33:15 +02:00
|
|
|
#include "xdg-decoration-unstable-v1-client-protocol.h"
|
2019-01-10 15:17:14 +01:00
|
|
|
#include "xdg-shell-client-protocol.h"
|
2019-05-10 08:36:19 +02:00
|
|
|
#include "tablet-unstable-v2-client-protocol.h"
|
2019-11-12 15:32:08 +01:00
|
|
|
#include "relative-pointer-unstable-v1-client-protocol.h"
|
2019-05-10 08:36:19 +02:00
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
struct wlr_wl_backend *get_wl_backend_from_backend(struct wlr_backend *backend) {
|
|
|
|
assert(wlr_backend_is_wl(backend));
|
|
|
|
return (struct wlr_wl_backend *)backend;
|
2018-09-17 22:10:34 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 18:27:05 +02:00
|
|
|
static int dispatch_events(int fd, uint32_t mask, void *data) {
|
2018-11-11 06:09:04 +01:00
|
|
|
struct wlr_wl_backend *wl = data;
|
2017-11-16 09:33:47 +01:00
|
|
|
|
|
|
|
if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {
|
2020-01-09 13:52:36 +01:00
|
|
|
if (mask & WL_EVENT_ERROR) {
|
|
|
|
wlr_log(WLR_ERROR, "Failed to read from remote Wayland display");
|
|
|
|
}
|
2018-11-11 06:09:04 +01:00
|
|
|
wl_display_terminate(wl->local_display);
|
2017-11-16 09:33:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-09 13:52:36 +01:00
|
|
|
int count = 0;
|
2017-06-20 23:51:45 +02:00
|
|
|
if (mask & WL_EVENT_READABLE) {
|
2020-01-09 13:52:36 +01:00
|
|
|
count = wl_display_dispatch(wl->remote_display);
|
2018-11-11 21:11:15 +01:00
|
|
|
}
|
|
|
|
if (mask & WL_EVENT_WRITABLE) {
|
|
|
|
wl_display_flush(wl->remote_display);
|
2017-06-20 23:51:45 +02:00
|
|
|
}
|
2017-06-20 18:27:05 +02:00
|
|
|
if (mask == 0) {
|
2020-01-09 13:52:36 +01:00
|
|
|
count = wl_display_dispatch_pending(wl->remote_display);
|
2018-11-11 06:09:04 +01:00
|
|
|
wl_display_flush(wl->remote_display);
|
2017-06-20 18:27:05 +02:00
|
|
|
}
|
2018-11-11 21:11:15 +01:00
|
|
|
|
2020-01-09 13:52:36 +01:00
|
|
|
if (count < 0) {
|
|
|
|
wlr_log(WLR_ERROR, "Failed to dispatch remote Wayland display");
|
|
|
|
wl_display_terminate(wl->local_display);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return count;
|
2017-06-20 18:27:05 +02:00
|
|
|
}
|
|
|
|
|
2019-01-10 15:17:14 +01:00
|
|
|
static void xdg_wm_base_handle_ping(void *data,
|
|
|
|
struct xdg_wm_base *base, uint32_t serial) {
|
|
|
|
xdg_wm_base_pong(base, serial);
|
2018-11-11 04:47:30 +01:00
|
|
|
}
|
|
|
|
|
2019-01-10 15:17:14 +01:00
|
|
|
static const struct xdg_wm_base_listener xdg_wm_base_listener = {
|
|
|
|
xdg_wm_base_handle_ping,
|
2018-11-11 04:47:30 +01:00
|
|
|
};
|
|
|
|
|
2019-09-24 14:33:15 +02:00
|
|
|
static void linux_dmabuf_v1_handle_format(void *data,
|
|
|
|
struct zwp_linux_dmabuf_v1 *linux_dmabuf_v1, uint32_t format) {
|
|
|
|
// Note, this event is deprecated
|
|
|
|
struct wlr_wl_backend *wl = data;
|
|
|
|
|
|
|
|
wlr_drm_format_set_add(&wl->linux_dmabuf_v1_formats, format,
|
|
|
|
DRM_FORMAT_MOD_INVALID);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void linux_dmabuf_v1_handle_modifier(void *data,
|
|
|
|
struct zwp_linux_dmabuf_v1 *linux_dmabuf_v1, uint32_t format,
|
|
|
|
uint32_t modifier_hi, uint32_t modifier_lo) {
|
|
|
|
struct wlr_wl_backend *wl = data;
|
|
|
|
|
|
|
|
uint64_t modifier = ((uint64_t)modifier_hi << 32) | modifier_lo;
|
|
|
|
wlr_drm_format_set_add(&wl->linux_dmabuf_v1_formats, format, modifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct zwp_linux_dmabuf_v1_listener linux_dmabuf_v1_listener = {
|
|
|
|
.format = linux_dmabuf_v1_handle_format,
|
|
|
|
.modifier = linux_dmabuf_v1_handle_modifier,
|
|
|
|
};
|
|
|
|
|
2021-01-04 10:51:34 +01:00
|
|
|
static bool device_has_name(const drmDevice *device, const char *name) {
|
|
|
|
for (size_t i = 0; i < DRM_NODE_MAX; i++) {
|
|
|
|
if (!(device->available_nodes & (1 << i))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(device->nodes[i], name) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *get_render_name(const char *name) {
|
|
|
|
uint32_t flags = 0;
|
|
|
|
int devices_len = drmGetDevices2(flags, NULL, 0);
|
|
|
|
if (devices_len < 0) {
|
2021-04-26 16:27:24 +02:00
|
|
|
wlr_log(WLR_ERROR, "drmGetDevices2 failed: %s", strerror(-devices_len));
|
2021-01-04 10:51:34 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
drmDevice **devices = calloc(devices_len, sizeof(drmDevice *));
|
|
|
|
if (devices == NULL) {
|
|
|
|
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
devices_len = drmGetDevices2(flags, devices, devices_len);
|
|
|
|
if (devices_len < 0) {
|
|
|
|
free(devices);
|
2021-04-26 16:27:24 +02:00
|
|
|
wlr_log(WLR_ERROR, "drmGetDevices2 failed: %s", strerror(-devices_len));
|
2021-01-04 10:51:34 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const drmDevice *match = NULL;
|
|
|
|
for (int i = 0; i < devices_len; i++) {
|
|
|
|
if (device_has_name(devices[i], name)) {
|
|
|
|
match = devices[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *render_name = NULL;
|
|
|
|
if (match == NULL) {
|
|
|
|
wlr_log(WLR_ERROR, "Cannot find DRM device %s", name);
|
|
|
|
} else if (!(match->available_nodes & (1 << DRM_NODE_RENDER))) {
|
2021-02-23 11:41:47 +01:00
|
|
|
// Likely a split display/render setup. Pick the primary node and hope
|
|
|
|
// Mesa will open the right render node under-the-hood.
|
|
|
|
wlr_log(WLR_DEBUG, "DRM device %s has no render node, "
|
|
|
|
"falling back to primary node", name);
|
|
|
|
assert(match->available_nodes & (1 << DRM_NODE_PRIMARY));
|
|
|
|
render_name = strdup(match->nodes[DRM_NODE_PRIMARY]);
|
2021-01-04 10:51:34 +01:00
|
|
|
} else {
|
|
|
|
render_name = strdup(match->nodes[DRM_NODE_RENDER]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < devices_len; i++) {
|
|
|
|
drmFreeDevice(&devices[i]);
|
|
|
|
}
|
|
|
|
free(devices);
|
|
|
|
|
|
|
|
return render_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void legacy_drm_handle_device(void *data, struct wl_drm *drm,
|
|
|
|
const char *name) {
|
|
|
|
struct wlr_wl_backend *wl = data;
|
|
|
|
|
|
|
|
// TODO: get FD from linux-dmabuf hints instead
|
|
|
|
wl->drm_render_name = get_render_name(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void legacy_drm_handle_format(void *data, struct wl_drm *drm,
|
|
|
|
uint32_t format) {
|
|
|
|
// This space is intentionally left blank
|
|
|
|
}
|
|
|
|
|
|
|
|
static void legacy_drm_handle_authenticated(void *data, struct wl_drm *drm) {
|
|
|
|
// This space is intentionally left blank
|
|
|
|
}
|
|
|
|
|
|
|
|
static void legacy_drm_handle_capabilities(void *data, struct wl_drm *drm,
|
|
|
|
uint32_t caps) {
|
|
|
|
// This space is intentionally left blank
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_drm_listener legacy_drm_listener = {
|
|
|
|
.device = legacy_drm_handle_device,
|
|
|
|
.format = legacy_drm_handle_format,
|
|
|
|
.authenticated = legacy_drm_handle_authenticated,
|
|
|
|
.capabilities = legacy_drm_handle_capabilities,
|
|
|
|
};
|
|
|
|
|
2021-02-09 23:29:44 +01:00
|
|
|
static void shm_handle_format(void *data, struct wl_shm *shm,
|
|
|
|
uint32_t shm_format) {
|
|
|
|
struct wlr_wl_backend *wl = data;
|
|
|
|
uint32_t drm_format = convert_wl_shm_format_to_drm(shm_format);
|
|
|
|
wlr_drm_format_set_add(&wl->shm_formats, drm_format, DRM_FORMAT_MOD_INVALID);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_shm_listener shm_listener = {
|
|
|
|
.format = shm_handle_format,
|
|
|
|
};
|
|
|
|
|
2018-11-11 04:47:30 +01:00
|
|
|
static void registry_global(void *data, struct wl_registry *registry,
|
2018-11-11 05:00:51 +01:00
|
|
|
uint32_t name, const char *iface, uint32_t version) {
|
|
|
|
struct wlr_wl_backend *wl = data;
|
|
|
|
|
2020-06-04 14:33:32 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Remote wayland global: %s v%" PRIu32, iface, version);
|
2018-11-11 05:00:51 +01:00
|
|
|
|
|
|
|
if (strcmp(iface, wl_compositor_interface.name) == 0) {
|
|
|
|
wl->compositor = wl_registry_bind(registry, name,
|
|
|
|
&wl_compositor_interface, 4);
|
|
|
|
} else if (strcmp(iface, wl_seat_interface.name) == 0) {
|
2020-10-03 17:34:32 +02:00
|
|
|
struct wl_seat *wl_seat = wl_registry_bind(registry, name,
|
2019-01-26 11:04:05 +01:00
|
|
|
&wl_seat_interface, 5);
|
2020-10-18 19:12:01 +02:00
|
|
|
if (!create_wl_seat(wl_seat, wl)) {
|
|
|
|
wl_seat_destroy(wl_seat);
|
|
|
|
}
|
2019-01-10 15:17:14 +01:00
|
|
|
} else if (strcmp(iface, xdg_wm_base_interface.name) == 0) {
|
|
|
|
wl->xdg_wm_base = wl_registry_bind(registry, name,
|
|
|
|
&xdg_wm_base_interface, 1);
|
|
|
|
xdg_wm_base_add_listener(wl->xdg_wm_base, &xdg_wm_base_listener, NULL);
|
2019-05-06 18:06:31 +02:00
|
|
|
} else if (strcmp(iface, zxdg_decoration_manager_v1_interface.name) == 0) {
|
|
|
|
wl->zxdg_decoration_manager_v1 = wl_registry_bind(registry, name,
|
|
|
|
&zxdg_decoration_manager_v1_interface, 1);
|
2019-06-21 00:48:19 +02:00
|
|
|
} else if (strcmp(iface, zwp_pointer_gestures_v1_interface.name) == 0) {
|
|
|
|
wl->zwp_pointer_gestures_v1 = wl_registry_bind(registry, name,
|
2021-07-12 19:51:21 +02:00
|
|
|
&zwp_pointer_gestures_v1_interface, version < 3 ? version : 3);
|
2019-11-16 21:05:46 +01:00
|
|
|
} else if (strcmp(iface, wp_presentation_interface.name) == 0) {
|
|
|
|
wl->presentation = wl_registry_bind(registry, name,
|
|
|
|
&wp_presentation_interface, 1);
|
2019-05-10 08:36:19 +02:00
|
|
|
} else if (strcmp(iface, zwp_tablet_manager_v2_interface.name) == 0) {
|
|
|
|
wl->tablet_manager = wl_registry_bind(registry, name,
|
|
|
|
&zwp_tablet_manager_v2_interface, 1);
|
2019-09-24 14:33:15 +02:00
|
|
|
} else if (strcmp(iface, zwp_linux_dmabuf_v1_interface.name) == 0 &&
|
|
|
|
version >= 3) {
|
|
|
|
wl->zwp_linux_dmabuf_v1 = wl_registry_bind(registry, name,
|
|
|
|
&zwp_linux_dmabuf_v1_interface, 3);
|
|
|
|
zwp_linux_dmabuf_v1_add_listener(wl->zwp_linux_dmabuf_v1,
|
|
|
|
&linux_dmabuf_v1_listener, wl);
|
2019-11-12 15:32:08 +01:00
|
|
|
} else if (strcmp(iface, zwp_relative_pointer_manager_v1_interface.name) == 0) {
|
|
|
|
wl->zwp_relative_pointer_manager_v1 = wl_registry_bind(registry, name,
|
|
|
|
&zwp_relative_pointer_manager_v1_interface, 1);
|
2021-01-04 10:51:34 +01:00
|
|
|
} else if (strcmp(iface, wl_drm_interface.name) == 0) {
|
|
|
|
wl->legacy_drm = wl_registry_bind(registry, name, &wl_drm_interface, 1);
|
|
|
|
wl_drm_add_listener(wl->legacy_drm, &legacy_drm_listener, wl);
|
2021-02-09 23:29:44 +01:00
|
|
|
} else if (strcmp(iface, wl_shm_interface.name) == 0) {
|
|
|
|
wl->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
|
|
|
|
wl_shm_add_listener(wl->shm, &shm_listener, wl);
|
2021-10-26 08:31:48 +02:00
|
|
|
} else if (strcmp(iface, xdg_activation_v1_interface.name) == 0) {
|
|
|
|
wl->activation_v1 = wl_registry_bind(registry, name,
|
|
|
|
&xdg_activation_v1_interface, 1);
|
2018-11-11 04:47:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void registry_global_remove(void *data, struct wl_registry *registry,
|
|
|
|
uint32_t name) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_registry_listener registry_listener = {
|
|
|
|
.global = registry_global,
|
|
|
|
.global_remove = registry_global_remove
|
|
|
|
};
|
|
|
|
|
2017-06-19 17:46:50 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-11-11 06:09:04 +01:00
|
|
|
static bool backend_start(struct wlr_backend *backend) {
|
|
|
|
struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend);
|
2021-08-19 20:47:36 +02:00
|
|
|
wlr_log(WLR_INFO, "Starting Wayland backend");
|
2017-06-19 19:40:58 +02:00
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
wl->started = true;
|
2018-11-11 04:47:30 +01:00
|
|
|
|
2020-10-03 23:06:10 +02:00
|
|
|
struct wlr_wl_seat *seat;
|
|
|
|
wl_list_for_each(seat, &wl->seats, link) {
|
2020-10-03 17:34:32 +02:00
|
|
|
if (seat->keyboard) {
|
2020-10-03 22:11:38 +02:00
|
|
|
create_wl_keyboard(seat);
|
2020-10-03 17:34:32 +02:00
|
|
|
}
|
2017-09-23 16:13:05 +02:00
|
|
|
|
2020-10-03 17:34:32 +02:00
|
|
|
if (wl->tablet_manager) {
|
2020-10-03 20:48:11 +02:00
|
|
|
wl_add_tablet_seat(wl->tablet_manager, seat);
|
2020-10-03 17:34:32 +02:00
|
|
|
}
|
2019-05-10 08:36:19 +02:00
|
|
|
}
|
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
for (size_t i = 0; i < wl->requested_outputs; ++i) {
|
|
|
|
wlr_wl_output_create(&wl->backend);
|
2017-06-19 22:36:40 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 17:46:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
static void backend_destroy(struct wlr_backend *backend) {
|
|
|
|
if (!backend) {
|
2017-04-25 21:06:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-06-19 17:46:50 +02:00
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend);
|
|
|
|
|
2018-04-29 13:16:31 +02:00
|
|
|
struct wlr_wl_output *output, *tmp_output;
|
2018-11-11 06:09:04 +01:00
|
|
|
wl_list_for_each_safe(output, tmp_output, &wl->outputs, link) {
|
2017-10-14 22:33:00 +02:00
|
|
|
wlr_output_destroy(&output->wlr_output);
|
2017-04-26 03:26:29 +02:00
|
|
|
}
|
2017-06-19 17:46:50 +02:00
|
|
|
|
2017-10-14 22:33:00 +02:00
|
|
|
struct wlr_input_device *input_device, *tmp_input_device;
|
2018-11-11 06:09:04 +01:00
|
|
|
wl_list_for_each_safe(input_device, tmp_input_device, &wl->devices, link) {
|
2017-10-14 22:33:00 +02:00
|
|
|
wlr_input_device_destroy(input_device);
|
2017-06-20 19:01:20 +02:00
|
|
|
}
|
|
|
|
|
2021-04-29 00:16:34 +02:00
|
|
|
struct wlr_wl_buffer *buffer, *tmp_buffer;
|
|
|
|
wl_list_for_each_safe(buffer, tmp_buffer, &wl->buffers, link) {
|
|
|
|
destroy_wl_buffer(buffer);
|
|
|
|
}
|
|
|
|
|
2021-04-29 00:07:31 +02:00
|
|
|
wlr_backend_finish(backend);
|
2018-01-30 19:45:57 +01:00
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
wl_list_remove(&wl->local_display_destroy.link);
|
2017-12-07 23:44:59 +01:00
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
wl_event_source_remove(wl->remote_display_src);
|
|
|
|
|
2020-12-04 16:38:55 +01:00
|
|
|
close(wl->drm_fd);
|
2018-11-11 06:09:04 +01:00
|
|
|
|
2021-02-09 23:29:44 +01:00
|
|
|
wlr_drm_format_set_finish(&wl->shm_formats);
|
2019-09-24 14:33:15 +02:00
|
|
|
wlr_drm_format_set_finish(&wl->linux_dmabuf_v1_formats);
|
|
|
|
|
2020-10-03 17:34:32 +02:00
|
|
|
destroy_wl_seats(wl);
|
2019-05-06 18:06:31 +02:00
|
|
|
if (wl->zxdg_decoration_manager_v1) {
|
|
|
|
zxdg_decoration_manager_v1_destroy(wl->zxdg_decoration_manager_v1);
|
|
|
|
}
|
2019-06-21 00:48:19 +02:00
|
|
|
if (wl->zwp_pointer_gestures_v1) {
|
|
|
|
zwp_pointer_gestures_v1_destroy(wl->zwp_pointer_gestures_v1);
|
|
|
|
}
|
2019-11-16 21:05:46 +01:00
|
|
|
if (wl->presentation) {
|
|
|
|
wp_presentation_destroy(wl->presentation);
|
|
|
|
}
|
2019-09-24 14:33:15 +02:00
|
|
|
if (wl->zwp_linux_dmabuf_v1) {
|
|
|
|
zwp_linux_dmabuf_v1_destroy(wl->zwp_linux_dmabuf_v1);
|
|
|
|
}
|
2021-02-09 23:29:44 +01:00
|
|
|
if (wl->shm) {
|
|
|
|
wl_shm_destroy(wl->shm);
|
|
|
|
}
|
2019-11-12 15:32:08 +01:00
|
|
|
if (wl->zwp_relative_pointer_manager_v1) {
|
|
|
|
zwp_relative_pointer_manager_v1_destroy(wl->zwp_relative_pointer_manager_v1);
|
|
|
|
}
|
2021-01-04 10:51:34 +01:00
|
|
|
free(wl->drm_render_name);
|
2021-10-26 08:31:48 +02:00
|
|
|
free(wl->activation_token);
|
2019-01-10 15:17:14 +01:00
|
|
|
xdg_wm_base_destroy(wl->xdg_wm_base);
|
2018-11-11 06:09:04 +01:00
|
|
|
wl_compositor_destroy(wl->compositor);
|
|
|
|
wl_registry_destroy(wl->registry);
|
2021-01-29 10:06:16 +01:00
|
|
|
wl_display_flush(wl->remote_display);
|
2018-11-11 06:09:04 +01:00
|
|
|
wl_display_disconnect(wl->remote_display);
|
|
|
|
free(wl);
|
2017-04-25 21:06:58 +02:00
|
|
|
}
|
|
|
|
|
2020-12-04 16:38:55 +01:00
|
|
|
static int backend_get_drm_fd(struct wlr_backend *backend) {
|
|
|
|
struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend);
|
|
|
|
return wl->drm_fd;
|
|
|
|
}
|
|
|
|
|
2021-04-29 00:16:34 +02:00
|
|
|
static uint32_t get_buffer_caps(struct wlr_backend *backend) {
|
2021-04-28 16:09:33 +02:00
|
|
|
struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend);
|
|
|
|
return (wl->zwp_linux_dmabuf_v1 ? WLR_BUFFER_CAP_DMABUF : 0)
|
|
|
|
| (wl->shm ? WLR_BUFFER_CAP_SHM : 0);
|
|
|
|
}
|
|
|
|
|
2021-02-04 14:57:18 +01:00
|
|
|
static const struct wlr_backend_impl backend_impl = {
|
2018-04-26 00:51:00 +02:00
|
|
|
.start = backend_start,
|
|
|
|
.destroy = backend_destroy,
|
2020-12-04 16:38:55 +01:00
|
|
|
.get_drm_fd = backend_get_drm_fd,
|
2021-04-29 00:16:34 +02:00
|
|
|
.get_buffer_caps = get_buffer_caps,
|
2017-06-19 17:46:50 +02:00
|
|
|
};
|
|
|
|
|
2017-06-21 00:22:21 +02:00
|
|
|
bool wlr_backend_is_wl(struct wlr_backend *b) {
|
|
|
|
return b->impl == &backend_impl;
|
|
|
|
}
|
2017-06-19 17:46:50 +02:00
|
|
|
|
2017-12-07 23:44:59 +01:00
|
|
|
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
2018-11-11 06:09:04 +01:00
|
|
|
struct wlr_wl_backend *wl =
|
|
|
|
wl_container_of(listener, wl, local_display_destroy);
|
|
|
|
backend_destroy(&wl->backend);
|
2017-12-07 23:44:59 +01:00
|
|
|
}
|
|
|
|
|
2018-04-28 13:38:03 +02:00
|
|
|
struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
|
2020-12-19 11:34:28 +01:00
|
|
|
const char *remote) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_INFO, "Creating wayland backend");
|
2017-06-19 17:46:50 +02:00
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
struct wlr_wl_backend *wl = calloc(1, sizeof(*wl));
|
|
|
|
if (!wl) {
|
|
|
|
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
2017-06-19 17:46:50 +02:00
|
|
|
return NULL;
|
2017-04-25 21:06:58 +02:00
|
|
|
}
|
2017-06-19 17:46:50 +02:00
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
wlr_backend_init(&wl->backend, &backend_impl);
|
2017-06-19 19:40:58 +02:00
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
wl->local_display = display;
|
|
|
|
wl_list_init(&wl->devices);
|
|
|
|
wl_list_init(&wl->outputs);
|
2020-10-03 23:06:10 +02:00
|
|
|
wl_list_init(&wl->seats);
|
2020-12-11 18:14:58 +01:00
|
|
|
wl_list_init(&wl->buffers);
|
2017-09-23 06:29:53 +02:00
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
wl->remote_display = wl_display_connect(remote);
|
|
|
|
if (!wl->remote_display) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log_errno(WLR_ERROR, "Could not connect to remote display");
|
2018-11-11 06:09:04 +01:00
|
|
|
goto error_wl;
|
2017-09-23 06:29:53 +02:00
|
|
|
}
|
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
wl->registry = wl_display_get_registry(wl->remote_display);
|
|
|
|
if (!wl->registry) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log_errno(WLR_ERROR, "Could not obtain reference to remote registry");
|
2018-11-11 06:09:04 +01:00
|
|
|
goto error_display;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_registry_add_listener(wl->registry, ®istry_listener, wl);
|
2020-11-26 11:40:23 +01:00
|
|
|
wl_display_roundtrip(wl->remote_display); // get globals
|
|
|
|
wl_display_roundtrip(wl->remote_display); // get linux-dmabuf formats
|
2018-11-11 06:09:04 +01:00
|
|
|
|
|
|
|
if (!wl->compositor) {
|
|
|
|
wlr_log(WLR_ERROR,
|
|
|
|
"Remote Wayland compositor does not support wl_compositor");
|
|
|
|
goto error_registry;
|
|
|
|
}
|
2019-01-10 15:17:14 +01:00
|
|
|
if (!wl->xdg_wm_base) {
|
2018-11-11 06:09:04 +01:00
|
|
|
wlr_log(WLR_ERROR,
|
2019-01-10 15:17:14 +01:00
|
|
|
"Remote Wayland compositor does not support xdg-shell");
|
2018-04-28 13:38:03 +02:00
|
|
|
goto error_registry;
|
2017-09-23 06:29:53 +02:00
|
|
|
}
|
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
struct wl_event_loop *loop = wl_display_get_event_loop(wl->local_display);
|
|
|
|
int fd = wl_display_get_fd(wl->remote_display);
|
2021-01-05 19:52:06 +01:00
|
|
|
wl->remote_display_src = wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
|
2018-11-11 06:09:04 +01:00
|
|
|
dispatch_events, wl);
|
|
|
|
if (!wl->remote_display_src) {
|
|
|
|
wlr_log(WLR_ERROR, "Failed to create event source");
|
|
|
|
goto error_registry;
|
|
|
|
}
|
|
|
|
wl_event_source_check(wl->remote_display_src);
|
|
|
|
|
2021-02-09 23:37:49 +01:00
|
|
|
if (wl->drm_render_name != NULL) {
|
|
|
|
wlr_log(WLR_DEBUG, "Opening DRM render node %s", wl->drm_render_name);
|
|
|
|
wl->drm_fd = open(wl->drm_render_name, O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
|
|
|
if (wl->drm_fd < 0) {
|
|
|
|
wlr_log_errno(WLR_ERROR, "Failed to open DRM render node %s",
|
|
|
|
wl->drm_render_name);
|
|
|
|
goto error_remote_display_src;
|
|
|
|
}
|
|
|
|
} else {
|
2021-04-28 16:11:09 +02:00
|
|
|
wl->drm_fd = -1;
|
2020-11-26 11:40:23 +01:00
|
|
|
}
|
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
wl->local_display_destroy.notify = handle_display_destroy;
|
|
|
|
wl_display_add_destroy_listener(display, &wl->local_display_destroy);
|
2017-12-07 23:44:59 +01:00
|
|
|
|
2021-10-26 08:31:48 +02:00
|
|
|
const char *token = getenv("XDG_ACTIVATION_TOKEN");
|
|
|
|
if (token != NULL) {
|
|
|
|
wl->activation_token = strdup(token);
|
|
|
|
unsetenv("XDG_ACTIVATION_TOKEN");
|
|
|
|
}
|
|
|
|
|
2018-11-11 06:09:04 +01:00
|
|
|
return &wl->backend;
|
2018-04-28 13:38:03 +02:00
|
|
|
|
2020-12-04 16:38:55 +01:00
|
|
|
error_remote_display_src:
|
2018-11-11 06:09:04 +01:00
|
|
|
wl_event_source_remove(wl->remote_display_src);
|
2018-04-28 13:38:03 +02:00
|
|
|
error_registry:
|
2021-01-04 10:51:34 +01:00
|
|
|
free(wl->drm_render_name);
|
2018-11-11 06:09:04 +01:00
|
|
|
if (wl->compositor) {
|
|
|
|
wl_compositor_destroy(wl->compositor);
|
|
|
|
}
|
2019-01-10 15:17:14 +01:00
|
|
|
if (wl->xdg_wm_base) {
|
|
|
|
xdg_wm_base_destroy(wl->xdg_wm_base);
|
2018-11-11 06:09:04 +01:00
|
|
|
}
|
|
|
|
wl_registry_destroy(wl->registry);
|
|
|
|
error_display:
|
|
|
|
wl_display_disconnect(wl->remote_display);
|
|
|
|
error_wl:
|
2021-04-29 00:16:34 +02:00
|
|
|
wlr_backend_finish(&wl->backend);
|
2018-11-11 06:09:04 +01:00
|
|
|
free(wl);
|
2018-04-28 13:38:03 +02:00
|
|
|
return NULL;
|
2017-04-25 17:32:52 +02:00
|
|
|
}
|
2019-11-12 17:56:57 +01:00
|
|
|
|
|
|
|
struct wl_display *wlr_wl_backend_get_remote_display(struct wlr_backend *backend) {
|
|
|
|
struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend);
|
|
|
|
return wl->remote_display;
|
|
|
|
}
|