2017-10-22 16:37:30 +02:00
|
|
|
#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 03:06:08 +01:00
|
|
|
#include <wlr/types/wlr_compositor.h>
|
2017-12-03 20:21:26 +01:00
|
|
|
#include <wlr/types/wlr_wl_shell.h>
|
2017-10-22 16:37:30 +02:00
|
|
|
// TODO WLR: make Xwayland optional
|
|
|
|
#include <wlr/xwayland.h>
|
2017-12-31 22:32:28 +01:00
|
|
|
#include <wlr/util/log.h>
|
2018-01-31 02:01:49 +01:00
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
2017-10-22 16:37:30 +02:00
|
|
|
#include "sway/server.h"
|
2017-12-08 14:07:47 +01:00
|
|
|
#include "sway/input/input-manager.h"
|
2017-10-22 16:37:30 +02:00
|
|
|
|
2018-01-31 02:01:49 +01:00
|
|
|
static void server_ready(struct wl_listener *listener, void *data) {
|
|
|
|
wlr_log(L_DEBUG, "Compositor is ready, executing cmds in queue");
|
|
|
|
// Execute commands until there are none left
|
|
|
|
config->active = true;
|
|
|
|
while (config->cmd_queue->length) {
|
|
|
|
char *line = config->cmd_queue->items[0];
|
2018-02-24 18:50:24 +01:00
|
|
|
struct cmd_results *res = execute_command(line, NULL);
|
2018-01-31 02:01:49 +01:00
|
|
|
if (res->status != CMD_SUCCESS) {
|
|
|
|
wlr_log(L_ERROR, "Error on line '%s': %s", line, res->error);
|
|
|
|
}
|
|
|
|
free_cmd_results(res);
|
|
|
|
free(line);
|
|
|
|
list_del(config->cmd_queue, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-22 16:37:30 +02:00
|
|
|
bool server_init(struct sway_server *server) {
|
2017-12-31 22:32:28 +01:00
|
|
|
wlr_log(L_DEBUG, "Initializing Wayland server");
|
2017-10-22 16:37:30 +02:00
|
|
|
|
|
|
|
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 03:06:08 +01:00
|
|
|
server->compositor = wlr_compositor_create(
|
|
|
|
server->wl_display, server->renderer);
|
|
|
|
|
2017-10-22 16:37:30 +02:00
|
|
|
server->data_device_manager =
|
|
|
|
wlr_data_device_manager_create(server->wl_display);
|
|
|
|
|
2018-02-14 20:51:51 +01:00
|
|
|
server->new_output.notify = handle_new_output;
|
|
|
|
wl_signal_add(&server->backend->events.new_output, &server->new_output);
|
2017-11-11 20:41:18 +01:00
|
|
|
|
2017-11-12 00:06:50 +01:00
|
|
|
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 12:19:36 +01: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;
|
2018-01-31 02:01:49 +01:00
|
|
|
wl_signal_add(&server->xwayland->events.ready,
|
|
|
|
&server->xwayland_ready);
|
|
|
|
// TODO: call server_ready now if xwayland is not enabled
|
|
|
|
server->xwayland_ready.notify = server_ready;
|
2017-12-04 12:19:36 +01:00
|
|
|
|
2017-12-03 20:21:26 +01: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;
|
|
|
|
|
2017-11-11 17:58:43 +01:00
|
|
|
server->socket = wl_display_add_socket_auto(server->wl_display);
|
2017-12-31 22:32:28 +01:00
|
|
|
if (!server->socket) {
|
|
|
|
wlr_log(L_ERROR, "Unable to open wayland socket");
|
2017-10-22 16:37:30 +02:00
|
|
|
wlr_backend_destroy(server->backend);
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-06 14:28:46 +01:00
|
|
|
|
2017-12-12 14:29:37 +01:00
|
|
|
input_manager = sway_input_manager_create(server);
|
2017-12-06 14:28:46 +01:00
|
|
|
|
2017-10-22 16:37:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void server_fini(struct sway_server *server) {
|
|
|
|
// TODO WLR: tear down more stuff
|
|
|
|
wlr_backend_destroy(server->backend);
|
|
|
|
}
|
2017-11-11 17:58:43 +01:00
|
|
|
|
|
|
|
void server_run(struct sway_server *server) {
|
2017-12-31 22:32:28 +01:00
|
|
|
wlr_log(L_INFO, "Running compositor on wayland display '%s'",
|
2017-11-11 17:58:43 +01:00
|
|
|
server->socket);
|
|
|
|
setenv("_WAYLAND_DISPLAY", server->socket, true);
|
2017-12-31 22:32:28 +01:00
|
|
|
if (!wlr_backend_start(server->backend)) {
|
|
|
|
wlr_log(L_ERROR, "Failed to start backend");
|
2017-11-11 17:58:43 +01:00
|
|
|
wlr_backend_destroy(server->backend);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setenv("WAYLAND_DISPLAY", server->socket, true);
|
|
|
|
wl_display_run(server->wl_display);
|
|
|
|
}
|