mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 03:35:41 +02:00
bar: allow explicit backend selection
This commit is contained in:
parent
586cb8a0dd
commit
473802cab8
3 changed files with 53 additions and 18 deletions
66
bar/bar.c
66
bar/bar.c
|
@ -368,6 +368,52 @@ destroy(struct bar *bar)
|
|||
struct bar *
|
||||
bar_new(const struct bar_config *config)
|
||||
{
|
||||
void *backend_data = NULL;
|
||||
const struct backend *backend_iface = NULL;
|
||||
|
||||
switch (config->backend) {
|
||||
case BAR_BACKEND_AUTO:
|
||||
#if defined(ENABLE_X11) && !defined(ENABLE_WAYLAND)
|
||||
backend_data = bar_backend_xcb_new();
|
||||
backend_iface = &xcb_backend_iface;
|
||||
#elif !defined(ENABLE_X11) && defined(ENABLE_WAYLAND)
|
||||
backend_data = bar_backend_wayland_new();
|
||||
backend_iface = &wayland_backend_iface;
|
||||
#else
|
||||
if (getenv("WAYLAND_DISPLAY") != NULL) {
|
||||
backend_data = bar_backend_wayland_new();
|
||||
backend_iface = &wayland_backend_iface;
|
||||
} else {
|
||||
backend_data = bar_backend_xcb_new();
|
||||
backend_iface = &xcb_backend_iface;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case BAR_BACKEND_XCB:
|
||||
#if defined(ENABLE_X11)
|
||||
backend_data = bar_backend_xcb_new();
|
||||
backend_iface = &xcb_backend_iface;
|
||||
#else
|
||||
LOG_ERR("f00bar was compiled without the XCB backend");
|
||||
return NULL;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case BAR_BACKEND_WAYLAND:
|
||||
#if defined(BAR_WAYLAND)
|
||||
backend_data = bar_backend_wayland_new();
|
||||
backend_iface = &wayland_backend_iface;
|
||||
#else
|
||||
LOG_ERR("f00bar was compiled without the Wayland backend");
|
||||
return NULL;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
if (backend_data == NULL)
|
||||
return NULL;
|
||||
|
||||
struct private *priv = calloc(1, sizeof(*priv));
|
||||
priv->monitor = config->monitor != NULL ? strdup(config->monitor) : NULL;
|
||||
priv->location = config->location;
|
||||
|
@ -392,24 +438,8 @@ bar_new(const struct bar_config *config)
|
|||
priv->left.count = config->left.count;
|
||||
priv->center.count = config->center.count;
|
||||
priv->right.count = config->right.count;
|
||||
|
||||
#if defined(ENABLE_X11) && !defined(ENABLE_WAYLAND)
|
||||
priv->backend.data = bar_backend_xcb_new();
|
||||
priv->backend.iface = &xcb_backend_iface;
|
||||
#else
|
||||
#if !defined(ENABLE_X11) && defined(ENABLE_WAYLAND)
|
||||
priv->backend.data = bar_backend_wayland_new();
|
||||
priv->backend.iface = &wayland_backend_iface;
|
||||
#else
|
||||
if (getenv("WAYLAND_DISPLAY") != NULL) {
|
||||
priv->backend.data = bar_backend_wayland_new();
|
||||
priv->backend.iface = &wayland_backend_iface;
|
||||
} else {
|
||||
priv->backend.data = bar_backend_xcb_new();
|
||||
priv->backend.iface = &xcb_backend_iface;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
priv->backend.data = backend_data;
|
||||
priv->backend.iface = backend_iface;
|
||||
|
||||
for (size_t i = 0; i < priv->left.count; i++)
|
||||
priv->left.mods[i] = config->left.mods[i];
|
||||
|
|
|
@ -15,8 +15,11 @@ struct bar {
|
|||
};
|
||||
|
||||
enum bar_location { BAR_TOP, BAR_BOTTOM };
|
||||
enum bar_backend { BAR_BACKEND_AUTO, BAR_BACKEND_XCB, BAR_BACKEND_WAYLAND };
|
||||
|
||||
struct bar_config {
|
||||
enum bar_backend backend;
|
||||
|
||||
const char *monitor;
|
||||
enum bar_location location;
|
||||
int height;
|
||||
|
|
2
config.c
2
config.c
|
@ -176,6 +176,8 @@ conf_to_bar(const struct yml_node *bar)
|
|||
|
||||
struct bar_config conf = {0};
|
||||
|
||||
conf.backend = BAR_BACKEND_AUTO;
|
||||
|
||||
/*
|
||||
* Required attributes
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue