kiwmi/kiwmi/server.c

83 lines
2.3 KiB
C
Raw Normal View History

2019-02-17 13:23:20 +01:00
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
2019-10-16 18:59:29 +02:00
#include "server.h"
2019-02-17 13:19:28 +01:00
#include <stdlib.h>
#include <wayland-server.h>
#include <wlr/backend.h>
2019-03-21 22:12:54 +01:00
#include <wlr/render/wlr_renderer.h>
2019-02-17 13:19:28 +01:00
#include <wlr/util/log.h>
bool
2019-10-16 18:59:29 +02:00
server_init(struct kiwmi_server *server, const char *UNUSED(config_path))
2019-02-17 13:19:28 +01:00
{
wlr_log(WLR_DEBUG, "Initializing Wayland server");
2019-04-15 11:37:37 +02:00
server->wl_display = wl_display_create();
2019-04-08 18:10:37 +02:00
server->wl_event_loop = wl_display_get_event_loop(server->wl_display);
2019-04-15 11:37:37 +02:00
server->backend = wlr_backend_autocreate(server->wl_display, NULL);
2019-02-17 13:19:28 +01:00
if (!server->backend) {
wlr_log(WLR_ERROR, "Failed to create backend");
2019-02-18 12:37:23 +01:00
wl_display_destroy(server->wl_display);
2019-02-17 13:19:28 +01:00
return false;
}
struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend);
wlr_renderer_init_wl_display(renderer, server->wl_display);
2019-03-17 20:04:52 +01:00
if (!desktop_init(&server->desktop, renderer)) {
wlr_log(WLR_ERROR, "Failed to initialize desktop");
2019-03-07 19:25:38 +01:00
wl_display_destroy(server->wl_display);
return false;
}
2019-03-17 20:17:41 +01:00
if (!input_init(&server->input)) {
wlr_log(WLR_ERROR, "Failed to initialize input");
wl_display_destroy(server->wl_display);
return false;
}
2019-03-07 23:36:45 +01:00
2019-04-08 18:10:37 +02:00
server->socket = wl_display_add_socket_auto(server->wl_display);
if (!server->socket) {
wlr_log(WLR_ERROR, "Failed to open Wayland socket");
wl_display_destroy(server->wl_display);
return false;
}
2019-02-18 12:37:23 +01:00
return true;
}
bool
server_run(struct kiwmi_server *server)
{
wlr_log(
WLR_DEBUG, "Running Wayland server on display '%s'", server->socket);
2019-02-17 13:19:28 +01:00
if (!wlr_backend_start(server->backend)) {
wlr_log(WLR_ERROR, "Failed to start backend");
wl_display_destroy(server->wl_display);
return false;
}
setenv("WAYLAND_DISPLAY", server->socket, true);
wl_display_run(server->wl_display);
2019-02-18 12:37:23 +01:00
return true;
2019-02-17 13:19:28 +01:00
}
void
server_fini(struct kiwmi_server *server)
{
wlr_log(WLR_DEBUG, "Shutting down Wayland server");
wl_display_destroy_clients(server->wl_display);
wl_display_destroy(server->wl_display);
}