forked from external/yambar
particle/list: expose info through the new struct particle_info struct
This commit is contained in:
parent
0f8f21510a
commit
6379b1939f
5 changed files with 56 additions and 48 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include "tllist.h"
|
#include "tllist.h"
|
||||||
|
|
||||||
#include "particles/empty.h"
|
#include "particles/empty.h"
|
||||||
|
#include "particles/list.h"
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
conf_err_prefix(const keychain_t *chain, const struct yml_node *node)
|
conf_err_prefix(const keychain_t *chain, const struct yml_node *node)
|
||||||
|
@ -245,8 +246,8 @@ verify_decoration(keychain_t *chain, const struct yml_node *node)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
bool
|
||||||
verify_list_items(keychain_t *chain, const struct yml_node *node)
|
conf_verify_particle_list_items(keychain_t *chain, const struct yml_node *node)
|
||||||
{
|
{
|
||||||
assert(yml_is_list(node));
|
assert(yml_is_list(node));
|
||||||
|
|
||||||
|
@ -317,14 +318,6 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
||||||
{"right-margin", false, &conf_verify_int}, \
|
{"right-margin", false, &conf_verify_int}, \
|
||||||
{"on-click", false, &conf_verify_string},
|
{"on-click", false, &conf_verify_string},
|
||||||
|
|
||||||
static const struct attr_info list[] = {
|
|
||||||
{"items", true, &verify_list_items},
|
|
||||||
{"spacing", false, &conf_verify_int},
|
|
||||||
{"left-spacing", false, &conf_verify_int},
|
|
||||||
{"right-spacing", false, &conf_verify_int},
|
|
||||||
COMMON_ATTRS
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct attr_info map[] = {
|
static const struct attr_info map[] = {
|
||||||
{"tag", true, &conf_verify_string},
|
{"tag", true, &conf_verify_string},
|
||||||
{"values", true, &verify_map_values},
|
{"values", true, &verify_map_values},
|
||||||
|
@ -346,7 +339,7 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
||||||
|
|
||||||
static const struct attr_info ramp[] = {
|
static const struct attr_info ramp[] = {
|
||||||
{"tag", true, &conf_verify_string},
|
{"tag", true, &conf_verify_string},
|
||||||
{"items", true, &verify_list_items},
|
{"items", true, &conf_verify_particle_list_items},
|
||||||
COMMON_ATTRS
|
COMMON_ATTRS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -366,6 +359,7 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
||||||
const struct particle_info *info;
|
const struct particle_info *info;
|
||||||
} particles_v2[] = {
|
} particles_v2[] = {
|
||||||
{"empty", &particle_empty},
|
{"empty", &particle_empty},
|
||||||
|
{"list", &particle_list},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
|
@ -373,7 +367,6 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
||||||
const struct attr_info *attrs;
|
const struct attr_info *attrs;
|
||||||
size_t count;
|
size_t count;
|
||||||
} particles[] = {
|
} particles[] = {
|
||||||
{"list", list, sizeof(list) / sizeof(list[0])},
|
|
||||||
{"map", map, sizeof(map) / sizeof(map[0])},
|
{"map", map, sizeof(map) / sizeof(map[0])},
|
||||||
{"progress-bar", progress_bar, sizeof(progress_bar) / sizeof(progress_bar[0])},
|
{"progress-bar", progress_bar, sizeof(progress_bar) / sizeof(progress_bar[0])},
|
||||||
{"ramp", ramp, sizeof(ramp) / sizeof(ramp[0])},
|
{"ramp", ramp, sizeof(ramp) / sizeof(ramp[0])},
|
||||||
|
@ -420,7 +413,7 @@ conf_verify_particle(keychain_t *chain, const struct yml_node *node)
|
||||||
if (yml_is_dict(node))
|
if (yml_is_dict(node))
|
||||||
return conf_verify_particle_dictionary(chain, node);
|
return conf_verify_particle_dictionary(chain, node);
|
||||||
else if (yml_is_list(node))
|
else if (yml_is_list(node))
|
||||||
return verify_list_items(chain, node);
|
return conf_verify_particle_list_items(chain, node);
|
||||||
else {
|
else {
|
||||||
LOG_ERR("%s: particle must be either a dictionary or a list",
|
LOG_ERR("%s: particle must be either a dictionary or a list",
|
||||||
conf_err_prefix(chain, node));
|
conf_err_prefix(chain, node));
|
||||||
|
|
|
@ -42,3 +42,4 @@ bool conf_verify_color(keychain_t *chain, const struct yml_node *node);
|
||||||
bool conf_verify_font(keychain_t *chain, const struct yml_node *node);
|
bool conf_verify_font(keychain_t *chain, const struct yml_node *node);
|
||||||
|
|
||||||
bool conf_verify_particle(keychain_t *chain, const struct yml_node *node);
|
bool conf_verify_particle(keychain_t *chain, const struct yml_node *node);
|
||||||
|
bool conf_verify_particle_list_items(keychain_t *chain, const struct yml_node *node);
|
||||||
|
|
38
config.c
38
config.c
|
@ -160,38 +160,6 @@ particle_string_from_config(const struct yml_node *node,
|
||||||
fg_color, left_margin, right_margin, on_click_template);
|
fg_color, left_margin, right_margin, on_click_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct particle *
|
|
||||||
particle_list_from_config(const struct yml_node *node,
|
|
||||||
const struct font *parent_font,
|
|
||||||
int left_margin, int right_margin,
|
|
||||||
const char *on_click_template)
|
|
||||||
{
|
|
||||||
const struct yml_node *items = yml_get_value(node, "items");
|
|
||||||
|
|
||||||
const struct yml_node *spacing = yml_get_value(node, "spacing");
|
|
||||||
const struct yml_node *_left_spacing = yml_get_value(node, "left-spacing");
|
|
||||||
const struct yml_node *_right_spacing = yml_get_value(node, "right-spacing");
|
|
||||||
|
|
||||||
int left_spacing = spacing != NULL ? yml_value_as_int(spacing) :
|
|
||||||
_left_spacing != NULL ? yml_value_as_int(_left_spacing) : 0;
|
|
||||||
int right_spacing = spacing != NULL ? yml_value_as_int(spacing) :
|
|
||||||
_right_spacing != NULL ? yml_value_as_int(_right_spacing) : 2;
|
|
||||||
|
|
||||||
size_t count = yml_list_length(items);
|
|
||||||
struct particle *parts[count];
|
|
||||||
|
|
||||||
size_t idx = 0;
|
|
||||||
for (struct yml_list_iter it = yml_list_iter(items);
|
|
||||||
it.node != NULL;
|
|
||||||
yml_list_next(&it), idx++)
|
|
||||||
{
|
|
||||||
parts[idx] = conf_to_particle(it.node, parent_font);
|
|
||||||
}
|
|
||||||
|
|
||||||
return particle_list_new(
|
|
||||||
parts, count, left_spacing, right_spacing, left_margin, right_margin,
|
|
||||||
on_click_template);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct particle *
|
static struct particle *
|
||||||
particle_map_from_config(const struct yml_node *node,
|
particle_map_from_config(const struct yml_node *node,
|
||||||
|
@ -317,13 +285,13 @@ conf_to_particle(const struct yml_node *node, const struct font *parent_font)
|
||||||
if (strcmp(type, "empty") == 0)
|
if (strcmp(type, "empty") == 0)
|
||||||
ret = particle_empty.from_conf(
|
ret = particle_empty.from_conf(
|
||||||
pair.value, parent_font, left, right, on_click_template);
|
pair.value, parent_font, left, right, on_click_template);
|
||||||
|
else if (strcmp(type, "list") == 0)
|
||||||
|
ret = particle_list.from_conf(
|
||||||
|
pair.value, parent_font, left, right, on_click_template);
|
||||||
|
|
||||||
else if (strcmp(type, "string") == 0)
|
else if (strcmp(type, "string") == 0)
|
||||||
ret = particle_string_from_config(
|
ret = particle_string_from_config(
|
||||||
pair.value, parent_font, left, right, on_click_template);
|
pair.value, parent_font, left, right, on_click_template);
|
||||||
else if (strcmp(type, "list") == 0)
|
|
||||||
ret = particle_list_from_config(
|
|
||||||
pair.value, parent_font, left, right, on_click_template);
|
|
||||||
else if (strcmp(type, "map") == 0)
|
else if (strcmp(type, "map") == 0)
|
||||||
ret = particle_map_from_config(
|
ret = particle_map_from_config(
|
||||||
pair.value, parent_font, left, right, on_click_template);
|
pair.value, parent_font, left, right, on_click_template);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#define LOG_MODULE "list"
|
#define LOG_MODULE "list"
|
||||||
#define LOG_ENABLE_DBG 1
|
#define LOG_ENABLE_DBG 1
|
||||||
#include "../log.h"
|
#include "../log.h"
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
struct private {
|
struct private {
|
||||||
struct particle **particles;
|
struct particle **particles;
|
||||||
|
@ -165,3 +166,46 @@ particle_list_new(
|
||||||
|
|
||||||
return particle;
|
return particle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct particle *
|
||||||
|
from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||||
|
int left_margin, int right_margin, const char *on_click_template)
|
||||||
|
{
|
||||||
|
const struct yml_node *items = yml_get_value(node, "items");
|
||||||
|
|
||||||
|
const struct yml_node *spacing = yml_get_value(node, "spacing");
|
||||||
|
const struct yml_node *_left_spacing = yml_get_value(node, "left-spacing");
|
||||||
|
const struct yml_node *_right_spacing = yml_get_value(node, "right-spacing");
|
||||||
|
|
||||||
|
int left_spacing = spacing != NULL ? yml_value_as_int(spacing) :
|
||||||
|
_left_spacing != NULL ? yml_value_as_int(_left_spacing) : 0;
|
||||||
|
int right_spacing = spacing != NULL ? yml_value_as_int(spacing) :
|
||||||
|
_right_spacing != NULL ? yml_value_as_int(_right_spacing) : 2;
|
||||||
|
|
||||||
|
size_t count = yml_list_length(items);
|
||||||
|
struct particle *parts[count];
|
||||||
|
|
||||||
|
size_t idx = 0;
|
||||||
|
for (struct yml_list_iter it = yml_list_iter(items);
|
||||||
|
it.node != NULL;
|
||||||
|
yml_list_next(&it), idx++)
|
||||||
|
{
|
||||||
|
parts[idx] = conf_to_particle(it.node, parent_font);
|
||||||
|
}
|
||||||
|
|
||||||
|
return particle_list_new(
|
||||||
|
parts, count, left_spacing, right_spacing, left_margin, right_margin,
|
||||||
|
on_click_template);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct particle_info particle_list = {
|
||||||
|
.from_conf = &from_conf,
|
||||||
|
.attr_count = PARTICLE_COMMON_ATTRS_COUNT + 4,
|
||||||
|
.attrs = {
|
||||||
|
{"items", true, &conf_verify_particle_list_items},
|
||||||
|
{"spacing", false, &conf_verify_int},
|
||||||
|
{"left-spacing", false, &conf_verify_int},
|
||||||
|
{"right-spacing", false, &conf_verify_int},
|
||||||
|
PARTICLE_COMMON_ATTRS,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
|
@ -5,3 +5,5 @@ struct particle *particle_list_new(
|
||||||
struct particle *particles[], size_t count,
|
struct particle *particles[], size_t count,
|
||||||
int left_spacing, int right_spacing, int left_margin, int right_margin,
|
int left_spacing, int right_spacing, int left_margin, int right_margin,
|
||||||
const char *on_click_template);
|
const char *on_click_template);
|
||||||
|
|
||||||
|
extern const struct particle_info particle_list;
|
||||||
|
|
Loading…
Add table
Reference in a new issue