mirror of
https://codeberg.org/dwl/dwl.git
synced 2024-12-27 03:36:31 +00:00
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.
This commit is contained in:
parent
251d15c1fd
commit
c82c000bd4
1 changed files with 18 additions and 1 deletions
19
dwl.c
19
dwl.c
|
@ -8,6 +8,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/signal.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <linux/input-event-codes.h>
|
#include <linux/input-event-codes.h>
|
||||||
#include <wayland-server-core.h>
|
#include <wayland-server-core.h>
|
||||||
#include <wlr/backend.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[]) {
|
int main(int argc, char *argv[]) {
|
||||||
wlr_log_init(WLR_DEBUG, NULL);
|
wlr_log_init(WLR_DEBUG, NULL);
|
||||||
char *startup_cmd = NULL;
|
char *startup_cmd = NULL;
|
||||||
|
pid_t startup_pid = -1;
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while ((c = getopt(argc, argv, "s:h")) != -1) {
|
while ((c = getopt(argc, argv, "s:h")) != -1) {
|
||||||
|
@ -1002,8 +1005,17 @@ int main(int argc, char *argv[]) {
|
||||||
* startup command if requested. */
|
* startup command if requested. */
|
||||||
setenv("WAYLAND_DISPLAY", socket, true);
|
setenv("WAYLAND_DISPLAY", socket, true);
|
||||||
if (startup_cmd) {
|
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);
|
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
|
/* Run the Wayland event loop. This does not return until you exit the
|
||||||
|
@ -1014,6 +1026,11 @@ int main(int argc, char *argv[]) {
|
||||||
socket);
|
socket);
|
||||||
wl_display_run(server.wl_display);
|
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. */
|
/* Once wl_display_run returns, we shut down the server. */
|
||||||
wl_display_destroy_clients(server.wl_display);
|
wl_display_destroy_clients(server.wl_display);
|
||||||
wl_display_destroy(server.wl_display);
|
wl_display_destroy(server.wl_display);
|
||||||
|
|
Loading…
Reference in a new issue