overline: new decoration

Similar to the ‘underline’ decoration
This commit is contained in:
Daniel Eklöf 2022-02-10 18:35:45 +01:00
parent 6ac046dec3
commit 605490c872
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
5 changed files with 111 additions and 1 deletions

View file

@ -14,6 +14,10 @@
* Support for custom font fallbacks * Support for custom font fallbacks
(https://codeberg.org/dnkl/yambar/issues/153). (https://codeberg.org/dnkl/yambar/issues/153).
* overline: new decoration
(https://codeberg.org/dnkl/yambar/issues/153).
### Changed ### Changed
### Deprecated ### Deprecated
### Removed ### Removed

View file

@ -1,7 +1,7 @@
deco_sdk = declare_dependency(dependencies: [pixman, tllist, fcft]) deco_sdk = declare_dependency(dependencies: [pixman, tllist, fcft])
decorations = [] decorations = []
foreach deco : ['background', 'border', 'stack', 'underline'] foreach deco : ['background', 'border', 'stack', 'underline', 'overline']
if plugs_as_libs if plugs_as_libs
shared_module('@0@'.format(deco), '@0@.c'.format(deco), shared_module('@0@'.format(deco), '@0@.c'.format(deco),
dependencies: deco_sdk, dependencies: deco_sdk,

72
decorations/overline.c Normal file
View file

@ -0,0 +1,72 @@
#include <stdlib.h>
#include "../config.h"
#include "../config-verify.h"
#include "../decoration.h"
#include "../plugin.h"
struct private {
int size;
pixman_color_t color;
};
static void
destroy(struct deco *deco)
{
struct private *d = deco->private;
free(d);
free(deco);
}
static void
expose(const struct deco *deco, pixman_image_t *pix, int x, int y, int width, int height)
{
const struct private *d = deco->private;
pixman_image_fill_rectangles(
PIXMAN_OP_OVER, pix, &d->color, 1,
&(pixman_rectangle16_t){x, y, width, d->size});
}
static struct deco *
overline_new(int size, pixman_color_t color)
{
struct private *priv = calloc(1, sizeof(*priv));
priv->size = size;
priv->color = color;
struct deco *deco = calloc(1, sizeof(*deco));
deco->private = priv;
deco->expose = &expose;
deco->destroy = &destroy;
return deco;
}
static 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 overline_new(yml_value_as_int(size), conf_to_color(color));
}
static bool
verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"size", true, &conf_verify_unsigned},
{"color", true, &conf_verify_color},
DECORATION_COMMON_ATTRS,
};
return conf_verify_dict(chain, node, attrs);
}
const struct deco_iface deco_overline_iface = {
.verify_conf = &verify_conf,
.from_conf = &from_conf,
};
#if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES)
extern const struct deco_iface iface __attribute__((weak, alias("deco_overline_iface")));
#endif

View file

@ -71,6 +71,38 @@ content:
``` ```
# OVERLINE
Similar to _underline_, this decoration renders a line of configurable
size and color at the top of the particle.
## CONFIGURATION
[[ *Name*
:[ *Type*
:[ *Req*
:[ *Description*
| size
: int
: yes
: The size (height/thickness) of the line, in pixels
| color
: color
: yes
: The color of the line. See *yambar*(5) for format.
## EXAMPLES
```
content:
string:
deco:
overline:
size: 2
color: ff0000ff
```
# BORDER # BORDER
This decoration renders a border of configurable size (i.e border This decoration renders a border of configurable size (i.e border

View file

@ -63,6 +63,7 @@ EXTERN_DECORATION(background);
EXTERN_DECORATION(border); EXTERN_DECORATION(border);
EXTERN_DECORATION(stack); EXTERN_DECORATION(stack);
EXTERN_DECORATION(underline); EXTERN_DECORATION(underline);
EXTERN_DECORATION(overline);
#undef EXTERN_DECORATION #undef EXTERN_DECORATION
#undef EXTERN_PARTICLE #undef EXTERN_PARTICLE
@ -152,6 +153,7 @@ init(void)
REGISTER_CORE_DECORATION(border, border); REGISTER_CORE_DECORATION(border, border);
REGISTER_CORE_DECORATION(stack, stack); REGISTER_CORE_DECORATION(stack, stack);
REGISTER_CORE_DECORATION(underline, underline); REGISTER_CORE_DECORATION(underline, underline);
REGISTER_CORE_DECORATION(overline, overline);
#undef REGISTER_CORE_DECORATION #undef REGISTER_CORE_DECORATION
#undef REGISTER_CORE_PARTICLE #undef REGISTER_CORE_PARTICLE