forked from external/yambar
particle/empty: expose info through the new struct particle_info struct
This commit is contained in:
parent
c2db518a4f
commit
0f8f21510a
4 changed files with 46 additions and 19 deletions
|
@ -9,6 +9,8 @@
|
|||
#include "plugin.h"
|
||||
#include "tllist.h"
|
||||
|
||||
#include "particles/empty.h"
|
||||
|
||||
const char *
|
||||
conf_err_prefix(const keychain_t *chain, const struct yml_node *node)
|
||||
{
|
||||
|
@ -315,10 +317,6 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
|||
{"right-margin", false, &conf_verify_int}, \
|
||||
{"on-click", false, &conf_verify_string},
|
||||
|
||||
static const struct attr_info empty[] = {
|
||||
COMMON_ATTRS
|
||||
};
|
||||
|
||||
static const struct attr_info list[] = {
|
||||
{"items", true, &verify_list_items},
|
||||
{"spacing", false, &conf_verify_int},
|
||||
|
@ -363,12 +361,18 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
|||
|
||||
#undef COMMON_ATTRS
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
const struct particle_info *info;
|
||||
} particles_v2[] = {
|
||||
{"empty", &particle_empty},
|
||||
};
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
const struct attr_info *attrs;
|
||||
size_t count;
|
||||
} particles[] = {
|
||||
{"empty", empty, sizeof(empty) / sizeof(empty[0])},
|
||||
{"list", list, sizeof(list) / sizeof(list[0])},
|
||||
{"map", map, sizeof(map) / sizeof(map[0])},
|
||||
{"progress-bar", progress_bar, sizeof(progress_bar) / sizeof(progress_bar[0])},
|
||||
|
@ -376,6 +380,21 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
|||
{"string", string, sizeof(string) / sizeof(string[0])},
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < sizeof(particles_v2) / sizeof(particles_v2[0]); i++) {
|
||||
if (strcmp(particles_v2[i].name, particle_name) != 0)
|
||||
continue;
|
||||
|
||||
if (!conf_verify_dict(chain_push(chain, particle_name), values,
|
||||
particles_v2[i].info->attrs,
|
||||
particles_v2[i].info->attr_count))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
chain_pop(chain);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sizeof(particles) / sizeof(particles[0]); i++) {
|
||||
if (strcmp(particles[i].name, particle_name) != 0)
|
||||
continue;
|
||||
|
|
11
config.c
11
config.c
|
@ -137,14 +137,6 @@ deco_from_config(const struct yml_node *node)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static struct particle *
|
||||
particle_empty_from_config(const struct yml_node *node,
|
||||
const struct font *parent_font,
|
||||
int left_margin, int right_margin,
|
||||
const char *on_click_template)
|
||||
{
|
||||
return particle_empty_new(left_margin, right_margin, on_click_template);
|
||||
}
|
||||
|
||||
static struct particle *
|
||||
particle_string_from_config(const struct yml_node *node,
|
||||
|
@ -323,8 +315,9 @@ conf_to_particle(const struct yml_node *node, const struct font *parent_font)
|
|||
|
||||
struct particle *ret = NULL;
|
||||
if (strcmp(type, "empty") == 0)
|
||||
ret = particle_empty_from_config(
|
||||
ret = particle_empty.from_conf(
|
||||
pair.value, parent_font, left, right, on_click_template);
|
||||
|
||||
else if (strcmp(type, "string") == 0)
|
||||
ret = particle_string_from_config(
|
||||
pair.value, parent_font, left, right, on_click_template);
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../config.h"
|
||||
|
||||
static int
|
||||
begin_expose(struct exposable *exposable)
|
||||
{
|
||||
|
@ -29,9 +31,8 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
|||
return exposable;
|
||||
}
|
||||
|
||||
struct particle *
|
||||
particle_empty_new(int left_margin, int right_margin,
|
||||
const char *on_click_template)
|
||||
static struct particle *
|
||||
empty_new(int left_margin, int right_margin, const char *on_click_template)
|
||||
{
|
||||
struct particle *particle = particle_common_new(
|
||||
left_margin, right_margin, on_click_template);
|
||||
|
@ -39,3 +40,18 @@ particle_empty_new(int left_margin, int right_margin,
|
|||
particle->instantiate = &instantiate;
|
||||
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)
|
||||
{
|
||||
return empty_new(left_margin, right_margin, on_click_template);
|
||||
}
|
||||
|
||||
const struct particle_info particle_empty = {
|
||||
.from_conf = &from_conf,
|
||||
.attr_count = PARTICLE_COMMON_ATTRS_COUNT + 0,
|
||||
.attrs = {
|
||||
PARTICLE_COMMON_ATTRS,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include "../particle.h"
|
||||
|
||||
struct particle *particle_empty_new(
|
||||
int left_margin, int right_margin, const char *on_click_template);
|
||||
extern const struct particle_info particle_empty;
|
||||
|
|
Loading…
Add table
Reference in a new issue