2017-09-23 06:29:53 +02:00
|
|
|
#define _POSIX_C_SOURCE 200112L
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
2017-10-20 17:49:04 +02:00
|
|
|
#include <unistd.h>
|
2017-09-23 02:24:32 +02:00
|
|
|
#include <wayland-server.h>
|
2017-12-27 14:37:55 +01:00
|
|
|
#include <wlr/config.h>
|
2017-09-23 06:29:53 +02:00
|
|
|
#include <wlr/backend.h>
|
2017-12-17 12:56:42 +01:00
|
|
|
#include <wlr/backend/headless.h>
|
2017-12-20 11:51:23 +01:00
|
|
|
#include <wlr/backend/multi.h>
|
2017-09-23 06:29:53 +02:00
|
|
|
#include <wlr/render.h>
|
2017-09-23 02:24:32 +02:00
|
|
|
#include <wlr/util/log.h>
|
|
|
|
#include "rootston/config.h"
|
|
|
|
#include "rootston/server.h"
|
|
|
|
|
2017-09-23 06:29:53 +02:00
|
|
|
struct roots_server server = { 0 };
|
2017-09-23 02:24:32 +02:00
|
|
|
|
2017-11-12 22:01:31 +01:00
|
|
|
static void ready(struct wl_listener *listener, void *data) {
|
|
|
|
if (server.config->startup_cmd != NULL) {
|
|
|
|
const char *cmd = server.config->startup_cmd;
|
|
|
|
pid_t pid = fork();
|
|
|
|
if (pid < 0) {
|
|
|
|
wlr_log(L_ERROR, "cannot execute binding command: fork() failed");
|
|
|
|
} else if (pid == 0) {
|
|
|
|
execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-23 02:24:32 +02:00
|
|
|
int main(int argc, char **argv) {
|
2017-12-31 22:29:05 +01:00
|
|
|
wlr_log_init(L_DEBUG, NULL);
|
2017-11-11 16:59:04 +01:00
|
|
|
assert(server.config = roots_config_create_from_args(argc, argv));
|
2017-09-23 06:29:53 +02:00
|
|
|
assert(server.wl_display = wl_display_create());
|
|
|
|
assert(server.wl_event_loop = wl_display_get_event_loop(server.wl_display));
|
|
|
|
|
2017-12-22 00:27:38 +01:00
|
|
|
server.backend = wlr_backend_autocreate(server.wl_display);
|
|
|
|
if (server.backend == NULL) {
|
2017-12-20 11:51:23 +01:00
|
|
|
wlr_log(L_ERROR, "could not start backend");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-01-23 22:06:54 +01:00
|
|
|
assert(server.renderer = wlr_backend_get_renderer(server.backend));
|
2017-10-15 17:06:03 +02:00
|
|
|
server.data_device_manager =
|
|
|
|
wlr_data_device_manager_create(server.wl_display);
|
2017-09-23 06:29:53 +02:00
|
|
|
wl_display_init_shm(server.wl_display);
|
|
|
|
server.desktop = desktop_create(&server, server.config);
|
2017-09-30 14:46:18 +02:00
|
|
|
server.input = input_create(&server, server.config);
|
2017-09-23 06:29:53 +02:00
|
|
|
|
|
|
|
const char *socket = wl_display_add_socket_auto(server.wl_display);
|
|
|
|
if (!socket) {
|
|
|
|
wlr_log_errno(L_ERROR, "Unable to open wayland socket");
|
|
|
|
wlr_backend_destroy(server.backend);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_log(L_INFO, "Running compositor on wayland display '%s'", socket);
|
|
|
|
setenv("_WAYLAND_DISPLAY", socket, true);
|
|
|
|
|
|
|
|
if (!wlr_backend_start(server.backend)) {
|
|
|
|
wlr_log(L_ERROR, "Failed to start backend");
|
|
|
|
wlr_backend_destroy(server.backend);
|
2017-12-07 00:13:06 +01:00
|
|
|
wl_display_destroy(server.wl_display);
|
2017-09-23 06:29:53 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-10-03 16:35:54 +02:00
|
|
|
setenv("WAYLAND_DISPLAY", socket, true);
|
2017-12-26 18:51:27 +01:00
|
|
|
#ifndef WLR_HAS_XWAYLAND
|
2017-11-12 22:01:31 +01:00
|
|
|
ready(NULL, NULL);
|
|
|
|
#else
|
2017-11-17 15:28:22 +01:00
|
|
|
if (server.desktop->xwayland != NULL) {
|
2017-11-22 14:23:23 +01: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-19 16:07:30 +01:00
|
|
|
wl_signal_add(&server.desktop->xwayland->events.ready,
|
|
|
|
&server.desktop->xwayland_ready);
|
|
|
|
server.desktop->xwayland_ready.notify = ready;
|
2017-11-17 15:28:22 +01:00
|
|
|
} else {
|
|
|
|
ready(NULL, NULL);
|
|
|
|
}
|
2017-11-12 22:01:31 +01:00
|
|
|
#endif
|
2017-10-20 17:49:04 +02:00
|
|
|
|
2017-09-23 06:29:53 +02:00
|
|
|
wl_display_run(server.wl_display);
|
2017-12-07 00:13:06 +01:00
|
|
|
wl_display_destroy(server.wl_display);
|
2017-09-23 02:24:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|