swayfx/sway/server.c

81 lines
2.6 KiB
C
Raw Normal View History

#define _POSIX_C_SOURCE 200112L
#include <stdlib.h>
#include <stdbool.h>
#include <wayland-server.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
#include <wlr/render.h>
#include <wlr/render/gles2.h>
2017-11-23 13:06:08 +11:00
#include <wlr/types/wlr_compositor.h>
2017-12-04 06:21:26 +11:00
#include <wlr/types/wlr_wl_shell.h>
// TODO WLR: make Xwayland optional
#include <wlr/xwayland.h>
#include "sway/server.h"
#include "log.h"
bool server_init(struct sway_server *server) {
sway_log(L_DEBUG, "Initializing Wayland server");
server->wl_display = wl_display_create();
server->wl_event_loop = wl_display_get_event_loop(server->wl_display);
server->backend = wlr_backend_autocreate(server->wl_display);
server->renderer = wlr_gles2_renderer_create(server->backend);
wl_display_init_shm(server->wl_display);
2017-11-23 13:06:08 +11:00
server->compositor = wlr_compositor_create(
server->wl_display, server->renderer);
server->data_device_manager =
wlr_data_device_manager_create(server->wl_display);
server->output_add.notify = output_add_notify;
wl_signal_add(&server->backend->events.output_add, &server->output_add);
2017-11-12 06:41:18 +11:00
server->output_remove.notify = output_remove_notify;
wl_signal_add(&server->backend->events.output_remove,
&server->output_remove);
server->xdg_shell_v6 = wlr_xdg_shell_v6_create(server->wl_display);
wl_signal_add(&server->xdg_shell_v6->events.new_surface,
&server->xdg_shell_v6_surface);
server->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface;
2017-12-04 22:19:36 +11:00
// TODO make xwayland optional
server->xwayland =
wlr_xwayland_create(server->wl_display, server->compositor);
wl_signal_add(&server->xwayland->events.new_surface,
&server->xwayland_surface);
server->xwayland_surface.notify = handle_xwayland_surface;
2017-12-04 06:21:26 +11:00
server->wl_shell = wlr_wl_shell_create(server->wl_display);
wl_signal_add(&server->wl_shell->events.new_surface,
&server->wl_shell_surface);
server->wl_shell_surface.notify = handle_wl_shell_surface;
server->socket = wl_display_add_socket_auto(server->wl_display);
if (!sway_assert(server->socket, "Unable to open wayland socket")) {
wlr_backend_destroy(server->backend);
return false;
}
return true;
}
void server_fini(struct sway_server *server) {
// TODO WLR: tear down more stuff
wlr_backend_destroy(server->backend);
}
void server_run(struct sway_server *server) {
sway_log(L_INFO, "Running compositor on wayland display '%s'",
server->socket);
setenv("_WAYLAND_DISPLAY", server->socket, true);
if (!sway_assert(wlr_backend_start(server->backend),
"Failed to start backend")) {
wlr_backend_destroy(server->backend);
return;
}
setenv("WAYLAND_DISPLAY", server->socket, true);
wl_display_run(server->wl_display);
}