2017-09-23 04:29:53 +00:00
|
|
|
#define _POSIX_C_SOURCE 200112L
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
2017-10-20 15:49:04 +00:00
|
|
|
#include <unistd.h>
|
2019-07-27 08:53:54 +00:00
|
|
|
#include <wayland-server-core.h>
|
2017-09-23 04:29:53 +00:00
|
|
|
#include <wlr/backend.h>
|
2017-12-17 11:56:42 +00:00
|
|
|
#include <wlr/backend/headless.h>
|
2017-12-20 10:51:23 +00:00
|
|
|
#include <wlr/backend/multi.h>
|
2018-02-12 20:29:23 +00:00
|
|
|
#include <wlr/config.h>
|
2018-03-19 22:16:29 +00:00
|
|
|
#include <wlr/render/wlr_renderer.h>
|
2017-09-23 00:24:32 +00:00
|
|
|
#include <wlr/util/log.h>
|
|
|
|
#include "rootston/config.h"
|
|
|
|
#include "rootston/server.h"
|
|
|
|
|
2017-09-23 04:29:53 +00:00
|
|
|
struct roots_server server = { 0 };
|
2017-09-23 00:24:32 +00:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log_init(WLR_DEBUG, NULL);
|
2018-04-08 16:49:48 +00:00
|
|
|
server.config = roots_config_create_from_args(argc, argv);
|
|
|
|
server.wl_display = wl_display_create();
|
2018-04-08 16:50:52 +00:00
|
|
|
server.wl_event_loop = wl_display_get_event_loop(server.wl_display);
|
2018-04-08 16:49:48 +00:00
|
|
|
assert(server.config && server.wl_display && server.wl_event_loop);
|
2017-09-23 04:29:53 +00:00
|
|
|
|
2018-05-25 10:14:35 +00:00
|
|
|
server.backend = wlr_backend_autocreate(server.wl_display, NULL);
|
2017-12-21 23:27:38 +00:00
|
|
|
if (server.backend == NULL) {
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log(WLR_ERROR, "could not start backend");
|
2017-12-20 10:51:23 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-04-08 16:49:48 +00:00
|
|
|
server.renderer = wlr_backend_get_renderer(server.backend);
|
|
|
|
assert(server.renderer);
|
2017-10-15 15:06:03 +00:00
|
|
|
server.data_device_manager =
|
|
|
|
wlr_data_device_manager_create(server.wl_display);
|
2018-05-21 18:07:08 +00:00
|
|
|
wlr_renderer_init_wl_display(server.renderer, server.wl_display);
|
2017-09-23 04:29:53 +00:00
|
|
|
server.desktop = desktop_create(&server, server.config);
|
2017-09-30 12:46:18 +00:00
|
|
|
server.input = input_create(&server, server.config);
|
2017-09-23 04:29:53 +00:00
|
|
|
|
|
|
|
const char *socket = wl_display_add_socket_auto(server.wl_display);
|
|
|
|
if (!socket) {
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log_errno(WLR_ERROR, "Unable to open wayland socket");
|
2017-09-23 04:29:53 +00:00
|
|
|
wlr_backend_destroy(server.backend);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log(WLR_INFO, "Running compositor on wayland display '%s'", socket);
|
2017-09-23 04:29:53 +00:00
|
|
|
setenv("_WAYLAND_DISPLAY", socket, true);
|
|
|
|
|
|
|
|
if (!wlr_backend_start(server.backend)) {
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log(WLR_ERROR, "Failed to start backend");
|
2017-09-23 04:29:53 +00:00
|
|
|
wlr_backend_destroy(server.backend);
|
2017-12-06 23:13:06 +00:00
|
|
|
wl_display_destroy(server.wl_display);
|
2017-09-23 04:29:53 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-10-03 14:35:54 +00:00
|
|
|
setenv("WAYLAND_DISPLAY", socket, true);
|
2018-11-12 09:12:46 +00:00
|
|
|
#if WLR_HAS_XWAYLAND
|
2017-11-17 14:28:22 +00:00
|
|
|
if (server.desktop->xwayland != NULL) {
|
2017-11-22 13:23:23 +00:00
|
|
|
struct roots_seat *xwayland_seat =
|
|
|
|
input_get_seat(server.input, ROOTS_CONFIG_DEFAULT_SEAT_NAME);
|
|
|
|
wlr_xwayland_set_seat(server.desktop->xwayland, xwayland_seat->seat);
|
2017-11-17 14:28:22 +00:00
|
|
|
}
|
2017-11-12 21:01:31 +00:00
|
|
|
#endif
|
2017-10-20 15:49:04 +00:00
|
|
|
|
2018-05-06 20:51:32 +00:00
|
|
|
if (server.config->startup_cmd != NULL) {
|
|
|
|
const char *cmd = server.config->startup_cmd;
|
|
|
|
pid_t pid = fork();
|
|
|
|
if (pid < 0) {
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log(WLR_ERROR, "cannot execute binding command: fork() failed");
|
2018-05-06 20:51:32 +00:00
|
|
|
} else if (pid == 0) {
|
|
|
|
execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-23 04:29:53 +00:00
|
|
|
wl_display_run(server.wl_display);
|
2018-11-12 09:12:46 +00:00
|
|
|
#if WLR_HAS_XWAYLAND
|
2019-01-18 11:20:04 +00:00
|
|
|
// We need to shutdown Xwayland before disconnecting all clients, otherwise
|
|
|
|
// wlroots will restart it automatically.
|
2018-06-08 08:29:55 +00:00
|
|
|
wlr_xwayland_destroy(server.desktop->xwayland);
|
|
|
|
#endif
|
2018-05-29 21:50:26 +00:00
|
|
|
wl_display_destroy_clients(server.wl_display);
|
2017-12-06 23:13:06 +00:00
|
|
|
wl_display_destroy(server.wl_display);
|
2017-09-23 00:24:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|