forked from external/yambar
main: add -b,--backend command line option
This option allows the user to explicitly select the backend to use. The default is still to auto-detect.
This commit is contained in:
parent
473802cab8
commit
5eef162d39
4 changed files with 33 additions and 12 deletions
8
config.c
8
config.c
|
@ -169,14 +169,14 @@ conf_to_particle(const struct yml_node *node, struct conf_inherit inherited)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bar *
|
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))
|
if (!conf_verify_bar(bar))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
struct bar_config conf = {0};
|
struct bar_config conf = {
|
||||||
|
.backend = backend,
|
||||||
conf.backend = BAR_BACKEND_AUTO;
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Required attributes
|
* Required attributes
|
||||||
|
|
3
config.h
3
config.h
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
#include "yml.h"
|
#include "yml.h"
|
||||||
|
#include "bar/bar.h"
|
||||||
|
|
||||||
struct bar;
|
struct bar;
|
||||||
struct particle;
|
struct particle;
|
||||||
|
|
||||||
bool conf_verify_bar(const struct yml_node *bar);
|
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
|
* Utility functions, for e.g. modules
|
||||||
|
|
|
@ -8,6 +8,12 @@ f00bar - modular status panel for X11 and Wayland
|
||||||
|
|
||||||
# OPTIONS
|
# 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*
|
*-c, --config=FILE*
|
||||||
Use an alternative configuration file instead of the default one.
|
Use an alternative configuration file instead of the default one.
|
||||||
|
|
||||||
|
|
28
main.c
28
main.c
|
@ -82,7 +82,7 @@ get_config_path(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bar *
|
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");
|
FILE *conf_file = fopen(config_path, "r");
|
||||||
if (conf_file == NULL) {
|
if (conf_file == NULL) {
|
||||||
|
@ -105,7 +105,7 @@ load_bar(const char *config_path)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bar = conf_to_bar(bar_conf);
|
bar = conf_to_bar(bar_conf, backend);
|
||||||
if (bar == NULL) {
|
if (bar == NULL) {
|
||||||
LOG_ERR("%s: failed to load configuration", config_path);
|
LOG_ERR("%s: failed to load configuration", config_path);
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -124,9 +124,10 @@ print_usage(const char *prog_name)
|
||||||
printf("Usage: %s [OPTION]...\n", prog_name);
|
printf("Usage: %s [OPTION]...\n", prog_name);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -c,--config=FILE alternative configuration file\n"
|
printf(" -b,--backend={xcb,wayland,auto} backend to use (default: auto)\n"
|
||||||
" -C,--validate verify configuration then quit\n"
|
" -c,--config=FILE alternative configuration file\n"
|
||||||
" -v,--version print f00sel version and quit\n");
|
" -C,--validate verify configuration then quit\n"
|
||||||
|
" -v,--version print f00sel version and quit\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -135,6 +136,7 @@ main(int argc, char *const *argv)
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
static const struct option longopts[] = {
|
static const struct option longopts[] = {
|
||||||
|
{"backend", required_argument, 0, 'b'},
|
||||||
{"config", required_argument, 0, 'c'},
|
{"config", required_argument, 0, 'c'},
|
||||||
{"validate", no_argument, 0, 'C'},
|
{"validate", no_argument, 0, 'C'},
|
||||||
{"version", no_argument, 0, 'v'},
|
{"version", no_argument, 0, 'v'},
|
||||||
|
@ -144,13 +146,25 @@ main(int argc, char *const *argv)
|
||||||
|
|
||||||
bool verify_config = false;
|
bool verify_config = false;
|
||||||
char *config_path = NULL;
|
char *config_path = NULL;
|
||||||
|
enum bar_backend backend = BAR_BACKEND_AUTO;
|
||||||
|
|
||||||
while (true) {
|
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)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch (c) {
|
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': {
|
case 'c': {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat(optarg, &st) == -1) {
|
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);
|
free(config_path);
|
||||||
|
|
||||||
if (bar == NULL) {
|
if (bar == NULL) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue