Apply "clang-format" preferences globally

This commit is contained in:
Delgan 2024-04-07 10:05:10 +02:00
parent d841aeeecd
commit b85ba99980
64 changed files with 1868 additions and 2678 deletions

View file

@ -1,13 +1,14 @@
#include "dynlist.h"
#include <stdlib.h>
#include <assert.h>
#include <stdlib.h>
#define LOG_MODULE "dynlist"
#include "../log.h"
#include "../particle.h"
struct private {
struct private
{
int left_spacing;
int right_spacing;
@ -77,8 +78,7 @@ dynlist_expose(const struct exposable *exposable, pixman_image_t *pix, int x, in
}
static void
on_mouse(struct exposable *exposable, struct bar *bar,
enum mouse_event event, enum mouse_button btn, int x, int y)
on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, enum mouse_button btn, int x, int y)
{
const struct private *e = exposable->private;
@ -87,12 +87,11 @@ on_mouse(struct exposable *exposable, struct bar *bar,
return;
}
int px = /*p->left_margin;*/0;
int px = /*p->left_margin;*/ 0;
for (size_t i = 0; i < e->count; i++) {
if (x >= px && x < px + e->exposables[i]->width) {
if (e->exposables[i]->on_mouse != NULL) {
e->exposables[i]->on_mouse(
e->exposables[i], bar, event, btn, x - px, y);
e->exposables[i]->on_mouse(e->exposables[i], bar, event, btn, x - px, y);
}
return;
}
@ -105,8 +104,7 @@ on_mouse(struct exposable *exposable, struct bar *bar,
}
struct exposable *
dynlist_exposable_new(struct exposable **exposables, size_t count,
int left_spacing, int right_spacing)
dynlist_exposable_new(struct exposable **exposables, size_t count, int left_spacing, int right_spacing)
{
struct private *e = calloc(1, sizeof(*e));
e->count = count;

View file

@ -3,5 +3,5 @@
#include <stddef.h>
struct particle;
struct exposable *dynlist_exposable_new(
struct exposable **exposables, size_t count, int left_spacing, int right_spacing);
struct exposable *dynlist_exposable_new(struct exposable **exposables, size_t count, int left_spacing,
int right_spacing);

View file

@ -1,15 +1,14 @@
#include <stdlib.h>
#include "../config.h"
#include "../config-verify.h"
#include "../config.h"
#include "../particle.h"
#include "../plugin.h"
static int
begin_expose(struct exposable *exposable)
{
exposable->width = exposable->particle->left_margin +
exposable->particle->right_margin;
exposable->width = exposable->particle->left_margin + exposable->particle->right_margin;
return exposable->width;
}

View file

@ -2,13 +2,14 @@
#define LOG_MODULE "list"
#define LOG_ENABLE_DBG 0
#include "../log.h"
#include "../config.h"
#include "../config-verify.h"
#include "../config.h"
#include "../log.h"
#include "../particle.h"
#include "../plugin.h"
struct private {
struct private
{
struct particle **particles;
size_t count;
int left_spacing, right_spacing;
@ -21,7 +22,6 @@ struct eprivate {
int left_spacing, right_spacing;
};
static void
exposable_destroy(struct exposable *exposable)
{
@ -86,16 +86,12 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int
}
static void
on_mouse(struct exposable *exposable, struct bar *bar,
enum mouse_event event, enum mouse_button btn, int x, int y)
on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, enum mouse_button btn, int x, int y)
{
const struct particle *p = exposable->particle;
const struct eprivate *e = exposable->private;
if ((event == ON_MOUSE_MOTION &&
exposable->particle->have_on_click_template) ||
exposable->on_click[btn] != NULL)
{
if ((event == ON_MOUSE_MOTION && exposable->particle->have_on_click_template) || exposable->on_click[btn] != NULL) {
/* We have our own handler */
exposable_default_on_mouse(exposable, bar, event, btn, x, y);
return;
@ -105,8 +101,7 @@ on_mouse(struct exposable *exposable, struct bar *bar,
for (size_t i = 0; i < e->count; i++) {
if (x >= px && x < px + e->exposables[i]->width) {
if (e->exposables[i]->on_mouse != NULL) {
e->exposables[i]->on_mouse(
e->exposables[i], bar, event, btn, x - px, y);
e->exposables[i]->on_mouse(e->exposables[i], bar, event, btn, x - px, y);
}
return;
}
@ -157,9 +152,8 @@ particle_destroy(struct particle *particle)
}
struct particle *
particle_list_new(struct particle *common,
struct particle *particles[], size_t count,
int left_spacing, int right_spacing)
particle_list_new(struct particle *common, struct particle *particles[], size_t count, int left_spacing,
int right_spacing)
{
struct private *p = calloc(1, sizeof(*p));
p->particles = malloc(count * sizeof(p->particles[0]));
@ -184,21 +178,20 @@ from_conf(const struct yml_node *node, struct particle *common)
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;
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, (struct conf_inherit){common->font, common->font_shaping, common->foreground});
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, (struct conf_inherit){common->font, common->font_shaping, common->foreground});
}
return particle_list_new(common, parts, count, left_spacing, right_spacing);

View file

@ -1,12 +1,12 @@
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#define LOG_MODULE "map"
#include "../log.h"
#include "../config.h"
#include "../config-verify.h"
#include "../config.h"
#include "../log.h"
#include "../particle.h"
#include "../plugin.h"
#include "dynlist.h"
@ -17,14 +17,22 @@ static bool
int_condition(const long tag_value, const long cond_value, enum map_op op)
{
switch (op) {
case MAP_OP_EQ: return tag_value == cond_value;
case MAP_OP_NE: return tag_value != cond_value;
case MAP_OP_LE: return tag_value <= cond_value;
case MAP_OP_LT: return tag_value < cond_value;
case MAP_OP_GE: return tag_value >= cond_value;
case MAP_OP_GT: return tag_value > cond_value;
case MAP_OP_SELF: LOG_WARN("using int tag as bool");
default: return false;
case MAP_OP_EQ:
return tag_value == cond_value;
case MAP_OP_NE:
return tag_value != cond_value;
case MAP_OP_LE:
return tag_value <= cond_value;
case MAP_OP_LT:
return tag_value < cond_value;
case MAP_OP_GE:
return tag_value >= cond_value;
case MAP_OP_GT:
return tag_value > cond_value;
case MAP_OP_SELF:
LOG_WARN("using int tag as bool");
default:
return false;
}
}
@ -32,34 +40,50 @@ static bool
float_condition(const double tag_value, const double cond_value, enum map_op op)
{
switch (op) {
case MAP_OP_EQ: return tag_value == cond_value;
case MAP_OP_NE: return tag_value != cond_value;
case MAP_OP_LE: return tag_value <= cond_value;
case MAP_OP_LT: return tag_value < cond_value;
case MAP_OP_GE: return tag_value >= cond_value;
case MAP_OP_GT: return tag_value > cond_value;
case MAP_OP_SELF: LOG_WARN("using float tag as bool");
default: return false;
case MAP_OP_EQ:
return tag_value == cond_value;
case MAP_OP_NE:
return tag_value != cond_value;
case MAP_OP_LE:
return tag_value <= cond_value;
case MAP_OP_LT:
return tag_value < cond_value;
case MAP_OP_GE:
return tag_value >= cond_value;
case MAP_OP_GT:
return tag_value > cond_value;
case MAP_OP_SELF:
LOG_WARN("using float tag as bool");
default:
return false;
}
}
static bool
str_condition(const char* tag_value, const char* cond_value, enum map_op op)
str_condition(const char *tag_value, const char *cond_value, enum map_op op)
{
switch (op) {
case MAP_OP_EQ: return strcmp(tag_value, cond_value) == 0;
case MAP_OP_NE: return strcmp(tag_value, cond_value) != 0;
case MAP_OP_LE: return strcmp(tag_value, cond_value) <= 0;
case MAP_OP_LT: return strcmp(tag_value, cond_value) < 0;
case MAP_OP_GE: return strcmp(tag_value, cond_value) >= 0;
case MAP_OP_GT: return strcmp(tag_value, cond_value) > 0;
case MAP_OP_SELF: LOG_WARN("using String tag as bool");
default: return false;
case MAP_OP_EQ:
return strcmp(tag_value, cond_value) == 0;
case MAP_OP_NE:
return strcmp(tag_value, cond_value) != 0;
case MAP_OP_LE:
return strcmp(tag_value, cond_value) <= 0;
case MAP_OP_LT:
return strcmp(tag_value, cond_value) < 0;
case MAP_OP_GE:
return strcmp(tag_value, cond_value) >= 0;
case MAP_OP_GT:
return strcmp(tag_value, cond_value) > 0;
case MAP_OP_SELF:
LOG_WARN("using String tag as bool");
default:
return false;
}
}
static bool
eval_comparison(const struct map_condition* map_cond, const struct tag_set *tags)
eval_comparison(const struct map_condition *map_cond, const struct tag_set *tags)
{
const struct tag *tag = tag_for_name(tags, map_cond->tag);
if (tag == NULL) {
@ -108,7 +132,7 @@ eval_comparison(const struct map_condition* map_cond, const struct tag_set *tags
return false;
}
case TAG_TYPE_STRING: {
const char* tag_value = tag->as_string(tag);
const char *tag_value = tag->as_string(tag);
return str_condition(tag_value, map_cond->value, map_cond->op);
}
}
@ -116,19 +140,17 @@ eval_comparison(const struct map_condition* map_cond, const struct tag_set *tags
}
static bool
eval_map_condition(const struct map_condition* map_cond, const struct tag_set *tags)
eval_map_condition(const struct map_condition *map_cond, const struct tag_set *tags)
{
switch(map_cond->op) {
switch (map_cond->op) {
case MAP_OP_NOT:
return !eval_map_condition(map_cond->cond1, tags);
case MAP_OP_AND:
return eval_map_condition(map_cond->cond1, tags) &&
eval_map_condition(map_cond->cond2, tags);
return eval_map_condition(map_cond->cond1, tags) && eval_map_condition(map_cond->cond2, tags);
case MAP_OP_OR:
return eval_map_condition(map_cond->cond1, tags) ||
eval_map_condition(map_cond->cond2, tags);
return eval_map_condition(map_cond->cond1, tags) || eval_map_condition(map_cond->cond2, tags);
default:
return eval_comparison(map_cond, tags);
@ -136,28 +158,27 @@ eval_map_condition(const struct map_condition* map_cond, const struct tag_set *t
}
void
free_map_condition(struct map_condition* c)
free_map_condition(struct map_condition *c)
{
switch (c->op)
{
case MAP_OP_EQ:
case MAP_OP_NE:
case MAP_OP_LE:
case MAP_OP_LT:
case MAP_OP_GE:
case MAP_OP_GT:
free(c->value);
/* FALLTHROUGH */
case MAP_OP_SELF:
free(c->tag);
break;
case MAP_OP_AND:
case MAP_OP_OR:
free_map_condition(c->cond2);
/* FALLTHROUGH */
case MAP_OP_NOT:
free_map_condition(c->cond1);
break;
switch (c->op) {
case MAP_OP_EQ:
case MAP_OP_NE:
case MAP_OP_LE:
case MAP_OP_LT:
case MAP_OP_GE:
case MAP_OP_GT:
free(c->value);
/* FALLTHROUGH */
case MAP_OP_SELF:
free(c->tag);
break;
case MAP_OP_AND:
case MAP_OP_OR:
free_map_condition(c->cond2);
/* FALLTHROUGH */
case MAP_OP_NOT:
free_map_condition(c->cond1);
break;
}
free(c);
}
@ -167,7 +188,8 @@ struct particle_map {
struct particle *particle;
};
struct private {
struct private
{
struct particle *default_particle;
struct particle_map *map;
size_t count;
@ -208,21 +230,16 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int
struct eprivate *e = exposable->private;
exposable_render_deco(exposable, pix, x, y, height);
e->exposable->expose(
e->exposable, pix, x + exposable->particle->left_margin, y, height);
e->exposable->expose(e->exposable, pix, x + exposable->particle->left_margin, y, height);
}
static void
on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event,
enum mouse_button btn, int x, int y)
on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, enum mouse_button btn, int x, int y)
{
const struct particle *p = exposable->particle;
const struct eprivate *e = exposable->private;
if ((event == ON_MOUSE_MOTION &&
exposable->particle->have_on_click_template) ||
exposable->on_click[btn] != NULL)
{
if ((event == ON_MOUSE_MOTION && exposable->particle->have_on_click_template) || exposable->on_click[btn] != NULL) {
/* We have our own handler */
exposable_default_on_mouse(exposable, bar, event, btn, x, y);
return;
@ -295,8 +312,8 @@ particle_destroy(struct particle *particle)
}
static struct particle *
map_new(struct particle *common, const struct particle_map particle_map[],
size_t count, struct particle *default_particle)
map_new(struct particle *common, const struct particle_map particle_map[], size_t count,
struct particle *default_particle)
{
struct private *priv = calloc(1, sizeof(*priv));
priv->default_particle = default_particle;
@ -314,22 +331,16 @@ map_new(struct particle *common, const struct particle_map particle_map[],
return common;
}
static bool
verify_map_conditions(keychain_t *chain, const struct yml_node *node)
{
if (!yml_is_dict(node)) {
LOG_ERR(
"%s: must be a dictionary of workspace-name: particle mappings",
conf_err_prefix(chain, node));
LOG_ERR("%s: must be a dictionary of workspace-name: particle mappings", conf_err_prefix(chain, node));
return false;
}
bool result = true;
for (struct yml_dict_iter it = yml_dict_iter(node);
it.key != NULL;
yml_dict_next(&it))
{
for (struct yml_dict_iter it = yml_dict_iter(node); it.key != NULL; yml_dict_next(&it)) {
const char *key = yml_value_as_string(it.key);
if (key == NULL) {
LOG_ERR("%s: key must be a string", conf_err_prefix(chain, it.key));
@ -363,17 +374,11 @@ from_conf(const struct yml_node *node, struct particle *common)
struct particle_map particle_map[yml_dict_length(conditions)];
struct conf_inherit inherited = {
.font = common->font,
.font_shaping = common->font_shaping,
.foreground = common->foreground
};
struct conf_inherit inherited
= {.font = common->font, .font_shaping = common->font_shaping, .foreground = common->foreground};
size_t idx = 0;
for (struct yml_dict_iter it = yml_dict_iter(conditions);
it.key != NULL;
yml_dict_next(&it), idx++)
{
for (struct yml_dict_iter it = yml_dict_iter(conditions); it.key != NULL; yml_dict_next(&it), idx++) {
/* Note we can skip the error checking here */
char *key_clone = strdup(yml_value_as_string(it.key));
YY_BUFFER_STATE buffer = yy_scan_string(key_clone);
@ -384,8 +389,7 @@ from_conf(const struct yml_node *node, struct particle *common)
particle_map[idx].particle = conf_to_particle(it.value, inherited);
}
struct particle *default_particle = def != NULL
? conf_to_particle(def, inherited) : NULL;
struct particle *default_particle = def != NULL ? conf_to_particle(def, inherited) : NULL;
return map_new(common, particle_map, yml_dict_length(conditions), default_particle);
}

View file

@ -28,7 +28,7 @@ struct map_condition {
void free_map_condition(struct map_condition *c);
typedef struct yy_buffer_state* YY_BUFFER_STATE;
typedef struct yy_buffer_state *YY_BUFFER_STATE;
YY_BUFFER_STATE yy_scan_string(const char *str);
int yyparse();
void yy_delete_buffer(YY_BUFFER_STATE buffer);

View file

@ -1,16 +1,17 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define LOG_MODULE "progress_bar"
#define LOG_ENABLE_DBG 0
#include "../log.h"
#include "../config.h"
#include "../config-verify.h"
#include "../config.h"
#include "../log.h"
#include "../particle.h"
#include "../plugin.h"
struct private {
struct private
{
char *tag;
int width;
@ -74,8 +75,7 @@ begin_expose(struct exposable *exposable)
/* Margins */
if (have_at_least_one) {
exposable->width += exposable->particle->left_margin +
exposable->particle->right_margin;
exposable->width += exposable->particle->left_margin + exposable->particle->right_margin;
} else
assert(exposable->width == 0);
@ -97,8 +97,7 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int
}
static void
on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event,
enum mouse_button btn, int x, int y)
on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, enum mouse_button btn, int x, int y)
{
const struct particle *p = exposable->particle;
const struct eprivate *e = exposable->private;
@ -161,18 +160,14 @@ on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event,
original[i] = exposable->on_click[i];
if (event == ON_MOUSE_CLICK) {
long where = clickable_width > 0
? 100 * (x - x_offset) / clickable_width
: 0;
long where = clickable_width > 0 ? 100 * (x - x_offset) / clickable_width : 0;
struct tag_set tags = {
.tags = (struct tag *[]){tag_new_int(NULL, "where", where)},
.count = 1,
};
tags_expand_templates(
exposable->on_click, (const char **)exposable->on_click,
MOUSE_BTN_COUNT, &tags);
tags_expand_templates(exposable->on_click, (const char **)exposable->on_click, MOUSE_BTN_COUNT, &tags);
tag_set_destroy(&tags);
}
@ -198,19 +193,17 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
long min = tag != NULL ? tag->min(tag) : 0;
long max = tag != NULL ? tag->max(tag) : 0;
LOG_DBG("%s: value=%ld, min=%ld, max=%ld",
tag != NULL ? tag->name(tag) : "<no tag>", value, min, max);
LOG_DBG("%s: value=%ld, min=%ld, max=%ld", tag != NULL ? tag->name(tag) : "<no tag>", value, min, max);
long fill_count = max == min ? 0 : p->width * value / (max - min);
long empty_count = p->width - fill_count;
struct eprivate *epriv = calloc(1, sizeof(*epriv));
epriv->count = (
1 + /* Start marker */
fill_count + /* Before current position */
1 + /* Current position indicator */
empty_count + /* After current position */
1); /* End marker */
epriv->count = (1 + /* Start marker */
fill_count + /* Before current position */
1 + /* Current position indicator */
empty_count + /* After current position */
1); /* End marker */
epriv->exposables = malloc(epriv->count * sizeof(epriv->exposables[0]));
@ -259,8 +252,7 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
LOG_DBG("tag: %s, value: %ld, "
"units-per-segment: %f, units-filled: %f, units-til-next: %f",
tag->name(tag), value,
units_per_segment, units_filled, units_til_next_segment);
tag->name(tag), value, units_per_segment, units_filled, units_til_next_segment);
#endif
@ -271,10 +263,8 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
}
static struct particle *
progress_bar_new(struct particle *common, const char *tag, int width,
struct particle *start_marker, struct particle *end_marker,
struct particle *fill, struct particle *empty,
struct particle *indicator)
progress_bar_new(struct particle *common, const char *tag, int width, struct particle *start_marker,
struct particle *end_marker, struct particle *fill, struct particle *empty, struct particle *indicator)
{
struct private *priv = calloc(1, sizeof(*priv));
priv->tag = strdup(tag);
@ -308,15 +298,10 @@ from_conf(const struct yml_node *node, struct particle *common)
.foreground = common->foreground,
};
return progress_bar_new(
common,
yml_value_as_string(tag),
yml_value_as_int(length),
conf_to_particle(start, inherited),
conf_to_particle(end, inherited),
conf_to_particle(fill, inherited),
conf_to_particle(empty, inherited),
conf_to_particle(indicator, inherited));
return progress_bar_new(common, yml_value_as_string(tag), yml_value_as_int(length),
conf_to_particle(start, inherited), conf_to_particle(end, inherited),
conf_to_particle(fill, inherited), conf_to_particle(empty, inherited),
conf_to_particle(indicator, inherited));
}
static bool

View file

@ -1,18 +1,19 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#define LOG_MODULE "ramp"
#define LOG_ENABLE_DBG 0
#include "../log.h"
#include "../config.h"
#include "../config-verify.h"
#include "../config.h"
#include "../log.h"
#include "../particle.h"
#include "../plugin.h"
struct private {
struct private
{
char *tag;
bool use_custom_min;
long min;
@ -57,21 +58,16 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int
struct eprivate *e = exposable->private;
exposable_render_deco(exposable, pix, x, y, height);
e->exposable->expose(
e->exposable, pix, x + exposable->particle->left_margin, y, height);
e->exposable->expose(e->exposable, pix, x + exposable->particle->left_margin, y, height);
}
static void
on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event,
enum mouse_button btn, int x, int y)
on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, enum mouse_button btn, int x, int y)
{
const struct particle *p = exposable->particle;
const struct eprivate *e = exposable->private;
if ((event == ON_MOUSE_MOTION &&
exposable->particle->have_on_click_template) ||
exposable->on_click[btn] != NULL)
{
if ((event == ON_MOUSE_MOTION && exposable->particle->have_on_click_template) || exposable->on_click[btn] != NULL) {
/* We have our own handler */
exposable_default_on_mouse(exposable, bar, event, btn, x, y);
return;
@ -118,22 +114,22 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
max = p->use_custom_max ? p->max : max;
if (min > max) {
LOG_WARN(
"tag's minimum value is greater than its maximum: "
"tag=\"%s\", min=%ld, max=%ld", p->tag, min, max);
LOG_WARN("tag's minimum value is greater than its maximum: "
"tag=\"%s\", min=%ld, max=%ld",
p->tag, min, max);
min = max;
}
if (value < min) {
LOG_WARN(
"tag's value is less than its minimum value: "
"tag=\"%s\", min=%ld, value=%ld", p->tag, min, value);
LOG_WARN("tag's value is less than its minimum value: "
"tag=\"%s\", min=%ld, value=%ld",
p->tag, min, value);
value = min;
}
if (value > max) {
LOG_WARN(
"tag's value is greater than its maximum value: "
"tag=\"%s\", max=%ld, value=%ld", p->tag, max, value);
LOG_WARN("tag's value is greater than its maximum value: "
"tag=\"%s\", max=%ld, value=%ld",
p->tag, max, value);
value = max;
}
@ -168,10 +164,8 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
}
static struct particle *
ramp_new(struct particle *common, const char *tag,
struct particle *particles[], size_t count,
bool use_custom_min, long min,
bool use_custom_max, long max)
ramp_new(struct particle *common, const char *tag, struct particle *particles[], size_t count, bool use_custom_min,
long min, bool use_custom_max, long max)
{
struct private *priv = calloc(1, sizeof(*priv));
@ -204,19 +198,15 @@ from_conf(const struct yml_node *node, struct particle *common)
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, (struct conf_inherit){common->font, common->font_shaping, common->foreground});
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, (struct conf_inherit){common->font, common->font_shaping, common->foreground});
}
long min_v = min != NULL ? yml_value_as_int(min) : 0;
long max_v = max != NULL ? yml_value_as_int(max) : 0;
return ramp_new(common, yml_value_as_string(tag), parts, count, min != NULL,
min_v, max != NULL, max_v);
return ramp_new(common, yml_value_as_string(tag), parts, count, min != NULL, min_v, max != NULL, max_v);
}
static bool

View file

@ -1,13 +1,13 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define LOG_MODULE "string"
#define LOG_ENABLE_DBG 0
#include "../log.h"
#include "../char32.h"
#include "../config.h"
#include "../config-verify.h"
#include "../config.h"
#include "../log.h"
#include "../particle.h"
#include "../plugin.h"
@ -18,7 +18,8 @@ struct text_run_cache {
bool in_use;
};
struct private {
struct private
{
char *text;
size_t max_len;
@ -51,9 +52,7 @@ begin_expose(struct exposable *exposable)
struct eprivate *e = exposable->private;
struct private *p = exposable->particle->private;
exposable->width =
exposable->particle->left_margin +
exposable->particle->right_margin;
exposable->width = exposable->particle->left_margin + exposable->particle->right_margin;
if (e->cache_idx >= 0) {
exposable->width += p->cache[e->cache_idx].width;
@ -97,9 +96,8 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int
* any real facts, but works very well with e.g. the "Awesome 6"
* font family.
*/
const double baseline = (double)y +
(double)(height + font->ascent + font->descent) / 2.0 -
(font->descent > 0 ? font->descent : 0);
const double baseline
= (double)y + (double)(height + font->ascent + font->descent) / 2.0 - (font->descent > 0 ? font->descent : 0);
x += exposable->particle->left_margin;
@ -112,17 +110,13 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int
if (pixman_image_get_format(glyph->pix) == PIXMAN_a8r8g8b8) {
/* Glyph surface is a pre-rendered image (typically a color emoji...) */
pixman_image_composite32(
PIXMAN_OP_OVER, glyph->pix, NULL, pix, 0, 0, 0, 0,
x + glyph->x, baseline - glyph->y,
glyph->width, glyph->height);
pixman_image_composite32(PIXMAN_OP_OVER, glyph->pix, NULL, pix, 0, 0, 0, 0, x + glyph->x,
baseline - glyph->y, glyph->width, glyph->height);
} else {
/* Glyph surface is an alpha mask */
pixman_image_t *src = pixman_image_create_solid_fill(&exposable->particle->foreground);
pixman_image_composite32(
PIXMAN_OP_OVER, src, glyph->pix, pix, 0, 0, 0, 0,
x + glyph->x, baseline - glyph->y,
glyph->width, glyph->height);
pixman_image_composite32(PIXMAN_OP_OVER, src, glyph->pix, pix, 0, 0, 0, 0, x + glyph->x,
baseline - glyph->y, glyph->width, glyph->height);
pixman_image_unref(src);
}
@ -188,11 +182,8 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
e->kern_x = calloc(chars, sizeof(e->kern_x[0]));
if (particle->font_shaping == FONT_SHAPE_FULL &&
fcft_capabilities() & FCFT_CAPABILITY_TEXT_RUN_SHAPING)
{
struct fcft_text_run *run = fcft_rasterize_text_run_utf32(
font, chars, wtext, FCFT_SUBPIXEL_NONE);
if (particle->font_shaping == FONT_SHAPE_FULL && fcft_capabilities() & FCFT_CAPABILITY_TEXT_RUN_SHAPING) {
struct fcft_text_run *run = fcft_rasterize_text_run_utf32(font, chars, wtext, FCFT_SUBPIXEL_NONE);
if (run != NULL) {
int w = 0;
@ -210,8 +201,7 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
if (cache_idx < 0) {
size_t new_size = p->cache_size + 1;
struct text_run_cache *new_cache = realloc(
p->cache, new_size * sizeof(new_cache[0]));
struct text_run_cache *new_cache = realloc(p->cache, new_size * sizeof(new_cache[0]));
p->cache_size = new_size;
p->cache = new_cache;
@ -235,8 +225,7 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
/* Convert text to glyph masks/images. */
for (size_t i = 0; i < chars; i++) {
const struct fcft_glyph *glyph = fcft_rasterize_char_utf32(
font, wtext[i], FCFT_SUBPIXEL_NONE);
const struct fcft_glyph *glyph = fcft_rasterize_char_utf32(font, wtext[i], FCFT_SUBPIXEL_NONE);
if (glyph == NULL)
continue;
@ -297,10 +286,7 @@ from_conf(const struct yml_node *node, struct particle *common)
const struct yml_node *text = yml_get_value(node, "text");
const struct yml_node *max = yml_get_value(node, "max");
return string_new(
common,
yml_value_as_string(text),
max != NULL ? yml_value_as_int(max) : 0);
return string_new(common, yml_value_as_string(text), max != NULL ? yml_value_as_int(max) : 0);
}
static bool