diff --git a/config.c b/config.c index e45d5cd..5c6eb57 100644 --- a/config.c +++ b/config.c @@ -169,14 +169,14 @@ conf_to_particle(const struct yml_node *node, struct conf_inherit inherited) } struct bar * -conf_to_bar(const struct yml_node *bar) +conf_to_bar(const struct yml_node *bar, enum bar_backend backend) { if (!conf_verify_bar(bar)) return NULL; - struct bar_config conf = {0}; - - conf.backend = BAR_BACKEND_AUTO; + struct bar_config conf = { + .backend = backend, + }; /* * Required attributes diff --git a/config.h b/config.h index ee3f281..a909c60 100644 --- a/config.h +++ b/config.h @@ -2,12 +2,13 @@ #include "font.h" #include "yml.h" +#include "bar/bar.h" struct bar; struct particle; bool conf_verify_bar(const struct yml_node *bar); -struct bar *conf_to_bar(const struct yml_node *bar); +struct bar *conf_to_bar(const struct yml_node *bar, enum bar_backend backend); /* * Utility functions, for e.g. modules diff --git a/doc/f00bar.1.scd b/doc/f00bar.1.scd index 8bc4a88..b43920f 100644 --- a/doc/f00bar.1.scd +++ b/doc/f00bar.1.scd @@ -8,6 +8,12 @@ f00bar - modular status panel for X11 and Wayland # OPTIONS +*-b, --backend={xcb,wayland,auto}* + Backend to use. The default is *auto*. In this mode, f00bar will + look for the environment variable _WAYLAND\_DISPLAY_, and if + available, use the *Wayland* backend. If not, the *XCB* backend is + used. + *-c, --config=FILE* Use an alternative configuration file instead of the default one. diff --git a/main.c b/main.c index 39e8292..421f873 100644 --- a/main.c +++ b/main.c @@ -82,7 +82,7 @@ get_config_path(void) } static struct bar * -load_bar(const char *config_path) +load_bar(const char *config_path, enum bar_backend backend) { FILE *conf_file = fopen(config_path, "r"); if (conf_file == NULL) { @@ -105,7 +105,7 @@ load_bar(const char *config_path) goto out; } - bar = conf_to_bar(bar_conf); + bar = conf_to_bar(bar_conf, backend); if (bar == NULL) { LOG_ERR("%s: failed to load configuration", config_path); goto out; @@ -124,9 +124,10 @@ print_usage(const char *prog_name) printf("Usage: %s [OPTION]...\n", prog_name); printf("\n"); printf("Options:\n"); - printf(" -c,--config=FILE alternative configuration file\n" - " -C,--validate verify configuration then quit\n" - " -v,--version print f00sel version and quit\n"); + printf(" -b,--backend={xcb,wayland,auto} backend to use (default: auto)\n" + " -c,--config=FILE alternative configuration file\n" + " -C,--validate verify configuration then quit\n" + " -v,--version print f00sel version and quit\n"); } int @@ -135,6 +136,7 @@ main(int argc, char *const *argv) setlocale(LC_ALL, ""); static const struct option longopts[] = { + {"backend", required_argument, 0, 'b'}, {"config", required_argument, 0, 'c'}, {"validate", no_argument, 0, 'C'}, {"version", no_argument, 0, 'v'}, @@ -144,13 +146,25 @@ main(int argc, char *const *argv) bool verify_config = false; char *config_path = NULL; + enum bar_backend backend = BAR_BACKEND_AUTO; while (true) { - int c = getopt_long(argc, argv, ":c:Cvh", longopts, NULL); + int c = getopt_long(argc, argv, ":b:c:Cvh", longopts, NULL); if (c == -1) break; switch (c) { + case 'b': + if (strcmp(optarg, "xcb") == 0) + backend = BAR_BACKEND_XCB; + else if (strcmp(optarg, "wayland") == 0) + backend = BAR_BACKEND_WAYLAND; + else { + LOG_ERR("%s: invalid backend", optarg); + return EXIT_FAILURE; + } + break; + case 'c': { struct stat st; if (stat(optarg, &st) == -1) { @@ -214,7 +228,7 @@ main(int argc, char *const *argv) } } - struct bar *bar = load_bar(config_path); + struct bar *bar = load_bar(config_path, backend); free(config_path); if (bar == NULL) {