commit 0d69e94ed01d94f82ba2b6f960aa672de7ed2ff9
parent e714a12f36b44d6b67fcad122c858af6b903bdb2
Author: lumidify <nobody@lumidify.org>
Date: Fri, 1 Sep 2023 18:35:03 +0200
Fix fontconfig initialization with pango backend; fix crash when removing socket client
Diffstat:
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/src/ltkd.c b/src/ltkd.c
@@ -1154,6 +1154,19 @@ ltk_create_window(const char *title, int x, int y, unsigned int w, unsigned int
window->text_context = ltk_text_context_create(window->renderdata, window->theme->font);
window->clipboard = ltk_clipboard_create(window->renderdata);
+ /* This hack is necessary to make the daemonization work properly when using Pango.
+ This may not be entirely accurate, but from what I gather, newer versions of Pango
+ initialize Fontconfig in a separate thread to avoid startup overhead. This leads
+ to non-deterministic behavior because the Fontconfig initialization doesn't work
+ properly after daemonization. Creating a text line and getting the size waits until
+ Fontconfig is initialized. Getting the size is important because Pango doesn't
+ actually do much until you try to use the line for something. */
+ /* FIXME: I guess just calling FcInit manually in the text backend could work as well. */
+ ltk_text_line *tmp = ltk_text_line_create(window->text_context, 10, "hi", 0, -1);
+ int tw, th;
+ ltk_text_line_get_size(tmp, &tw, &th);
+ ltk_text_line_destroy(tmp);
+
return window;
}
diff --git a/src/widget.c b/src/widget.c
@@ -167,10 +167,13 @@ ltk_widget_remove_client(int client) {
if (ptr->event_masks[i].client == client) {
memmove(ptr->event_masks + i, ptr->event_masks + i + 1, ptr->masks_num - i - 1);
ptr->masks_num--;
- size_t sz = ideal_array_size(ptr->masks_alloc, ptr->masks_num - 1);
- if (sz != ptr->masks_alloc) {
- ptr->masks_alloc = sz;
- ptr->event_masks = ltk_reallocarray(ptr->event_masks, sz, sizeof(client_event_mask));
+ /* FIXME: maybe reset to NULL in that case? */
+ if (ptr->masks_num > 0) {
+ size_t sz = ideal_array_size(ptr->masks_alloc, ptr->masks_num);
+ if (sz != ptr->masks_alloc) {
+ ptr->masks_alloc = sz;
+ ptr->event_masks = ltk_reallocarray(ptr->event_masks, sz, sizeof(client_event_mask));
+ }
}
break;
}