Skip to content

Commit 1838419

Browse files
committed
Move font config to ouput level & fix output configuration (was always broken)
1 parent 1f7f6ec commit 1838419

File tree

11 files changed

+130
-62
lines changed

11 files changed

+130
-62
lines changed

meson.build

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ if not fs.is_absolute(sysconfdir)
4545
sysconfdir = prefix / sysconfdir
4646
endif
4747

48-
global_configuration_h = configuration_data({
49-
'WOB_VERSION': '"@0@"'.format(meson.project_version()),
50-
'WOB_ETC_CONFIG_FOLDER_PATH': '"@0@"'.format(sysconfdir),
51-
})
52-
configure_file(output: 'global_configuration.h', configuration: global_configuration_h)
48+
global_configuration_h = configuration_data()
49+
50+
global_configuration_h.set_quoted('WOB_VERSION', meson.project_version())
51+
global_configuration_h.set_quoted('WOB_ETC_CONFIG_FOLDER_PATH', sysconfdir)
5352

5453
wayland_scanner_code = generator(
5554
wayland_scanner,
@@ -92,15 +91,19 @@ wob_dependencies = [wayland_client, rt, inih, libm]
9291
if seccomp.found()
9392
wob_dependencies += seccomp
9493
wob_sources += 'src/pledge_seccomp.c'
94+
global_configuration_h.set('WOB_PLEDGE_ENABLED', 'true')
9595
else
9696
wob_sources += 'src/pledge.c'
97+
global_configuration_h.set('WOB_PLEDGE_ENABLED', 'false')
9798
endif
9899

99100
if freetype2.found()
100101
wob_dependencies += freetype2
101102
wob_sources += 'src/font_freetype.c'
103+
global_configuration_h.set('WOB_TEXT_ENABLED', 'true')
102104
else
103105
wob_sources += 'src/font_stub.c'
106+
global_configuration_h.set('WOB_TEXT_ENABLED', 'false')
104107
endif
105108

106109
executable(
@@ -155,3 +158,5 @@ if get_option('systemd-unit-files').enabled()
155158
)
156159
install_data('etc/systemd/wob.socket', install_dir: systemd_unit_dir)
157160
endif
161+
162+
configure_file(output: 'global_configuration.h', configuration: global_configuration_h)

src/color.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,36 @@ bool
8989
wob_color_from_rgba_string(const char *str, struct wob_color *color)
9090
{
9191
unsigned long length = strlen(str);
92-
for (const char *c = str; *c != '\0'; ++c) {
93-
if (!isxdigit(*c)) {
94-
return false;
95-
}
96-
}
9792

9893
uint8_t parts[4];
9994
parts[3] = 0xFF;
10095
switch (length) {
10196
case 8:
102-
parts[3] = hex_to_int(str[6]) * 16 + hex_to_int(str[7]);
97+
int p6 = hex_to_int(str[6]);
98+
int p7 = hex_to_int(str[7]);
99+
100+
if (p6 < 0 || p7 < 0) {
101+
return false;
102+
}
103+
104+
parts[3] = p6 * 16 + p7;
103105
// fallthrough
104106
case 6:
105-
parts[0] = hex_to_int(str[0]) * 16 + hex_to_int(str[1]);
106-
parts[1] = hex_to_int(str[2]) * 16 + hex_to_int(str[3]);
107-
parts[2] = hex_to_int(str[4]) * 16 + hex_to_int(str[5]);
107+
int p0 = hex_to_int(str[0]);
108+
int p1 = hex_to_int(str[1]);
109+
int p2 = hex_to_int(str[2]);
110+
int p3 = hex_to_int(str[3]);
111+
int p4 = hex_to_int(str[4]);
112+
int p5 = hex_to_int(str[5]);
113+
114+
if (p0 < 0 || p1 < 0 || p2 < 0 || p3 < 0 || p4 < 0 || p5 < 0) {
115+
return false;
116+
}
117+
118+
parts[0] = p0 * 16 + p1;
119+
parts[1] = p2 * 16 + p3;
120+
parts[2] = p4 * 16 + p5;
121+
108122
break;
109123
default:
110124
return false;

src/config.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,15 @@ handler(void *user, const char *section, const char *name, const char *value)
307307
return 1;
308308
}
309309
if (strcmp(name, "font") == 0) {
310-
config->default_style.font_path = strdup(value);
310+
config->font_path = strdup(value);
311+
return 1;
312+
}
313+
if (strcmp(name, "font_size") == 0) {
314+
if (parse_number(value, &ul) == false) {
315+
wob_log_error("Font size must be a positive value.");
316+
return 0;
317+
}
318+
config->font_size = ul;
311319
return 1;
312320
}
313321

@@ -393,6 +401,14 @@ handler(void *user, const char *section, const char *name, const char *value)
393401
output_config->dimensions.bar_padding = ul;
394402
return 1;
395403
}
404+
if (strcmp(name, "font_size") == 0) {
405+
if (parse_number(value, &ul) == false) {
406+
wob_log_error("Font size must be a positive value.");
407+
return 0;
408+
}
409+
output_config->font_size = ul;
410+
return 1;
411+
}
396412

397413
wob_log_warn("Unknown config key %s", name);
398414
return 1;
@@ -457,10 +473,6 @@ handler(void *user, const char *section, const char *name, const char *value)
457473
}
458474
return 1;
459475
}
460-
if (strcmp(name, "font") == 0) {
461-
style->font_path = strdup(value);
462-
return 1;
463-
}
464476

465477
wob_log_warn("Unknown config key %s", name);
466478
return 1;
@@ -520,13 +532,14 @@ wob_config_create()
520532
config->margin = (struct wob_margin) {.top = 0, .left = 0, .bottom = 0, .right = 0};
521533
config->anchor = WOB_ANCHOR_CENTER;
522534
config->overflow_mode = WOB_OVERFLOW_MODE_WRAP;
535+
config->font_path = NULL;
536+
config->font_size = 16;
523537
config->default_style.colors.background = (struct wob_color) {.a = 1.0f, .r = 0.0f, .g = 0.0f, .b = 0.0f};
524538
config->default_style.colors.value = (struct wob_color) {.a = 1.0f, .r = 1.0f, .g = 1.0f, .b = 1.0f};
525539
config->default_style.colors.border = (struct wob_color) {.a = 1.0f, .r = 1.0f, .g = 1.0f, .b = 1.0f};
526540
config->default_style.overflow_colors.background = (struct wob_color) {.a = 1.0f, .r = 0.0f, .g = 0.0f, .b = 0.0f};
527541
config->default_style.overflow_colors.value = (struct wob_color) {.a = 1.0f, .r = 1.0f, .g = 0.0f, .b = 0.0f};
528542
config->default_style.overflow_colors.border = (struct wob_color) {.a = 1.0f, .r = 1.0f, .g = 1.0f, .b = 1.0f};
529-
config->default_style.font_path = NULL;
530543

531544
return config;
532545
}
@@ -594,7 +607,8 @@ wob_config_debug(struct wob_config *config)
594607
wob_log_debug("config.overflow_colors.background = " WOB_COLOR_PRINTF_FORMAT, WOB_COLOR_PRINTF_RGBA(config->default_style.overflow_colors.background));
595608
wob_log_debug("config.overflow_colors.value = " WOB_COLOR_PRINTF_FORMAT, WOB_COLOR_PRINTF_RGBA(config->default_style.overflow_colors.value));
596609
wob_log_debug("config.overflow_colors.border = " WOB_COLOR_PRINTF_FORMAT, WOB_COLOR_PRINTF_RGBA(config->default_style.overflow_colors.border));
597-
wob_log_debug("config.font = %s", config->default_style.font_path != NULL ? config->default_style.font_path : "<empty>");
610+
wob_log_debug("config.font = %s", config->font_path != NULL ? config->font_path : "<empty>");
611+
wob_log_debug("config.font_size = %d", config->font_size);
598612

599613
struct wob_style *style;
600614
wl_list_for_each (style, &config->styles, link) {
@@ -604,7 +618,6 @@ wob_config_debug(struct wob_config *config)
604618
wob_log_debug("config.style.%s.overflow_colors.background = " WOB_COLOR_PRINTF_FORMAT, style->name, WOB_COLOR_PRINTF_RGBA(style->overflow_colors.background));
605619
wob_log_debug("config.style.%s.overflow_colors.value = " WOB_COLOR_PRINTF_FORMAT, style->name, WOB_COLOR_PRINTF_RGBA(style->overflow_colors.value));
606620
wob_log_debug("config.style.%s.overflow_colors.border = " WOB_COLOR_PRINTF_FORMAT, style->name, WOB_COLOR_PRINTF_RGBA(style->overflow_colors.border));
607-
wob_log_debug("config.style.%s.font = %s", style->name, style->font_path != NULL ? style->font_path : "<empty>");
608621
}
609622

610623
struct wob_output_config *output_config;
@@ -626,6 +639,7 @@ wob_config_debug(struct wob_config *config)
626639
WOB_ORIENTATION_HORIZONTAL,
627640
WOB_ORIENTATION_VERTICAL
628641
);
642+
wob_log_debug("config.output.%s.font_size = %d", output_config->id, output_config->font_size);
629643
}
630644
}
631645

@@ -642,12 +656,11 @@ wob_config_destroy(struct wob_config *config)
642656
struct wob_style *style, *style_tmp;
643657
wl_list_for_each_safe (style, style_tmp, &config->styles, link) {
644658
free(style->name);
645-
free(style->font_path);
646659
free(style);
647660
}
648661

649-
if (config->default_style.font_path != NULL) {
650-
free(config->default_style.font_path);
662+
if (config->font_path != NULL) {
663+
free(config->font_path);
651664
}
652665

653666
free(config);
@@ -699,7 +712,8 @@ wob_config_match_output(struct wob_config *config, const char *match)
699712
struct wob_output_config *output_config = NULL;
700713
bool output_found = false;
701714
wl_list_for_each (output_config, &config->outputs, link) {
702-
if (strstr(output_config->match, match) == 0) {
715+
wob_log_debug("%s = %s?", output_config->match, match);
716+
if (strstr(match, output_config->match) != NULL) {
703717
output_found = true;
704718
break;
705719
}

src/config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct wob_output_config {
5353
struct wob_dimensions dimensions;
5454
struct wob_margin margin;
5555
unsigned long anchor;
56+
unsigned long font_size;
5657
};
5758

5859
struct wob_colors {
@@ -63,7 +64,6 @@ struct wob_colors {
6364

6465
struct wob_style {
6566
char *name;
66-
char *font_path;
6767
struct wob_colors colors;
6868
struct wob_colors overflow_colors;
6969
struct wl_list link;
@@ -80,6 +80,8 @@ struct wob_config {
8080
struct wl_list styles;
8181
struct wl_list outputs;
8282
bool sandbox;
83+
char *font_path;
84+
unsigned long font_size;
8385
};
8486

8587
struct wob_config *wob_config_create();

src/font.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stddef.h>
55

66
#include "color.h"
7+
#include "config.h"
78

89
struct wob_font_manager;
910

@@ -20,6 +21,8 @@ void wob_font_manager_destroy(struct wob_font_manager *);
2021

2122
void wob_font_manager_load_font(struct wob_font_manager *, const char *fpath);
2223

24+
void wob_font_manager_load_fonts_from_config(struct wob_font_manager *, struct wob_config *);
25+
2326
struct wob_font *wob_font_manager_get(struct wob_font_manager *, const char *fpath);
2427

2528
void wob_font_render_text(struct wob_font *font, char *text, int font_size, struct wob_color font_color, uint32_t *argb8888_buffer, size_t argb8888_buffer_size);

src/font_freetype.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include "font.h"
44
#include "log.h"
55

6-
#include <wayland-util.h>
76
#include <ft2build.h>
7+
#include <wayland-util.h>
88
#include FT_FREETYPE_H
99
#include FT_GLYPH_H
1010

@@ -77,6 +77,14 @@ wob_font_manager_load_font(struct wob_font_manager *manager, const char *fpath)
7777
wl_list_insert(&manager->fonts, &font->link);
7878
}
7979

80+
void
81+
wob_font_manager_load_fonts_from_config(struct wob_font_manager *manager, struct wob_config *config)
82+
{
83+
if (config->font_path != NULL) {
84+
wob_font_manager_load_font(manager, config->font_path);
85+
}
86+
}
87+
8088
struct wob_font *
8189
wob_font_manager_get(struct wob_font_manager *manager, const char *fpath)
8290
{
@@ -116,7 +124,7 @@ wob_font_render_text_dimensions(struct wob_font *font, char *text, int font_size
116124
dimensions.w += glyph_bbox.xMax;
117125

118126
if (has_kerning && previous != 0) {
119-
FT_Get_Kerning( ft_face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
127+
FT_Get_Kerning(ft_face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
120128
dimensions.w += delta.x / 64;
121129
}
122130

@@ -136,7 +144,7 @@ wob_font_render_text(struct wob_font *font, char *text, int font_size, struct wo
136144
bool has_kerning = FT_HAS_KERNING(ft_face);
137145

138146
for (const char *c = text; *c != '\0'; c += 1) {
139-
FT_Vector delta;
147+
FT_Vector delta;
140148
FT_UInt glyph_index = FT_Get_Char_Index(ft_face, *c);
141149
FT_Load_Glyph(ft_face, glyph_index, FT_LOAD_DEFAULT);
142150
FT_Render_Glyph(ft_face->glyph, FT_RENDER_MODE_NORMAL);
@@ -145,7 +153,7 @@ wob_font_render_text(struct wob_font *font, char *text, int font_size, struct wo
145153

146154
argb8888_buffer += ft_face->glyph->advance.x / 64;
147155
if (has_kerning && previous != 0) {
148-
FT_Get_Kerning( ft_face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
156+
FT_Get_Kerning(ft_face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
149157
argb8888_buffer += delta.x / 64;
150158
}
151159

src/font_stub.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,29 @@ wob_font_manager_destroy(struct wob_font_manager *manager)
2121
void
2222
wob_font_manager_load_font(struct wob_font_manager *manager, const char *fpath)
2323
{
24-
wob_log_error("STUB!");
24+
wob_log_error("STUB wob_font_manager_load_font!");
25+
}
26+
27+
void
28+
wob_font_manager_load_fonts_from_config(struct wob_font_manager *manager, struct wob_config *config)
29+
{
30+
if (config->font_path != NULL) {
31+
wob_font_manager_load_font(manager, config->font_path);
32+
}
2533
}
2634

2735
struct wob_font *
2836
wob_font_manager_get(struct wob_font_manager *manager, const char *fpath)
2937
{
30-
wob_log_error("STUB!");
38+
wob_log_error("STUB wob_font_manager_get!");
3139

3240
return NULL;
3341
}
3442

3543
struct wob_font_text_dimensions
3644
wob_font_render_text_dimensions(struct wob_font *font, char *text, int font_size)
3745
{
38-
wob_log_error("STUB!");
46+
wob_log_error("STUB wob_font_render_text_dimensions!");
3947

4048
struct wob_font_text_dimensions d = {.h = 0, .w = 0};
4149

@@ -45,5 +53,5 @@ wob_font_render_text_dimensions(struct wob_font *font, char *text, int font_size
4553
void
4654
wob_font_render_text(struct wob_font *font, char *text, int font_size, struct wob_color font_color, uint32_t *argb8888_buffer, size_t argb8888_buffer_size)
4755
{
48-
wob_log_error("STUB!");
56+
wob_log_error("STUB wob_font_render_text!");
4957
}

0 commit comments

Comments
 (0)