2017-10-23 01:37:30 +11:00
|
|
|
#define _POSIX_C_SOURCE 200112L
|
2018-03-30 15:47:57 +11:00
|
|
|
#include <assert.h>
|
2017-10-23 01:37:30 +11:00
|
|
|
#include <stdbool.h>
|
2018-03-30 15:47:57 +11:00
|
|
|
#include <stdlib.h>
|
2017-10-23 01:37:30 +11:00
|
|
|
#include <wayland-server.h>
|
|
|
|
#include <wlr/backend.h>
|
|
|
|
#include <wlr/backend/session.h>
|
2018-03-20 09:31:18 +11:00
|
|
|
#include <wlr/render/wlr_renderer.h>
|
2017-11-23 13:06:08 +11:00
|
|
|
#include <wlr/types/wlr_compositor.h>
|
2018-03-30 15:47:57 +11:00
|
|
|
#include <wlr/types/wlr_gamma_control.h>
|
2018-04-01 00:21:15 +11:00
|
|
|
#include <wlr/types/wlr_linux_dmabuf.h>
|
2018-03-29 06:47:22 +11:00
|
|
|
#include <wlr/types/wlr_layer_shell.h>
|
2018-04-01 00:21:15 +11:00
|
|
|
#include <wlr/types/wlr_primary_selection.h>
|
2018-03-30 09:07:03 +11:00
|
|
|
#include <wlr/types/wlr_screenshooter.h>
|
2018-04-08 03:21:07 +10:00
|
|
|
#include <wlr/types/wlr_server_decoration.h>
|
2018-03-31 15:13:26 +11:00
|
|
|
#include <wlr/types/wlr_xcursor_manager.h>
|
2018-04-06 04:01:14 +10:00
|
|
|
#include <wlr/types/wlr_xdg_output.h>
|
|
|
|
#include <wlr/types/wlr_wl_shell.h>
|
2018-04-17 17:54:02 +10:00
|
|
|
#include <wlr/types/wlr_idle.h>
|
2018-03-30 15:47:57 +11:00
|
|
|
#include <wlr/util/log.h>
|
2017-10-23 01:37:30 +11:00
|
|
|
// TODO WLR: make Xwayland optional
|
|
|
|
#include <wlr/xwayland.h>
|
2018-01-31 12:01:49 +11:00
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
2017-12-09 00:07:47 +11:00
|
|
|
#include "sway/input/input-manager.h"
|
2018-04-06 04:01:14 +10:00
|
|
|
#include "sway/server.h"
|
|
|
|
#include "sway/tree/layout.h"
|
2017-10-23 01:37:30 +11:00
|
|
|
|
2018-01-31 12:01:49 +11: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-25 04:50:24 +11:00
|
|
|
struct cmd_results *res = execute_command(line, NULL);
|
2018-01-31 12:01:49 +11: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-23 01:37:30 +11:00
|
|
|
bool server_init(struct sway_server *server) {
|
2018-01-01 08:32:28 +11:00
|
|
|
wlr_log(L_DEBUG, "Initializing Wayland server");
|
2017-10-23 01:37:30 +11: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);
|
|
|
|
|
2018-05-10 02:32:55 +10:00
|
|
|
if (!server->backend) {
|
|
|
|
wlr_log(L_ERROR, "Unable to create backend");
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-30 15:47:57 +11:00
|
|
|
struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend);
|
|
|
|
assert(renderer);
|
|
|
|
|
2018-04-21 23:08:48 +10:00
|
|
|
wlr_renderer_init_wl_shm(renderer, server->wl_display);
|
2017-10-23 01:37:30 +11:00
|
|
|
|
2018-03-30 15:47:57 +11:00
|
|
|
server->compositor = wlr_compositor_create(server->wl_display, renderer);
|
2017-10-23 01:37:30 +11:00
|
|
|
server->data_device_manager =
|
|
|
|
wlr_data_device_manager_create(server->wl_display);
|
2018-03-30 09:07:03 +11:00
|
|
|
|
2018-04-17 17:54:02 +10:00
|
|
|
server->idle = wlr_idle_create(server->wl_display);
|
2018-03-30 09:07:03 +11:00
|
|
|
wlr_screenshooter_create(server->wl_display);
|
|
|
|
wlr_gamma_control_manager_create(server->wl_display);
|
2018-04-01 00:21:15 +11:00
|
|
|
wlr_primary_selection_device_manager_create(server->wl_display);
|
2017-10-23 01:37:30 +11:00
|
|
|
|
2018-02-15 06:51:51 +11:00
|
|
|
server->new_output.notify = handle_new_output;
|
|
|
|
wl_signal_add(&server->backend->events.new_output, &server->new_output);
|
2017-11-12 06:41:18 +11:00
|
|
|
|
2018-04-06 04:01:14 +10:00
|
|
|
wlr_xdg_output_manager_create(server->wl_display,
|
|
|
|
root_container.sway_root->output_layout);
|
|
|
|
|
2018-03-29 06:47:22 +11:00
|
|
|
server->layer_shell = wlr_layer_shell_create(server->wl_display);
|
|
|
|
wl_signal_add(&server->layer_shell->events.new_surface,
|
|
|
|
&server->layer_shell_surface);
|
|
|
|
server->layer_shell_surface.notify = handle_layer_shell_surface;
|
|
|
|
|
2017-11-12 10:06:50 +11: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;
|
|
|
|
|
2018-04-01 00:21:15 +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;
|
|
|
|
|
2017-12-04 22:19:36 +11:00
|
|
|
// TODO make xwayland optional
|
|
|
|
server->xwayland =
|
2018-05-07 22:23:44 +10:00
|
|
|
wlr_xwayland_create(server->wl_display, server->compositor, false);
|
2017-12-04 22:19:36 +11:00
|
|
|
wl_signal_add(&server->xwayland->events.new_surface,
|
|
|
|
&server->xwayland_surface);
|
|
|
|
server->xwayland_surface.notify = handle_xwayland_surface;
|
2018-01-31 12:01:49 +11: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 22:19:36 +11:00
|
|
|
|
2018-03-31 15:13:26 +11:00
|
|
|
// TODO: configurable cursor theme and size
|
|
|
|
server->xcursor_manager = wlr_xcursor_manager_create(NULL, 24);
|
|
|
|
wlr_xcursor_manager_load(server->xcursor_manager, 1);
|
|
|
|
struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor(
|
|
|
|
server->xcursor_manager, "left_ptr", 1);
|
|
|
|
if (xcursor != NULL) {
|
|
|
|
struct wlr_xcursor_image *image = xcursor->images[0];
|
|
|
|
wlr_xwayland_set_cursor(server->xwayland, image->buffer,
|
|
|
|
image->width * 4, image->width, image->height, image->hotspot_x,
|
|
|
|
image->hotspot_y);
|
|
|
|
}
|
|
|
|
|
2018-04-08 03:21:07 +10:00
|
|
|
// TODO: Integration with sway borders
|
|
|
|
struct wlr_server_decoration_manager *deco_manager =
|
|
|
|
wlr_server_decoration_manager_create(server->wl_display);
|
|
|
|
wlr_server_decoration_manager_set_default_mode(
|
|
|
|
deco_manager, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER);
|
|
|
|
|
2018-04-09 01:19:14 +10:00
|
|
|
wlr_linux_dmabuf_create(server->wl_display, renderer);
|
2017-12-04 06:21:26 +11:00
|
|
|
|
2017-11-12 03:58:43 +11:00
|
|
|
server->socket = wl_display_add_socket_auto(server->wl_display);
|
2018-01-01 08:32:28 +11:00
|
|
|
if (!server->socket) {
|
|
|
|
wlr_log(L_ERROR, "Unable to open wayland socket");
|
2017-10-23 01:37:30 +11:00
|
|
|
wlr_backend_destroy(server->backend);
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-07 00:28:46 +11:00
|
|
|
|
2018-04-02 22:49:38 +10:00
|
|
|
input_manager = input_manager_create(server);
|
2017-10-23 01:37:30 +11:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void server_fini(struct sway_server *server) {
|
2018-04-18 08:15:11 +10:00
|
|
|
// TODO: free sway-specific resources
|
|
|
|
wl_display_destroy(server->wl_display);
|
2017-10-23 01:37:30 +11:00
|
|
|
}
|
2017-11-12 03:58:43 +11:00
|
|
|
|
|
|
|
void server_run(struct sway_server *server) {
|
2018-01-01 08:32:28 +11:00
|
|
|
wlr_log(L_INFO, "Running compositor on wayland display '%s'",
|
2017-11-12 03:58:43 +11:00
|
|
|
server->socket);
|
2018-03-30 15:13:54 +11:00
|
|
|
setenv("WAYLAND_DISPLAY", server->socket, true);
|
2018-01-01 08:32:28 +11:00
|
|
|
if (!wlr_backend_start(server->backend)) {
|
|
|
|
wlr_log(L_ERROR, "Failed to start backend");
|
2017-11-12 03:58:43 +11:00
|
|
|
wlr_backend_destroy(server->backend);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wl_display_run(server->wl_display);
|
|
|
|
}
|