forked from external/yambar
decorations: are now plugins
This commit is contained in:
parent
4eee71eaf4
commit
7754ef3661
11 changed files with 160 additions and 124 deletions
24
decorations/CMakeLists.txt
Normal file
24
decorations/CMakeLists.txt
Normal file
|
@ -0,0 +1,24 @@
|
|||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
add_library(decoration-sdk INTERFACE)
|
||||
target_compile_options(decoration-sdk INTERFACE ${CAIRO_CFLAGS_OTHER})
|
||||
target_include_directories(decoration-sdk INTERFACE ${CAIRO_INCLUDE_DIRS})
|
||||
|
||||
set(CMAKE_SHARED_MODULE_PREFIX decoration_)
|
||||
|
||||
add_library(background MODULE background.c background.h)
|
||||
target_link_libraries(background decoration-sdk)
|
||||
|
||||
add_library(stack MODULE stack.c stack.h)
|
||||
target_link_libraries(stack decoration-sdk)
|
||||
|
||||
add_library(underline MODULE underline.c underline.h)
|
||||
target_link_libraries(underline decoration-sdk)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
background
|
||||
stack
|
||||
underline
|
||||
|
||||
DESTINATION lib/f00bar)
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../config.h"
|
||||
#include "../config-verify.h"
|
||||
|
||||
struct private {
|
||||
struct rgba color;
|
||||
};
|
||||
|
@ -24,8 +27,8 @@ expose(const struct deco *deco, cairo_t *cr, int x, int y, int width, int height
|
|||
cairo_fill(cr);
|
||||
}
|
||||
|
||||
struct deco *
|
||||
deco_background(struct rgba color)
|
||||
static struct deco *
|
||||
background_new(struct rgba color)
|
||||
{
|
||||
struct private *priv = malloc(sizeof(*priv));
|
||||
priv->color = color;
|
||||
|
@ -37,3 +40,21 @@ deco_background(struct rgba color)
|
|||
|
||||
return deco;
|
||||
}
|
||||
|
||||
struct deco *
|
||||
from_conf(const struct yml_node *node)
|
||||
{
|
||||
const struct yml_node *color = yml_get_value(node, "color");
|
||||
return background_new(conf_to_color(color));
|
||||
}
|
||||
|
||||
bool
|
||||
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||
{
|
||||
static const struct attr_info attrs[] = {
|
||||
{"color", true, &conf_verify_color},
|
||||
DECORATION_COMMON_ATTRS,
|
||||
};
|
||||
|
||||
return conf_verify_dict(chain, node, attrs);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
#define LOG_MODULE "stack"
|
||||
#include "../log.h"
|
||||
#include "../config.h"
|
||||
#include "../config-verify.h"
|
||||
|
||||
struct private {
|
||||
struct deco **decos;
|
||||
size_t count;
|
||||
|
@ -26,8 +31,8 @@ expose(const struct deco *deco, cairo_t *cr, int x, int y, int width, int height
|
|||
d->decos[i]->expose(d->decos[i], cr, x, y, width, height);
|
||||
}
|
||||
|
||||
struct deco *
|
||||
deco_stack(struct deco *decos[], size_t count)
|
||||
static struct deco *
|
||||
stack_new(struct deco *decos[], size_t count)
|
||||
{
|
||||
struct private *priv = malloc(sizeof(*priv));
|
||||
priv->decos = malloc(count * sizeof(priv->decos[0]));
|
||||
|
@ -43,3 +48,39 @@ deco_stack(struct deco *decos[], size_t count)
|
|||
|
||||
return deco;
|
||||
}
|
||||
struct deco *
|
||||
from_conf(const struct yml_node *node)
|
||||
{
|
||||
size_t count = yml_list_length(node);
|
||||
|
||||
struct deco *decos[count];
|
||||
size_t idx = 0;
|
||||
|
||||
for (struct yml_list_iter it = yml_list_iter(node);
|
||||
it.node != NULL;
|
||||
yml_list_next(&it), idx++)
|
||||
{
|
||||
decos[idx] = conf_to_deco(it.node);
|
||||
}
|
||||
|
||||
return stack_new(decos, count);
|
||||
}
|
||||
|
||||
bool
|
||||
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||
{
|
||||
if (!yml_is_list(node)) {
|
||||
LOG_ERR("%s: must be a list of decorations", conf_err_prefix(chain, node));
|
||||
return false;
|
||||
}
|
||||
|
||||
for (struct yml_list_iter it = yml_list_iter(node);
|
||||
it.node != NULL;
|
||||
yml_list_next(&it))
|
||||
{
|
||||
if (!conf_verify_decoration(chain, it.node))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../config.h"
|
||||
#include "../config-verify.h"
|
||||
|
||||
struct private {
|
||||
int size;
|
||||
struct rgba color;
|
||||
|
@ -25,8 +28,8 @@ expose(const struct deco *deco, cairo_t *cr, int x, int y, int width, int height
|
|||
cairo_fill(cr);
|
||||
}
|
||||
|
||||
struct deco *
|
||||
deco_underline(int size, struct rgba color)
|
||||
static struct deco *
|
||||
underline_new(int size, struct rgba color)
|
||||
{
|
||||
struct private *priv = malloc(sizeof(*priv));
|
||||
priv->size = size;
|
||||
|
@ -39,3 +42,23 @@ deco_underline(int size, struct rgba color)
|
|||
|
||||
return deco;
|
||||
}
|
||||
|
||||
struct deco *
|
||||
from_conf(const struct yml_node *node)
|
||||
{
|
||||
const struct yml_node *size = yml_get_value(node, "size");
|
||||
const struct yml_node *color = yml_get_value(node, "color");
|
||||
return underline_new(yml_value_as_int(size), conf_to_color(color));
|
||||
}
|
||||
|
||||
bool
|
||||
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||
{
|
||||
static const struct attr_info attrs[] = {
|
||||
{"size", true, &conf_verify_int},
|
||||
{"color", true, &conf_verify_color},
|
||||
DECORATION_COMMON_ATTRS,
|
||||
};
|
||||
|
||||
return conf_verify_dict(chain, node, attrs);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue