~ruther/dwl

c82c000bd413579237f5292d8076f045726efe15 — Devin J. Pohly 5 years ago 251d15c
treat startup command as long-running

Not quite a perfect mirror of xinit, where the startup command execs the
window manager, and the termination of that process brings down the
windowing system, but it might be the Wayland analogue.
1 files changed, 18 insertions(+), 1 deletions(-)

M dwl.c
M dwl.c => dwl.c +18 -1
@@ 8,6 8,8 @@
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <sys/signal.h>
#include <sys/wait.h>
#include <linux/input-event-codes.h>
#include <wayland-server-core.h>
#include <wlr/backend.h>


@@ 865,6 867,7 @@ static void server_new_xdg_surface(struct wl_listener *listener, void *data) {
int main(int argc, char *argv[]) {
	wlr_log_init(WLR_DEBUG, NULL);
	char *startup_cmd = NULL;
	pid_t startup_pid = -1;

	int c;
	while ((c = getopt(argc, argv, "s:h")) != -1) {


@@ 1002,8 1005,17 @@ int main(int argc, char *argv[]) {
	 * startup command if requested. */
	setenv("WAYLAND_DISPLAY", socket, true);
	if (startup_cmd) {
		if (fork() == 0) {
		startup_pid = fork();
		if (startup_pid < 0) {
			perror("startup: fork");
			wl_display_destroy(server.wl_display);
			return 1;
		}
		if (startup_pid == 0) {
			execl("/bin/sh", "/bin/sh", "-c", startup_cmd, (void *)NULL);
			perror("startup: execl");
			wl_display_destroy(server.wl_display);
			return 1;
		}
	}
	/* Run the Wayland event loop. This does not return until you exit the


@@ 1014,6 1026,11 @@ int main(int argc, char *argv[]) {
			socket);
	wl_display_run(server.wl_display);

	if (startup_cmd) {
		kill(startup_pid, SIGTERM);
		waitpid(startup_pid, NULL, 0);
	}

	/* Once wl_display_run returns, we shut down the server. */
	wl_display_destroy_clients(server.wl_display);
	wl_display_destroy(server.wl_display);

Do not follow this link