Add -S|--session <command> option

...to start <command> on startup and to terminate the compositor when
<command> exits.

This is useful for session management as it allows the session client (for
example `lxqt-session`) to terminate labwc - be exiting itself.

Under X, xinit starts the server and keeps it alive for as long as
lxqt-session runs. Thus either the session client starts the Window
Manager, or the Window Manager can be launched independently first.  On
Wayland, the Compositor is both Display Server and Window Manager, so the
described session management mechanisms do not work because the Compositor
needs to be running before the session can function.

As some session clients support both X11 and Wayland, this command line
option avoids re-writes and fragmentation.

Co-authored-by: @Consolatis
This commit is contained in:
Johan Malm 2024-03-09 17:12:54 +00:00 committed by Consolatis
parent 55138dbe0e
commit c841a25acf
6 changed files with 95 additions and 5 deletions

View file

@ -24,6 +24,7 @@ static const struct option long_options[] = {
{"merge-config", no_argument, NULL, 'm'},
{"reconfigure", no_argument, NULL, 'r'},
{"startup", required_argument, NULL, 's'},
{"session", required_argument, NULL, 'S'},
{"version", no_argument, NULL, 'v'},
{"verbose", no_argument, NULL, 'V'},
{0, 0, 0, 0}
@ -39,6 +40,7 @@ static const char labwc_usage[] =
" -m, --merge-config Merge user config files/theme in all XDG Base Dirs\n"
" -r, --reconfigure Reload the compositor configuration\n"
" -s, --startup <command> Run command on startup\n"
" -S, --session <command> Run command on startup and terminate on exit\n"
" -v, --version Show version number and quit\n"
" -V, --verbose Enable more verbose logging\n";
@ -87,12 +89,13 @@ main(int argc, char *argv[])
textdomain(GETTEXT_PACKAGE);
#endif
char *startup_cmd = NULL;
char *primary_client = NULL;
enum wlr_log_importance verbosity = WLR_ERROR;
int c;
while (1) {
int index = 0;
c = getopt_long(argc, argv, "c:C:dehmrs:vV", long_options, &index);
c = getopt_long(argc, argv, "c:C:dehmrs:S:vV", long_options, &index);
if (c == -1) {
break;
}
@ -118,6 +121,9 @@ main(int argc, char *argv[])
case 's':
startup_cmd = optarg;
break;
case 'S':
primary_client = optarg;
break;
case 'v':
printf("labwc " LABWC_VERSION "\n");
exit(0);
@ -171,6 +177,16 @@ main(int argc, char *argv[])
menu_init(&server);
/* Start session-manager if one is specified by -S|--session */
if (primary_client) {
server.primary_client_pid = spawn_primary_client(primary_client);
if (server.primary_client_pid < 0) {
wlr_log(WLR_ERROR, "fatal error starting primary client: %s",
primary_client);
goto out;
}
}
session_autostart_init(&server);
if (startup_cmd) {
spawn_async_no_shell(startup_cmd);
@ -178,6 +194,7 @@ main(int argc, char *argv[])
wl_display_run(server.wl_display);
out:
session_shutdown(&server);
server_finish(&server);