labwc/src/main.c

72 lines
1.2 KiB
C
Raw Normal View History

#include "common/spawn.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"
2019-05-11 21:26:59 +01:00
#include <cairo.h>
#include <pango/pangocairo.h>
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[] =
"Usage: labwc [-h] [-s <startup-command>] [-c <config-file>]\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-05-11 06:59:27 +01:00
2019-05-11 21:26:59 +01:00
int c;
2020-09-25 19:42:40 +01:00
while ((c = getopt(argc, argv, "c:s:h")) != -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;
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-09-25 19:42:40 +01:00
wlr_log_init(WLR_ERROR, NULL);
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")) {
wlr_log(WLR_ERROR, "XDG_RUNTIME_DIR is required to be set");
2020-05-11 06:59:27 +01:00
return 1;
}
struct server server = { 0 };
server_init(&server);
server_start(&server);
2020-05-11 06:59:27 +01:00
theme_read(rc.theme_name);
2020-06-29 19:27:59 +01:00
xbm_load(server.renderer);
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);
2020-08-13 20:18:48 +01:00
rcxml_finish();
pango_cairo_font_map_set_default(NULL);
2019-05-11 21:26:59 +01:00
return 0;
}