Spawning a frontend
This commit is contained in:
parent
d5312fe4dd
commit
4f703cba94
6 changed files with 80 additions and 3 deletions
19
include/kiwmi/frontend.h
Normal file
19
include/kiwmi/frontend.h
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/* Copyright (c), Niclas Meyer <niclas@countingsort.com>
|
||||||
|
*
|
||||||
|
* 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 <stdbool.h>
|
||||||
|
|
||||||
|
struct kiwmi_frontend {
|
||||||
|
const char *frontend_path;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool frontend_init(struct kiwmi_frontend *frontend, const char *frontend_path);
|
||||||
|
|
||||||
|
#endif /* KIWMI_FRONTEND_H */
|
|
@ -8,7 +8,10 @@
|
||||||
#ifndef KIWMI_SERVER_H
|
#ifndef KIWMI_SERVER_H
|
||||||
#define KIWMI_SERVER_H
|
#define KIWMI_SERVER_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "kiwmi/desktop/desktop.h"
|
#include "kiwmi/desktop/desktop.h"
|
||||||
|
#include "kiwmi/frontend.h"
|
||||||
#include "kiwmi/input/input.h"
|
#include "kiwmi/input/input.h"
|
||||||
|
|
||||||
struct kiwmi_server {
|
struct kiwmi_server {
|
||||||
|
@ -17,9 +20,10 @@ struct kiwmi_server {
|
||||||
const char *socket;
|
const char *socket;
|
||||||
struct kiwmi_desktop desktop;
|
struct kiwmi_desktop desktop;
|
||||||
struct kiwmi_input input;
|
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);
|
bool server_run(struct kiwmi_server *server);
|
||||||
void server_fini(struct kiwmi_server *server);
|
void server_fini(struct kiwmi_server *server);
|
||||||
|
|
||||||
|
|
47
kiwmi/frontend.c
Normal file
47
kiwmi/frontend.c
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/* Copyright (c), Niclas Meyer <niclas@countingsort.com>
|
||||||
|
*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,7 +72,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
struct kiwmi_server server;
|
struct kiwmi_server server;
|
||||||
|
|
||||||
if (!server_init(&server)) {
|
if (!server_init(&server, frontend_path)) {
|
||||||
wlr_log(WLR_ERROR, "Failed to initialize server");
|
wlr_log(WLR_ERROR, "Failed to initialize server");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
kiwmi_sources = files(
|
kiwmi_sources = files(
|
||||||
'main.c',
|
'main.c',
|
||||||
|
'frontend.c',
|
||||||
'server.c',
|
'server.c',
|
||||||
'desktop/desktop.c',
|
'desktop/desktop.c',
|
||||||
'desktop/output.c',
|
'desktop/output.c',
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
bool
|
bool
|
||||||
server_init(struct kiwmi_server *server)
|
server_init(struct kiwmi_server *server, const char *frontend_path)
|
||||||
{
|
{
|
||||||
wlr_log(WLR_DEBUG, "Initializing Wayland server");
|
wlr_log(WLR_DEBUG, "Initializing Wayland server");
|
||||||
|
|
||||||
|
@ -42,6 +42,12 @@ server_init(struct kiwmi_server *server)
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue