labwc/src/main.c

100 lines
1.7 KiB
C
Raw Normal View History

#include "common/font.h"
2020-11-01 22:22:15 +00:00
#include "common/log.h"
#include "common/spawn.h"
#include "config/session.h"
2019-11-19 21:00:26 +00:00
#include "labwc.h"
2020-08-03 20:56:38 +01:00
#include "theme/theme.h"
2020-08-31 20:01:08 +01:00
#include "xbm/xbm.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 };
2020-06-11 21:20:43 +01:00
struct theme theme = { 0 };
2019-12-16 21:19:50 +00:00
2020-07-16 20:16:43 +01:00
static const char labwc_usage[] =
2020-10-23 20:08:56 +01:00
"Usage: labwc [-h] [-s <startup-command>] [-c <config-file>] [-v]\n";
2020-07-16 20:16:43 +01:00
static void
usage(void)
2020-07-16 20:16:43 +01:00
{
printf("%s", labwc_usage);
exit(0);
}
int
main(int argc, char *argv[])
2019-12-27 21:22:45 +00:00
{
2019-05-11 21:26:59 +01:00
char *startup_cmd = NULL;
2020-07-18 11:28:39 +01:00
char *config_file = NULL;
2020-10-23 20:08:56 +01:00
enum verbosity {
LAB_VERBOSITY_ERROR = 0,
LAB_VERBOSITY_INFO,
LAB_VERBOSITY_DEBUG,
} verbosity = LAB_VERBOSITY_ERROR;
2020-05-11 06:59:27 +01:00
2019-05-11 21:26:59 +01:00
int c;
2020-10-23 20:08:56 +01:00
while ((c = getopt(argc, argv, "c:s:hv")) != -1) {
2019-05-11 21:26:59 +01:00
switch (c) {
2020-07-18 11:28:39 +01:00
case 'c':
config_file = optarg;
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':
++verbosity;
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
}
}
if (optind < argc) {
2020-07-16 20:16:43 +01:00
usage();
}
2019-05-11 21:26:59 +01:00
2020-10-23 20:08:56 +01:00
switch (verbosity) {
case LAB_VERBOSITY_ERROR:
wlr_log_init(WLR_ERROR, NULL);
break;
case LAB_VERBOSITY_INFO:
wlr_log_init(WLR_INFO, NULL);
break;
case LAB_VERBOSITY_DEBUG:
default:
wlr_log_init(WLR_DEBUG, NULL);
break;
}
session_environment_init();
2020-07-18 11:28:39 +01:00
rcxml_read(config_file);
2020-06-05 23:04:54 +01:00
2020-05-11 06:59:27 +01:00
if (!getenv("XDG_RUNTIME_DIR")) {
2020-11-01 22:22:15 +00:00
die("XDG_RUNTIME_DIR is unset");
2020-05-11 06:59:27 +01:00
}
struct server server = { 0 };
server_init(&server);
server_start(&server);
2020-05-11 06:59:27 +01:00
2021-02-21 21:54:40 +00:00
theme_init(&theme, server.renderer, rc.theme_name);
server.theme = &theme;
2020-06-29 19:27:59 +01:00
2020-10-22 19:43:27 +01:00
struct menu rootmenu = { 0 };
2021-02-19 23:05:14 +00:00
menu_init_rootmenu(&server, &rootmenu);
2020-10-19 22:14:17 +01:00
session_autostart_init();
if (startup_cmd) {
2020-06-19 22:29:54 +01:00
spawn_async_no_shell(startup_cmd);
}
2020-07-16 20:16:43 +01:00
2019-05-11 21:26:59 +01:00
wl_display_run(server.wl_display);
server_finish(&server);
2021-02-21 22:03:14 +00:00
menu_finish(&rootmenu);
theme_finish(&theme);
2020-08-13 20:18:48 +01:00
rcxml_finish();
font_finish();
2019-05-11 21:26:59 +01:00
return 0;
}