2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2022-04-22 17:00:36 +01:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
|
#include <string.h>
|
2022-10-04 21:48:57 +01:00
|
|
|
#include <unistd.h>
|
2022-04-22 17:00:36 +01:00
|
|
|
#include "common/dir.h"
|
2022-09-16 18:41:02 -04:00
|
|
|
#include "common/fd_util.h"
|
2020-10-31 15:41:06 +00:00
|
|
|
#include "common/font.h"
|
2022-09-16 18:41:02 -04:00
|
|
|
#include "common/mem.h"
|
2020-11-01 22:22:15 +00:00
|
|
|
#include "common/spawn.h"
|
2020-10-08 20:50:20 +01:00
|
|
|
#include "config/session.h"
|
2019-11-19 21:00:26 +00:00
|
|
|
#include "labwc.h"
|
2021-02-21 22:18:34 +00:00
|
|
|
#include "theme.h"
|
2020-10-19 22:14:17 +01:00
|
|
|
#include "menu/menu.h"
|
2019-05-11 21:26:59 +01:00
|
|
|
|
2020-06-05 23:04:54 +01:00
|
|
|
struct rcxml rc = { 0 };
|
2019-12-16 21:19:50 +00:00
|
|
|
|
2022-10-06 21:54:26 +01:00
|
|
|
static const struct option long_options[] = {
|
|
|
|
|
{"config", required_argument, NULL, 'c'},
|
|
|
|
|
{"config-dir", required_argument, NULL, 'C'},
|
|
|
|
|
{"debug", no_argument, NULL, 'd'},
|
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
|
{"startup", required_argument, NULL, 's'},
|
|
|
|
|
{"version", no_argument, NULL, 'v'},
|
|
|
|
|
{"verbose", no_argument, NULL, 'V'},
|
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-16 20:16:43 +01:00
|
|
|
static const char labwc_usage[] =
|
2022-04-22 17:00:36 +01:00
|
|
|
"Usage: labwc [options...]\n"
|
2022-10-06 21:54:26 +01:00
|
|
|
" -c, --config <file> Specify config file (with path)\n"
|
|
|
|
|
" -C, --config-dir <dir> Specify config directory\n"
|
|
|
|
|
" -d, --debug Enable full logging, including debug information\n"
|
|
|
|
|
" -h, --help Show help message and quit\n"
|
|
|
|
|
" -s, --startup <command> Run command on startup\n"
|
|
|
|
|
" -v, --version Show version number and quit\n"
|
|
|
|
|
" -V, --verbose Enable more verbose logging\n";
|
2020-07-16 20:16:43 +01:00
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
usage(void)
|
2020-07-16 20:16:43 +01:00
|
|
|
{
|
|
|
|
|
printf("%s", labwc_usage);
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
int
|
|
|
|
|
main(int argc, char *argv[])
|
2019-12-27 21:22:45 +00:00
|
|
|
{
|
2022-05-01 14:38:45 +10:00
|
|
|
#if HAVE_NLS
|
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
|
|
|
|
|
textdomain(GETTEXT_PACKAGE);
|
|
|
|
|
#endif
|
2019-05-11 21:26:59 +01:00
|
|
|
char *startup_cmd = NULL;
|
2020-07-18 11:28:39 +01:00
|
|
|
char *config_file = NULL;
|
2021-03-06 11:38:17 +00:00
|
|
|
enum wlr_log_importance verbosity = WLR_ERROR;
|
2020-05-11 06:59:27 +01:00
|
|
|
|
2019-05-11 21:26:59 +01:00
|
|
|
int c;
|
2022-10-06 21:54:26 +01:00
|
|
|
while (1) {
|
|
|
|
|
int index = 0;
|
|
|
|
|
c = getopt_long(argc, argv, "c:C:dhs:vV", long_options, &index);
|
|
|
|
|
if (c == -1) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 21:26:59 +01:00
|
|
|
switch (c) {
|
2020-07-18 11:28:39 +01:00
|
|
|
case 'c':
|
|
|
|
|
config_file = optarg;
|
|
|
|
|
break;
|
2022-04-22 17:00:36 +01:00
|
|
|
case 'C':
|
2022-09-16 18:41:02 -04:00
|
|
|
rc.config_dir = xstrdup(optarg);
|
2022-04-22 17:00:36 +01:00
|
|
|
break;
|
2021-03-06 11:38:17 +00:00
|
|
|
case 'd':
|
|
|
|
|
verbosity = WLR_DEBUG;
|
|
|
|
|
break;
|
2020-09-25 19:42:40 +01:00
|
|
|
case 's':
|
|
|
|
|
startup_cmd = optarg;
|
|
|
|
|
break;
|
2020-10-23 20:08:56 +01:00
|
|
|
case 'v':
|
2021-03-06 11:38:17 +00:00
|
|
|
printf("labwc " LABWC_VERSION "\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
case 'V':
|
|
|
|
|
verbosity = WLR_INFO;
|
2020-10-23 20:08:56 +01:00
|
|
|
break;
|
2020-09-25 19:42:40 +01:00
|
|
|
case 'h':
|
2019-05-11 21:26:59 +01:00
|
|
|
default:
|
2020-07-16 20:16:43 +01:00
|
|
|
usage();
|
2019-05-11 21:26:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-28 20:41:41 +01:00
|
|
|
if (optind < argc) {
|
2020-07-16 20:16:43 +01:00
|
|
|
usage();
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2019-05-11 21:26:59 +01:00
|
|
|
|
2021-03-06 11:38:17 +00:00
|
|
|
wlr_log_init(verbosity, NULL);
|
2020-10-08 20:50:20 +01:00
|
|
|
|
2022-04-22 17:00:36 +01:00
|
|
|
if (!rc.config_dir) {
|
|
|
|
|
rc.config_dir = config_dir();
|
|
|
|
|
}
|
|
|
|
|
wlr_log(WLR_INFO, "using config dir (%s)\n", rc.config_dir);
|
|
|
|
|
session_environment_init(rc.config_dir);
|
2020-07-18 11:28:39 +01:00
|
|
|
rcxml_read(config_file);
|
2020-06-05 23:04:54 +01:00
|
|
|
|
2022-10-04 21:48:57 +01:00
|
|
|
/*
|
|
|
|
|
* Set environment variable LABWC_PID to the pid of the compositor
|
|
|
|
|
* so that SIGHUP and SIGTERM can be sent to specific instances using
|
|
|
|
|
* `kill -s <signal> <pid>` rather than `killall -s <signal> labwc`
|
|
|
|
|
*/
|
|
|
|
|
char pid[32];
|
|
|
|
|
snprintf(pid, sizeof(pid), "%d", getpid());
|
|
|
|
|
if (setenv("LABWC_PID", pid, true) < 0) {
|
|
|
|
|
wlr_log_errno(WLR_ERROR, "unable to set LABWC_PID");
|
|
|
|
|
} else {
|
|
|
|
|
wlr_log(WLR_DEBUG, "LABWC_PID=%s", pid);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 06:59:27 +01:00
|
|
|
if (!getenv("XDG_RUNTIME_DIR")) {
|
2021-07-22 21:30:17 +01:00
|
|
|
wlr_log(WLR_ERROR, "XDG_RUNTIME_DIR is unset");
|
|
|
|
|
exit(EXIT_FAILURE);
|
2020-05-11 06:59:27 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-17 00:49:26 +00:00
|
|
|
increase_nofile_limit();
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
struct server server = { 0 };
|
2020-06-03 18:39:46 +01:00
|
|
|
server_init(&server);
|
|
|
|
|
server_start(&server);
|
2020-05-11 06:59:27 +01:00
|
|
|
|
2021-02-25 22:14:07 +00:00
|
|
|
struct theme theme = { 0 };
|
2022-02-17 01:46:32 +01:00
|
|
|
theme_init(&theme, rc.theme_name);
|
2022-03-09 05:40:54 +01:00
|
|
|
rc.theme = &theme;
|
2021-02-21 21:54:40 +00:00
|
|
|
server.theme = &theme;
|
2020-06-29 19:27:59 +01:00
|
|
|
|
2021-11-02 18:31:19 +00:00
|
|
|
menu_init_rootmenu(&server);
|
2022-01-26 00:07:10 +01:00
|
|
|
menu_init_windowmenu(&server);
|
2020-10-19 22:14:17 +01:00
|
|
|
|
2022-04-22 17:00:36 +01:00
|
|
|
session_autostart_init(rc.config_dir);
|
2020-09-28 20:41:41 +01:00
|
|
|
if (startup_cmd) {
|
2020-06-19 22:29:54 +01:00
|
|
|
spawn_async_no_shell(startup_cmd);
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-07-16 20:16:43 +01:00
|
|
|
|
2019-05-11 21:26:59 +01:00
|
|
|
wl_display_run(server.wl_display);
|
2020-09-28 20:41:41 +01:00
|
|
|
|
2020-06-03 18:39:46 +01:00
|
|
|
server_finish(&server);
|
2021-02-21 22:03:14 +00:00
|
|
|
|
2021-11-02 18:31:19 +00:00
|
|
|
menu_finish();
|
2021-02-21 22:03:14 +00:00
|
|
|
theme_finish(&theme);
|
2020-08-13 20:18:48 +01:00
|
|
|
rcxml_finish();
|
2020-10-31 15:41:06 +00:00
|
|
|
font_finish();
|
2019-05-11 21:26:59 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|