From ab565e2c8722ae5ee6d7746ea1630da9f42bbff2 Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Tue, 26 Mar 2019 21:45:00 +0100 Subject: [PATCH] Spawning a frontend --- include/kiwmi/frontend.h | 19 ++++++++++++++++ include/kiwmi/server.h | 6 ++++- kiwmi/frontend.c | 47 ++++++++++++++++++++++++++++++++++++++++ kiwmi/main.c | 2 +- kiwmi/meson.build | 1 + kiwmi/server.c | 8 ++++++- 6 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 include/kiwmi/frontend.h create mode 100644 kiwmi/frontend.c diff --git a/include/kiwmi/frontend.h b/include/kiwmi/frontend.h new file mode 100644 index 0000000..3772ca6 --- /dev/null +++ b/include/kiwmi/frontend.h @@ -0,0 +1,19 @@ +/* Copyright (c), Charlotte Meyer + * + * 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/. + */ + +#ifndef KIWMI_FRONTEND_H +#define KIWMI_FRONTEND_H + +#include + +struct kiwmi_frontend { + const char *frontend_path; +}; + +bool frontend_init(struct kiwmi_frontend *frontend, const char *frontend_path); + +#endif /* KIWMI_FRONTEND_H */ diff --git a/include/kiwmi/server.h b/include/kiwmi/server.h index 23ff90c..42f772c 100644 --- a/include/kiwmi/server.h +++ b/include/kiwmi/server.h @@ -8,7 +8,10 @@ #ifndef KIWMI_SERVER_H #define KIWMI_SERVER_H +#include + #include "kiwmi/desktop/desktop.h" +#include "kiwmi/frontend.h" #include "kiwmi/input/input.h" struct kiwmi_server { @@ -17,9 +20,10 @@ struct kiwmi_server { const char *socket; struct kiwmi_desktop desktop; struct kiwmi_input input; + struct kiwmi_frontend frontend; }; -bool server_init(struct kiwmi_server *server); +bool server_init(struct kiwmi_server *server, const char *frontend_path); bool server_run(struct kiwmi_server *server); void server_fini(struct kiwmi_server *server); diff --git a/kiwmi/frontend.c b/kiwmi/frontend.c new file mode 100644 index 0000000..bc082e5 --- /dev/null +++ b/kiwmi/frontend.c @@ -0,0 +1,47 @@ +/* Copyright (c), Charlotte Meyer + * + * 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/. + */ + +#include "kiwmi/frontend.h" + +#include +#include + +#include + +#include + +static bool +spawn_frontend(const char *path) +{ + pid_t pid = fork(); + + if (pid < 0) { + wlr_log(WLR_ERROR, "Failed to start frontend (fork)"); + return false; + } + + if (pid == 0) { + execlp(path, path, NULL); + wlr_log(WLR_ERROR, "Failed to start frontend (exec), continuing"); + _exit(EXIT_FAILURE); + } + + return true; +} + +bool +frontend_init(struct kiwmi_frontend *frontend, const char *frontend_path) +{ + frontend->frontend_path = frontend_path; + + if (strcmp(frontend_path, "NONE") == 0) { + wlr_log(WLR_ERROR, "Launching without a frontend"); + return true; + } else { + return spawn_frontend(frontend_path); + } +} diff --git a/kiwmi/main.c b/kiwmi/main.c index e4e5fac..d5076de 100644 --- a/kiwmi/main.c +++ b/kiwmi/main.c @@ -72,7 +72,7 @@ main(int argc, char **argv) struct kiwmi_server server; - if (!server_init(&server)) { + if (!server_init(&server, frontend_path)) { wlr_log(WLR_ERROR, "Failed to initialize server"); exit(EXIT_FAILURE); } diff --git a/kiwmi/meson.build b/kiwmi/meson.build index 489b970..3a8feeb 100644 --- a/kiwmi/meson.build +++ b/kiwmi/meson.build @@ -1,5 +1,6 @@ kiwmi_sources = files( 'main.c', + 'frontend.c', 'server.c', 'desktop/desktop.c', 'desktop/output.c', diff --git a/kiwmi/server.c b/kiwmi/server.c index 9eace5a..98d1248 100644 --- a/kiwmi/server.c +++ b/kiwmi/server.c @@ -15,7 +15,7 @@ #include bool -server_init(struct kiwmi_server *server) +server_init(struct kiwmi_server *server, const char *frontend_path) { wlr_log(WLR_DEBUG, "Initializing Wayland server"); @@ -42,6 +42,12 @@ server_init(struct kiwmi_server *server) return false; } + if (!frontend_init(&server->frontend, frontend_path)) { + wlr_log(WLR_ERROR, "Failed to initialize frontend"); + wl_display_destroy(server->wl_display); + return false; + } + return true; }