aboutsummaryrefslogtreecommitdiff
path: root/rootston/main.c
blob: 5a60000cff5f9b139618db13add4f555e5e5aad6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#define _POSIX_C_SOURCE 200112L
#include <assert.h>
#include <stdlib.h>
#include <wayland-server.h>
#include <wlr/backend.h>
#include <wlr/render.h>
#include <wlr/render/gles2.h>
#include <wlr/util/log.h>
#include "rootston/config.h"
#include "rootston/server.h"

struct roots_server server = { 0 };

int main(int argc, char **argv) {
	assert(server.config = parse_args(argc, argv));
	assert(server.wl_display = wl_display_create());
	assert(server.wl_event_loop = wl_display_get_event_loop(server.wl_display));

	assert(server.backend = wlr_backend_autocreate(server.wl_display));

	assert(server.renderer = wlr_gles2_renderer_create(server.backend));
	wl_display_init_shm(server.wl_display);
	server.desktop = desktop_create(&server, server.config);
	server.input = input_create(&server, server.config);
	server.data_device_manager = wlr_data_device_manager_create(
			server.wl_display);

	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);
		return 1;
	}

	setenv("WAYLAND_DISPLAY", socket, true);
	wl_display_run(server.wl_display);
	wlr_backend_destroy(server.backend);
	return 0;
}