2017-10-22 16:37:30 +02:00
|
|
|
#define _POSIX_C_SOURCE 200112L
|
2018-03-30 06:47:57 +02:00
|
|
|
#include <assert.h>
|
2017-10-22 16:37:30 +02:00
|
|
|
#include <stdbool.h>
|
2018-03-30 06:47:57 +02:00
|
|
|
#include <stdlib.h>
|
2017-10-22 16:37:30 +02:00
|
|
|
#include <wayland-server.h>
|
|
|
|
#include <wlr/backend.h>
|
|
|
|
#include <wlr/backend/session.h>
|
2018-03-19 23:31:18 +01:00
|
|
|
#include <wlr/render/wlr_renderer.h>
|
2017-11-23 03:06:08 +01:00
|
|
|
#include <wlr/types/wlr_compositor.h>
|
2018-07-01 23:55:25 +02:00
|
|
|
#include <wlr/types/wlr_export_dmabuf_v1.h>
|
2018-03-30 06:47:57 +02:00
|
|
|
#include <wlr/types/wlr_gamma_control.h>
|
2018-07-22 17:27:54 +02:00
|
|
|
#include <wlr/types/wlr_gamma_control_v1.h>
|
2018-04-29 10:40:58 +02:00
|
|
|
#include <wlr/types/wlr_idle.h>
|
2018-03-28 21:47:22 +02:00
|
|
|
#include <wlr/types/wlr_layer_shell.h>
|
2018-03-31 15:21:15 +02:00
|
|
|
#include <wlr/types/wlr_primary_selection.h>
|
2018-07-01 23:55:25 +02:00
|
|
|
#include <wlr/types/wlr_screencopy_v1.h>
|
2018-04-07 19:21:07 +02:00
|
|
|
#include <wlr/types/wlr_server_decoration.h>
|
2018-03-31 06:13:26 +02:00
|
|
|
#include <wlr/types/wlr_xcursor_manager.h>
|
2018-04-05 20:01:14 +02:00
|
|
|
#include <wlr/types/wlr_xdg_output.h>
|
2018-03-30 06:47:57 +02:00
|
|
|
#include <wlr/util/log.h>
|
2018-06-23 08:24:11 +02:00
|
|
|
#include "list.h"
|
2018-01-31 02:01:49 +01:00
|
|
|
#include "sway/config.h"
|
2018-07-02 02:26:57 +02:00
|
|
|
#include "sway/desktop/idle_inhibit_v1.h"
|
2017-12-08 14:07:47 +01:00
|
|
|
#include "sway/input/input-manager.h"
|
2018-04-05 20:01:14 +02:00
|
|
|
#include "sway/server.h"
|
2018-08-26 04:05:16 +02:00
|
|
|
#include "sway/tree/root.h"
|
2018-07-25 13:32:20 +02:00
|
|
|
#include "config.h"
|
2018-07-24 22:16:06 +02:00
|
|
|
#ifdef HAVE_XWAYLAND
|
2018-06-18 23:49:28 +02:00
|
|
|
#include "sway/xwayland.h"
|
2018-07-24 22:16:06 +02:00
|
|
|
#endif
|
2018-01-31 02:01:49 +01:00
|
|
|
|
2018-06-13 00:39:24 +02:00
|
|
|
bool server_privileged_prepare(struct sway_server *server) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Preparing Wayland server initialization");
|
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);
|
2018-05-25 14:51:01 +02:00
|
|
|
server->backend = wlr_backend_autocreate(server->wl_display, NULL);
|
2017-10-22 16:37:30 +02:00
|
|
|
|
2018-05-09 18:32:55 +02:00
|
|
|
if (!server->backend) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_ERROR, "Unable to create backend");
|
2018-05-09 18:32:55 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-06-13 00:39:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool server_init(struct sway_server *server) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Initializing Wayland server");
|
2018-06-13 00:39:24 +02:00
|
|
|
|
2018-03-30 06:47:57 +02:00
|
|
|
struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend);
|
|
|
|
assert(renderer);
|
|
|
|
|
2018-05-21 20:11:20 +02:00
|
|
|
wlr_renderer_init_wl_display(renderer, server->wl_display);
|
2017-10-22 16:37:30 +02:00
|
|
|
|
2018-03-30 06:47:57 +02:00
|
|
|
server->compositor = wlr_compositor_create(server->wl_display, renderer);
|
2017-10-22 16:37:30 +02:00
|
|
|
server->data_device_manager =
|
|
|
|
wlr_data_device_manager_create(server->wl_display);
|
2018-03-30 00:07:03 +02:00
|
|
|
|
|
|
|
wlr_gamma_control_manager_create(server->wl_display);
|
2018-07-22 17:27:54 +02:00
|
|
|
wlr_gamma_control_manager_v1_create(server->wl_display);
|
2018-03-31 15:21:15 +02:00
|
|
|
wlr_primary_selection_device_manager_create(server->wl_display);
|
2017-10-22 16:37:30 +02:00
|
|
|
|
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
|
|
|
|
2018-04-05 20:01:14 +02:00
|
|
|
wlr_xdg_output_manager_create(server->wl_display,
|
|
|
|
root_container.sway_root->output_layout);
|
|
|
|
|
2018-07-02 02:26:57 +02:00
|
|
|
server->idle = wlr_idle_create(server->wl_display);
|
|
|
|
server->idle_inhibit_manager_v1 =
|
|
|
|
sway_idle_inhibit_manager_v1_create(server->wl_display, server->idle);
|
2018-06-27 11:16:49 +02:00
|
|
|
|
2018-03-28 21:47:22 +02: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 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;
|
|
|
|
|
2018-05-13 17:38:56 +02:00
|
|
|
server->xdg_shell = wlr_xdg_shell_create(server->wl_display);
|
|
|
|
wl_signal_add(&server->xdg_shell->events.new_surface,
|
|
|
|
&server->xdg_shell_surface);
|
|
|
|
server->xdg_shell_surface.notify = handle_xdg_shell_surface;
|
2018-03-31 15:21:15 +02:00
|
|
|
|
2018-07-24 23:37:41 +02:00
|
|
|
#ifdef HAVE_XWAYLAND
|
2018-06-18 23:49:28 +02:00
|
|
|
server->xwayland.wlr_xwayland =
|
2018-05-13 20:18:07 +02:00
|
|
|
wlr_xwayland_create(server->wl_display, server->compositor, true);
|
2018-06-18 23:49:28 +02:00
|
|
|
wl_signal_add(&server->xwayland.wlr_xwayland->events.new_surface,
|
2017-12-04 12:19:36 +01:00
|
|
|
&server->xwayland_surface);
|
|
|
|
server->xwayland_surface.notify = handle_xwayland_surface;
|
2018-06-18 23:49:28 +02:00
|
|
|
wl_signal_add(&server->xwayland.wlr_xwayland->events.ready,
|
|
|
|
&server->xwayland_ready);
|
|
|
|
server->xwayland_ready.notify = handle_xwayland_ready;
|
2017-12-04 12:19:36 +01:00
|
|
|
|
2018-03-31 06:13:26 +02:00
|
|
|
// TODO: configurable cursor theme and size
|
2018-06-18 23:49:28 +02:00
|
|
|
server->xwayland.xcursor_manager = wlr_xcursor_manager_create(NULL, 24);
|
|
|
|
wlr_xcursor_manager_load(server->xwayland.xcursor_manager, 1);
|
2018-03-31 06:13:26 +02:00
|
|
|
struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor(
|
2018-06-18 23:49:28 +02:00
|
|
|
server->xwayland.xcursor_manager, "left_ptr", 1);
|
2018-03-31 06:13:26 +02:00
|
|
|
if (xcursor != NULL) {
|
|
|
|
struct wlr_xcursor_image *image = xcursor->images[0];
|
2018-06-18 23:49:28 +02:00
|
|
|
wlr_xwayland_set_cursor(server->xwayland.wlr_xwayland, image->buffer,
|
2018-03-31 06:13:26 +02:00
|
|
|
image->width * 4, image->width, image->height, image->hotspot_x,
|
|
|
|
image->hotspot_y);
|
|
|
|
}
|
2018-07-24 23:37:41 +02:00
|
|
|
#endif
|
2018-03-31 06:13:26 +02:00
|
|
|
|
2018-07-13 22:53:56 +02:00
|
|
|
server->server_decoration_manager =
|
2018-04-07 19:21:07 +02:00
|
|
|
wlr_server_decoration_manager_create(server->wl_display);
|
|
|
|
wlr_server_decoration_manager_set_default_mode(
|
2018-07-13 22:53:56 +02:00
|
|
|
server->server_decoration_manager,
|
|
|
|
WLR_SERVER_DECORATION_MANAGER_MODE_SERVER);
|
|
|
|
wl_signal_add(&server->server_decoration_manager->events.new_decoration,
|
|
|
|
&server->server_decoration);
|
|
|
|
server->server_decoration.notify = handle_server_decoration;
|
2018-07-29 19:31:10 +02:00
|
|
|
wl_list_init(&server->decorations);
|
2018-04-07 19:21:07 +02:00
|
|
|
|
2018-06-22 14:44:16 +02:00
|
|
|
wlr_export_dmabuf_manager_v1_create(server->wl_display);
|
2018-07-01 23:55:25 +02:00
|
|
|
wlr_screencopy_manager_v1_create(server->wl_display);
|
2017-12-03 20:21:26 +01:00
|
|
|
|
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) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_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
|
|
|
|
2018-08-18 08:58:50 +02:00
|
|
|
// This may have been set already via -Dtxn-timeout
|
|
|
|
if (!server->txn_timeout_ms) {
|
|
|
|
server->txn_timeout_ms = 200;
|
2018-06-25 01:09:43 +02:00
|
|
|
}
|
2018-08-18 08:58:50 +02:00
|
|
|
|
2018-07-14 15:14:55 +02:00
|
|
|
server->dirty_containers = create_list();
|
2018-06-27 11:07:48 +02:00
|
|
|
server->transactions = create_list();
|
|
|
|
|
2018-04-02 14:49:38 +02:00
|
|
|
input_manager = input_manager_create(server);
|
2017-10-22 16:37:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void server_fini(struct sway_server *server) {
|
2018-04-18 00:15:11 +02:00
|
|
|
// TODO: free sway-specific resources
|
2018-08-30 10:05:04 +02:00
|
|
|
#ifdef HAVE_XWAYLAND
|
|
|
|
wlr_xwayland_destroy(server->xwayland.wlr_xwayland);
|
|
|
|
#endif
|
|
|
|
wl_display_destroy_clients(server->wl_display);
|
2018-04-18 00:15:11 +02:00
|
|
|
wl_display_destroy(server->wl_display);
|
2018-07-14 15:14:55 +02:00
|
|
|
list_free(server->dirty_containers);
|
2018-06-27 11:07:48 +02:00
|
|
|
list_free(server->transactions);
|
2017-10-22 16:37:30 +02:00
|
|
|
}
|
2017-11-11 17:58:43 +01:00
|
|
|
|
2018-07-19 07:39:58 +02:00
|
|
|
bool server_start_backend(struct sway_server *server) {
|
|
|
|
wlr_log(WLR_INFO, "Starting backend on wayland display '%s'",
|
2017-11-11 17:58:43 +01:00
|
|
|
server->socket);
|
2017-12-31 22:32:28 +01:00
|
|
|
if (!wlr_backend_start(server->backend)) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_ERROR, "Failed to start backend");
|
2017-11-11 17:58:43 +01:00
|
|
|
wlr_backend_destroy(server->backend);
|
2018-07-19 07:39:58 +02:00
|
|
|
return false;
|
2017-11-11 17:58:43 +01:00
|
|
|
}
|
2018-07-19 07:39:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void server_run(struct sway_server *server) {
|
|
|
|
wlr_log(WLR_INFO, "Running compositor on wayland display '%s'",
|
|
|
|
server->socket);
|
2017-11-11 17:58:43 +01:00
|
|
|
wl_display_run(server->wl_display);
|
|
|
|
}
|